clang 22.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
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::make_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(),
1483 T->getIndexTypeCVRQualifiers());
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(),
1503 T->getIndexTypeCVRQualifiers());
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(),
1515 T->getIndexTypeCVRQualifiers());
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(),
1530 T->getIndexTypeCVRQualifiers());
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
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
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::VisitHLSLAttributedResourceType(
2013 const clang::HLSLAttributedResourceType *T) {
2014 Error Err = Error::success();
2015 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
2016 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2017 QualType ToContainedType = importChecked(Err, T->getContainedType());
2018 if (Err)
2019 return std::move(Err);
2020
2021 return Importer.getToContext().getHLSLAttributedResourceType(
2022 ToWrappedType, ToContainedType, ToAttrs);
2023}
2024
2025ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2026 const clang::HLSLInlineSpirvType *T) {
2027 Error Err = Error::success();
2028
2029 uint32_t ToOpcode = T->getOpcode();
2030 uint32_t ToSize = T->getSize();
2031 uint32_t ToAlignment = T->getAlignment();
2032
2033 llvm::SmallVector<SpirvOperand> ToOperands;
2034
2035 for (auto &Operand : T->getOperands()) {
2036 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2037
2038 switch (Operand.getKind()) {
2039 case SpirvOperandKind::ConstantId:
2040 ToOperands.push_back(SpirvOperand::createConstant(
2041 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2042 break;
2043 case SpirvOperandKind::Literal:
2044 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2045 break;
2046 case SpirvOperandKind::TypeId:
2047 ToOperands.push_back(SpirvOperand::createType(
2048 importChecked(Err, Operand.getResultType())));
2049 break;
2050 default:
2051 llvm_unreachable("Invalid SpirvOperand kind");
2052 }
2053
2054 if (Err)
2055 return std::move(Err);
2056 }
2057
2058 return Importer.getToContext().getHLSLInlineSpirvType(
2059 ToOpcode, ToSize, ToAlignment, ToOperands);
2060}
2061
2062ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2063 const clang::ConstantMatrixType *T) {
2064 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2065 if (!ToElementTypeOrErr)
2066 return ToElementTypeOrErr.takeError();
2067
2068 return Importer.getToContext().getConstantMatrixType(
2069 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2070}
2071
2072ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2073 const clang::DependentAddressSpaceType *T) {
2074 Error Err = Error::success();
2075 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2076 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2077 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2078 if (Err)
2079 return std::move(Err);
2080
2081 return Importer.getToContext().getDependentAddressSpaceType(
2082 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2083}
2084
2085ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2086 const clang::DependentBitIntType *T) {
2087 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2088 if (!ToNumBitsExprOrErr)
2089 return ToNumBitsExprOrErr.takeError();
2090 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2091 *ToNumBitsExprOrErr);
2092}
2093
2094ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2095 const clang::PredefinedSugarType *T) {
2096 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2097}
2098
2099ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2100 const clang::DependentSizedMatrixType *T) {
2101 Error Err = Error::success();
2102 QualType ToElementType = importChecked(Err, T->getElementType());
2103 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2104 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2105 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2106 if (Err)
2107 return std::move(Err);
2108
2109 return Importer.getToContext().getDependentSizedMatrixType(
2110 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2111}
2112
2113ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2114 const clang::DependentVectorType *T) {
2115 Error Err = Error::success();
2116 QualType ToElementType = importChecked(Err, T->getElementType());
2117 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2118 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2119 if (Err)
2120 return std::move(Err);
2121
2122 return Importer.getToContext().getDependentVectorType(
2123 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2124}
2125
2126ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2127 const clang::ObjCTypeParamType *T) {
2128 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2129 if (!ToDeclOrErr)
2130 return ToDeclOrErr.takeError();
2131
2132 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2133 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2134 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2135 if (!ToProtocolOrErr)
2136 return ToProtocolOrErr.takeError();
2137 ToProtocols.push_back(*ToProtocolOrErr);
2138 }
2139
2140 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2141 ToProtocols);
2142}
2143
2144ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2145 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2146 if (!ToElementTypeOrErr)
2147 return ToElementTypeOrErr.takeError();
2148
2149 ASTContext &ToCtx = Importer.getToContext();
2150 if (T->isReadOnly())
2151 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2152 else
2153 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2154}
2155
2156//----------------------------------------------------------------------------
2157// Import Declarations
2158//----------------------------------------------------------------------------
2160 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2161 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2162 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2163 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2164 // FIXME: We could support these constructs by importing a different type of
2165 // this parameter and by importing the original type of the parameter only
2166 // after the FunctionDecl is created. See
2167 // VisitFunctionDecl::UsedDifferentProtoType.
2168 DeclContext *OrigDC = D->getDeclContext();
2169 FunctionDecl *FunDecl;
2170 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2171 FunDecl->hasBody()) {
2172 auto getLeafPointeeType = [](const Type *T) {
2173 while (T->isPointerType() || T->isArrayType()) {
2174 T = T->getPointeeOrArrayElementType();
2175 }
2176 return T;
2177 };
2178 for (const ParmVarDecl *P : FunDecl->parameters()) {
2179 const Type *LeafT =
2180 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2181 auto *RT = dyn_cast<RecordType>(LeafT);
2182 if (RT && RT->getDecl() == D) {
2183 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2184 << D->getDeclKindName();
2185 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2186 }
2187 }
2188 }
2189
2190 // Import the context of this declaration.
2191 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2192 return Err;
2193
2194 // Import the name of this declaration.
2195 if (Error Err = importInto(Name, D->getDeclName()))
2196 return Err;
2197
2198 // Import the location of this declaration.
2199 if (Error Err = importInto(Loc, D->getLocation()))
2200 return Err;
2201
2202 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2203 if (ToD)
2204 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2205 return Err;
2206
2207 return Error::success();
2208}
2209
2211 NamedDecl *&ToD, SourceLocation &Loc) {
2212
2213 // Import the name of this declaration.
2214 if (Error Err = importInto(Name, D->getDeclName()))
2215 return Err;
2216
2217 // Import the location of this declaration.
2218 if (Error Err = importInto(Loc, D->getLocation()))
2219 return Err;
2220
2221 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2222 if (ToD)
2223 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2224 return Err;
2225
2226 return Error::success();
2227}
2228
2230 if (!FromD)
2231 return Error::success();
2232
2233 if (!ToD)
2234 if (Error Err = importInto(ToD, FromD))
2235 return Err;
2236
2237 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2238 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2239 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2240 !ToRecord->getDefinition()) {
2241 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2242 return Err;
2243 }
2244 }
2245 return Error::success();
2246 }
2247
2248 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2249 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2250 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2251 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2252 return Err;
2253 }
2254 }
2255 return Error::success();
2256 }
2257
2258 return Error::success();
2259}
2260
2261Error
2263 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2264 // NOTE: To.Name and To.Loc are already imported.
2265 // We only have to import To.LocInfo.
2266 switch (To.getName().getNameKind()) {
2273 return Error::success();
2274
2276 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2277 To.setCXXOperatorNameRange(*ToRangeOrErr);
2278 else
2279 return ToRangeOrErr.takeError();
2280 return Error::success();
2281 }
2283 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2284 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2285 else
2286 return LocOrErr.takeError();
2287 return Error::success();
2288 }
2292 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2293 To.setNamedTypeInfo(*ToTInfoOrErr);
2294 else
2295 return ToTInfoOrErr.takeError();
2296 return Error::success();
2297 }
2298 }
2299 llvm_unreachable("Unknown name kind.");
2300}
2301
2302Error
2304 if (Importer.isMinimalImport() && !ForceImport) {
2305 auto ToDCOrErr = Importer.ImportContext(FromDC);
2306 return ToDCOrErr.takeError();
2307 }
2308
2309 // We use strict error handling in case of records and enums, but not
2310 // with e.g. namespaces.
2311 //
2312 // FIXME Clients of the ASTImporter should be able to choose an
2313 // appropriate error handling strategy for their needs. For instance,
2314 // they may not want to mark an entire namespace as erroneous merely
2315 // because there is an ODR error with two typedefs. As another example,
2316 // the client may allow EnumConstantDecls with same names but with
2317 // different values in two distinct translation units.
2318 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2319
2320 auto MightNeedReordering = [](const Decl *D) {
2322 };
2323
2324 // Import everything that might need reordering first.
2325 Error ChildErrors = Error::success();
2326 for (auto *From : FromDC->decls()) {
2327 if (!MightNeedReordering(From))
2328 continue;
2329
2330 ExpectedDecl ImportedOrErr = import(From);
2331
2332 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2333 // want to make sure that we are also completing each FieldDecl. There
2334 // are currently cases where this does not happen and this is correctness
2335 // fix since operations such as code generation will expect this to be so.
2336 if (!ImportedOrErr) {
2337 HandleChildErrors.handleChildImportResult(ChildErrors,
2338 ImportedOrErr.takeError());
2339 continue;
2340 }
2341 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2342 Decl *ImportedDecl = *ImportedOrErr;
2343 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2344 if (FieldFrom && FieldTo) {
2345 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2346 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2347 }
2348 }
2349
2350 // We reorder declarations in RecordDecls because they may have another order
2351 // in the "to" context than they have in the "from" context. This may happen
2352 // e.g when we import a class like this:
2353 // struct declToImport {
2354 // int a = c + b;
2355 // int b = 1;
2356 // int c = 2;
2357 // };
2358 // During the import of `a` we import first the dependencies in sequence,
2359 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2360 // first removing the already imported members and then adding them in the
2361 // order as they appear in the "from" context.
2362 //
2363 // Keeping field order is vital because it determines structure layout.
2364 //
2365 // Here and below, we cannot call field_begin() method and its callers on
2366 // ToDC if it has an external storage. Calling field_begin() will
2367 // automatically load all the fields by calling
2368 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2369 // call ASTImporter::Import(). This is because the ExternalASTSource
2370 // interface in LLDB is implemented by the means of the ASTImporter. However,
2371 // calling an import at this point would result in an uncontrolled import, we
2372 // must avoid that.
2373
2374 auto ToDCOrErr = Importer.ImportContext(FromDC);
2375 if (!ToDCOrErr) {
2376 consumeError(std::move(ChildErrors));
2377 return ToDCOrErr.takeError();
2378 }
2379
2380 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2381 DeclContext *ToDC = *ToDCOrErr;
2382 // Remove all declarations, which may be in wrong order in the
2383 // lexical DeclContext and then add them in the proper order.
2384 for (auto *D : FromRD->decls()) {
2385 if (!MightNeedReordering(D))
2386 continue;
2387
2388 assert(D && "DC contains a null decl");
2389 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2390 // Remove only the decls which we successfully imported.
2391 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2392 // Remove the decl from its wrong place in the linked list.
2393 ToDC->removeDecl(ToD);
2394 // Add the decl to the end of the linked list.
2395 // This time it will be at the proper place because the enclosing for
2396 // loop iterates in the original (good) order of the decls.
2397 ToDC->addDeclInternal(ToD);
2398 }
2399 }
2400 }
2401
2402 // Import everything else.
2403 for (auto *From : FromDC->decls()) {
2404 if (MightNeedReordering(From))
2405 continue;
2406
2407 ExpectedDecl ImportedOrErr = import(From);
2408 if (!ImportedOrErr)
2409 HandleChildErrors.handleChildImportResult(ChildErrors,
2410 ImportedOrErr.takeError());
2411 }
2412
2413 return ChildErrors;
2414}
2415
2417 const FieldDecl *To) {
2418 RecordDecl *FromRecordDecl = nullptr;
2419 RecordDecl *ToRecordDecl = nullptr;
2420 // If we have a field that is an ArrayType we need to check if the array
2421 // element is a RecordDecl and if so we need to import the definition.
2422 QualType FromType = From->getType();
2423 QualType ToType = To->getType();
2424 if (FromType->isArrayType()) {
2425 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2426 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2427 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2428 }
2429
2430 if (!FromRecordDecl || !ToRecordDecl) {
2431 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2432 const RecordType *RecordTo = ToType->getAs<RecordType>();
2433
2434 if (RecordFrom && RecordTo) {
2435 FromRecordDecl = RecordFrom->getDecl();
2436 ToRecordDecl = RecordTo->getDecl();
2437 }
2438 }
2439
2440 if (FromRecordDecl && ToRecordDecl) {
2441 if (FromRecordDecl->isCompleteDefinition() &&
2442 !ToRecordDecl->isCompleteDefinition())
2443 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2444 }
2445
2446 return Error::success();
2447}
2448
2450 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2451 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2452 if (!ToDCOrErr)
2453 return ToDCOrErr.takeError();
2454 ToDC = *ToDCOrErr;
2455
2456 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2457 auto ToLexicalDCOrErr = Importer.ImportContext(
2458 FromD->getLexicalDeclContext());
2459 if (!ToLexicalDCOrErr)
2460 return ToLexicalDCOrErr.takeError();
2461 ToLexicalDC = *ToLexicalDCOrErr;
2462 } else
2463 ToLexicalDC = ToDC;
2464
2465 return Error::success();
2466}
2467
2469 const CXXRecordDecl *From, CXXRecordDecl *To) {
2470 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2471 "Import implicit methods to or from non-definition");
2472
2473 for (CXXMethodDecl *FromM : From->methods())
2474 if (FromM->isImplicit()) {
2475 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2476 if (!ToMOrErr)
2477 return ToMOrErr.takeError();
2478 }
2479
2480 return Error::success();
2481}
2482
2484 ASTImporter &Importer) {
2485 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2486 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2488 else
2489 return ToTypedefOrErr.takeError();
2490 }
2491 return Error::success();
2492}
2493
2495 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2496 auto DefinitionCompleter = [To]() {
2497 // There are cases in LLDB when we first import a class without its
2498 // members. The class will have DefinitionData, but no members. Then,
2499 // importDefinition is called from LLDB, which tries to get the members, so
2500 // when we get here, the class already has the DefinitionData set, so we
2501 // must unset the CompleteDefinition here to be able to complete again the
2502 // definition.
2503 To->setCompleteDefinition(false);
2504 To->completeDefinition();
2505 };
2506
2507 if (To->getDefinition() || To->isBeingDefined()) {
2508 if (Kind == IDK_Everything ||
2509 // In case of lambdas, the class already has a definition ptr set, but
2510 // the contained decls are not imported yet. Also, isBeingDefined was
2511 // set in CXXRecordDecl::CreateLambda. We must import the contained
2512 // decls here and finish the definition.
2513 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2514 if (To->isLambda()) {
2515 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2517 ToCaptures.reserve(FromCXXRD->capture_size());
2518 for (const auto &FromCapture : FromCXXRD->captures()) {
2519 if (auto ToCaptureOrErr = import(FromCapture))
2520 ToCaptures.push_back(*ToCaptureOrErr);
2521 else
2522 return ToCaptureOrErr.takeError();
2523 }
2524 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2525 ToCaptures);
2526 }
2527
2528 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2529 // Finish the definition of the lambda, set isBeingDefined to false.
2530 if (To->isLambda())
2531 DefinitionCompleter();
2532 return Result;
2533 }
2534
2535 return Error::success();
2536 }
2537
2538 To->startDefinition();
2539 // Set the definition to complete even if it is really not complete during
2540 // import. Some AST constructs (expressions) require the record layout
2541 // to be calculated (see 'clang::computeDependence') at the time they are
2542 // constructed. Import of such AST node is possible during import of the
2543 // same record, there is no way to have a completely defined record (all
2544 // fields imported) at that time without multiple AST import passes.
2545 if (!Importer.isMinimalImport())
2546 To->setCompleteDefinition(true);
2547 // Complete the definition even if error is returned.
2548 // The RecordDecl may be already part of the AST so it is better to
2549 // have it in complete state even if something is wrong with it.
2550 auto DefinitionCompleterScopeExit =
2551 llvm::make_scope_exit(DefinitionCompleter);
2552
2553 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2554 return Err;
2555
2556 // Add base classes.
2557 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2558 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2559 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2560
2561 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2562 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2563
2564 #define FIELD(Name, Width, Merge) \
2565 ToData.Name = FromData.Name;
2566 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2567
2568 // Copy over the data stored in RecordDeclBits
2569 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2570
2572 for (const auto &Base1 : FromCXX->bases()) {
2573 ExpectedType TyOrErr = import(Base1.getType());
2574 if (!TyOrErr)
2575 return TyOrErr.takeError();
2576
2577 SourceLocation EllipsisLoc;
2578 if (Base1.isPackExpansion()) {
2579 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2580 EllipsisLoc = *LocOrErr;
2581 else
2582 return LocOrErr.takeError();
2583 }
2584
2585 // Ensure that we have a definition for the base.
2586 if (Error Err =
2587 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2588 return Err;
2589
2590 auto RangeOrErr = import(Base1.getSourceRange());
2591 if (!RangeOrErr)
2592 return RangeOrErr.takeError();
2593
2594 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2595 if (!TSIOrErr)
2596 return TSIOrErr.takeError();
2597
2598 Bases.push_back(
2599 new (Importer.getToContext()) CXXBaseSpecifier(
2600 *RangeOrErr,
2601 Base1.isVirtual(),
2602 Base1.isBaseOfClass(),
2603 Base1.getAccessSpecifierAsWritten(),
2604 *TSIOrErr,
2605 EllipsisLoc));
2606 }
2607 if (!Bases.empty())
2608 ToCXX->setBases(Bases.data(), Bases.size());
2609 }
2610
2611 if (shouldForceImportDeclContext(Kind)) {
2612 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2613 return Err;
2614 }
2615
2616 return Error::success();
2617}
2618
2620 if (To->getAnyInitializer())
2621 return Error::success();
2622
2623 Expr *FromInit = From->getInit();
2624 if (!FromInit)
2625 return Error::success();
2626
2627 ExpectedExpr ToInitOrErr = import(FromInit);
2628 if (!ToInitOrErr)
2629 return ToInitOrErr.takeError();
2630
2631 To->setInit(*ToInitOrErr);
2632 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2633 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2634 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2635 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2636 // FIXME: Also import the initializer value.
2637 }
2638
2639 // FIXME: Other bits to merge?
2640 return Error::success();
2641}
2642
2644 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2645 if (To->getDefinition() || To->isBeingDefined()) {
2646 if (Kind == IDK_Everything)
2647 return ImportDeclContext(From, /*ForceImport=*/true);
2648 return Error::success();
2649 }
2650
2651 To->startDefinition();
2652
2653 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2654 return Err;
2655
2656 ExpectedType ToTypeOrErr =
2657 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2658 if (!ToTypeOrErr)
2659 return ToTypeOrErr.takeError();
2660
2661 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2662 if (!ToPromotionTypeOrErr)
2663 return ToPromotionTypeOrErr.takeError();
2664
2666 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2667 return Err;
2668
2669 // FIXME: we might need to merge the number of positive or negative bits
2670 // if the enumerator lists don't match.
2671 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2672 From->getNumPositiveBits(),
2673 From->getNumNegativeBits());
2674 return Error::success();
2675}
2676
2680 for (const auto &Arg : FromArgs) {
2681 if (auto ToOrErr = import(Arg))
2682 ToArgs.push_back(*ToOrErr);
2683 else
2684 return ToOrErr.takeError();
2685 }
2686
2687 return Error::success();
2688}
2689
2690// FIXME: Do not forget to remove this and use only 'import'.
2693 return import(From);
2694}
2695
2696template <typename InContainerTy>
2698 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2699 for (const auto &FromLoc : Container) {
2700 if (auto ToLocOrErr = import(FromLoc))
2701 ToTAInfo.addArgument(*ToLocOrErr);
2702 else
2703 return ToLocOrErr.takeError();
2704 }
2705 return Error::success();
2706}
2707
2713
2714bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2715 bool IgnoreTemplateParmDepth) {
2716 // Eliminate a potential failure point where we attempt to re-import
2717 // something we're trying to import while completing ToRecord.
2718 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2719 if (ToOrigin) {
2720 To = ToOrigin;
2721 }
2722
2724 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2725 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2727 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2728 IgnoreTemplateParmDepth);
2729 return Ctx.IsEquivalent(From, To);
2730}
2731
2733 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2734 << D->getDeclKindName();
2735 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2736}
2737
2739 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2740 << D->getDeclKindName();
2741 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2742}
2743
2745 // Import the context of this declaration.
2746 DeclContext *DC, *LexicalDC;
2747 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2748 return std::move(Err);
2749
2750 // Import the location of this declaration.
2751 ExpectedSLoc LocOrErr = import(D->getLocation());
2752 if (!LocOrErr)
2753 return LocOrErr.takeError();
2754
2755 EmptyDecl *ToD;
2756 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2757 return ToD;
2758
2759 ToD->setLexicalDeclContext(LexicalDC);
2760 LexicalDC->addDeclInternal(ToD);
2761 return ToD;
2762}
2763
2765 TranslationUnitDecl *ToD =
2766 Importer.getToContext().getTranslationUnitDecl();
2767
2768 Importer.MapImported(D, ToD);
2769
2770 return ToD;
2771}
2772
2774 DeclContext *DC, *LexicalDC;
2775 DeclarationName Name;
2776 SourceLocation Loc;
2777 NamedDecl *ToND;
2778 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2779 return std::move(Err);
2780 if (ToND)
2781 return ToND;
2782
2783 BindingDecl *ToD;
2784 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2785 Name.getAsIdentifierInfo(), D->getType()))
2786 return ToD;
2787
2788 Error Err = Error::success();
2789 QualType ToType = importChecked(Err, D->getType());
2790 Expr *ToBinding = importChecked(Err, D->getBinding());
2791 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2792 if (Err)
2793 return std::move(Err);
2794
2795 ToD->setBinding(ToType, ToBinding);
2796 ToD->setDecomposedDecl(ToDecomposedDecl);
2797 addDeclToContexts(D, ToD);
2798
2799 return ToD;
2800}
2801
2803 ExpectedSLoc LocOrErr = import(D->getLocation());
2804 if (!LocOrErr)
2805 return LocOrErr.takeError();
2806 auto ColonLocOrErr = import(D->getColonLoc());
2807 if (!ColonLocOrErr)
2808 return ColonLocOrErr.takeError();
2809
2810 // Import the context of this declaration.
2811 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2812 if (!DCOrErr)
2813 return DCOrErr.takeError();
2814 DeclContext *DC = *DCOrErr;
2815
2816 AccessSpecDecl *ToD;
2817 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2818 DC, *LocOrErr, *ColonLocOrErr))
2819 return ToD;
2820
2821 // Lexical DeclContext and Semantic DeclContext
2822 // is always the same for the accessSpec.
2823 ToD->setLexicalDeclContext(DC);
2824 DC->addDeclInternal(ToD);
2825
2826 return ToD;
2827}
2828
2830 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2831 if (!DCOrErr)
2832 return DCOrErr.takeError();
2833 DeclContext *DC = *DCOrErr;
2834 DeclContext *LexicalDC = DC;
2835
2836 Error Err = Error::success();
2837 auto ToLocation = importChecked(Err, D->getLocation());
2838 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2839 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2840 auto ToMessage = importChecked(Err, D->getMessage());
2841 if (Err)
2842 return std::move(Err);
2843
2844 StaticAssertDecl *ToD;
2845 if (GetImportedOrCreateDecl(
2846 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2847 ToRParenLoc, D->isFailed()))
2848 return ToD;
2849
2850 ToD->setLexicalDeclContext(LexicalDC);
2851 LexicalDC->addDeclInternal(ToD);
2852 return ToD;
2853}
2854
2856 // Import the major distinguishing characteristics of this namespace.
2857 DeclContext *DC, *LexicalDC;
2858 DeclarationName Name;
2859 SourceLocation Loc;
2860 NamedDecl *ToD;
2861 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2862 return std::move(Err);
2863 if (ToD)
2864 return ToD;
2865
2866 NamespaceDecl *MergeWithNamespace = nullptr;
2867 if (!Name) {
2868 // This is an anonymous namespace. Adopt an existing anonymous
2869 // namespace if we can.
2870 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2871 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2872 MergeWithNamespace = TU->getAnonymousNamespace();
2873 else
2874 MergeWithNamespace =
2875 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2876 } else {
2877 SmallVector<NamedDecl *, 4> ConflictingDecls;
2878 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2879 for (auto *FoundDecl : FoundDecls) {
2880 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2881 continue;
2882
2883 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2884 MergeWithNamespace = FoundNS;
2885 ConflictingDecls.clear();
2886 break;
2887 }
2888
2889 ConflictingDecls.push_back(FoundDecl);
2890 }
2891
2892 if (!ConflictingDecls.empty()) {
2893 ExpectedName NameOrErr = Importer.HandleNameConflict(
2894 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2895 ConflictingDecls.size());
2896 if (NameOrErr)
2897 Name = NameOrErr.get();
2898 else
2899 return NameOrErr.takeError();
2900 }
2901 }
2902
2903 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2904 if (!BeginLocOrErr)
2905 return BeginLocOrErr.takeError();
2906 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2907 if (!RBraceLocOrErr)
2908 return RBraceLocOrErr.takeError();
2909
2910 // Create the "to" namespace, if needed.
2911 NamespaceDecl *ToNamespace = MergeWithNamespace;
2912 if (!ToNamespace) {
2913 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2914 D->isInline(), *BeginLocOrErr, Loc,
2915 Name.getAsIdentifierInfo(),
2916 /*PrevDecl=*/nullptr, D->isNested()))
2917 return ToNamespace;
2918 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2919 ToNamespace->setLexicalDeclContext(LexicalDC);
2920 LexicalDC->addDeclInternal(ToNamespace);
2921
2922 // If this is an anonymous namespace, register it as the anonymous
2923 // namespace within its context.
2924 if (!Name) {
2925 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2926 TU->setAnonymousNamespace(ToNamespace);
2927 else
2928 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2929 }
2930 }
2931 Importer.MapImported(D, ToNamespace);
2932
2933 if (Error Err = ImportDeclContext(D))
2934 return std::move(Err);
2935
2936 return ToNamespace;
2937}
2938
2940 // Import the major distinguishing characteristics of this namespace.
2941 DeclContext *DC, *LexicalDC;
2942 DeclarationName Name;
2943 SourceLocation Loc;
2944 NamedDecl *LookupD;
2945 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2946 return std::move(Err);
2947 if (LookupD)
2948 return LookupD;
2949
2950 // NOTE: No conflict resolution is done for namespace aliases now.
2951
2952 Error Err = Error::success();
2953 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2954 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2955 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2956 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2957 auto ToNamespace = importChecked(Err, D->getNamespace());
2958 if (Err)
2959 return std::move(Err);
2960
2961 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2962
2963 NamespaceAliasDecl *ToD;
2964 if (GetImportedOrCreateDecl(
2965 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2966 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2967 return ToD;
2968
2969 ToD->setLexicalDeclContext(LexicalDC);
2970 LexicalDC->addDeclInternal(ToD);
2971
2972 return ToD;
2973}
2974
2977 // Import the major distinguishing characteristics of this typedef.
2978 DeclarationName Name;
2979 SourceLocation Loc;
2980 NamedDecl *ToD;
2981 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2982 // is created.
2983 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2984 return std::move(Err);
2985 if (ToD)
2986 return ToD;
2987
2988 DeclContext *DC = cast_or_null<DeclContext>(
2989 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2990 DeclContext *LexicalDC =
2991 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2993
2994 // If this typedef is not in block scope, determine whether we've
2995 // seen a typedef with the same name (that we can merge with) or any
2996 // other entity by that name (which name lookup could conflict with).
2997 // Note: Repeated typedefs are not valid in C99:
2998 // 'typedef int T; typedef int T;' is invalid
2999 // We do not care about this now.
3000 if (DC && !DC->isFunctionOrMethod()) {
3001 SmallVector<NamedDecl *, 4> ConflictingDecls;
3002 unsigned IDNS = Decl::IDNS_Ordinary;
3003 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3004 for (auto *FoundDecl : FoundDecls) {
3005 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3006 continue;
3007 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3008 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3009 continue;
3010
3011 QualType FromUT = D->getUnderlyingType();
3012 QualType FoundUT = FoundTypedef->getUnderlyingType();
3013 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3014 // If the underlying declarations are unnamed records these can be
3015 // imported as different types. We should create a distinct typedef
3016 // node in this case.
3017 // If we found an existing underlying type with a record in a
3018 // different context (than the imported), this is already reason for
3019 // having distinct typedef nodes for these.
3020 // Again this can create situation like
3021 // 'typedef int T; typedef int T;' but this is hard to avoid without
3022 // a rename strategy at import.
3023 if (!FromUT.isNull() && !FoundUT.isNull()) {
3024 RecordDecl *FromR = FromUT->getAsRecordDecl();
3025 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3026 if (FromR && FoundR &&
3027 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3028 continue;
3029 }
3030 // If the "From" context has a complete underlying type but we
3031 // already have a complete underlying type then return with that.
3032 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3033 return Importer.MapImported(D, FoundTypedef);
3034 // FIXME Handle redecl chain. When you do that make consistent changes
3035 // in ASTImporterLookupTable too.
3036 } else {
3037 ConflictingDecls.push_back(FoundDecl);
3038 }
3039 }
3040 }
3041
3042 if (!ConflictingDecls.empty()) {
3043 ExpectedName NameOrErr = Importer.HandleNameConflict(
3044 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3045 if (NameOrErr)
3046 Name = NameOrErr.get();
3047 else
3048 return NameOrErr.takeError();
3049 }
3050 }
3051
3052 Error Err = Error::success();
3054 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3055 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3056 if (Err)
3057 return std::move(Err);
3058
3059 // Create the new typedef node.
3060 // FIXME: ToUnderlyingType is not used.
3061 (void)ToUnderlyingType;
3062 TypedefNameDecl *ToTypedef;
3063 if (IsAlias) {
3064 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3065 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3066 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3067 return ToTypedef;
3068 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3069 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3070 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3071 return ToTypedef;
3072
3073 // Import the DeclContext and set it to the Typedef.
3074 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3075 return std::move(Err);
3076 ToTypedef->setDeclContext(DC);
3077 ToTypedef->setLexicalDeclContext(LexicalDC);
3078 // Add to the lookupTable because we could not do that in MapImported.
3079 Importer.AddToLookupTable(ToTypedef);
3080
3081 ToTypedef->setAccess(D->getAccess());
3082
3083 // Templated declarations should not appear in DeclContext.
3084 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3085 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3086 LexicalDC->addDeclInternal(ToTypedef);
3087
3088 return ToTypedef;
3089}
3090
3094
3098
3101 // Import the major distinguishing characteristics of this typedef.
3102 DeclContext *DC, *LexicalDC;
3103 DeclarationName Name;
3104 SourceLocation Loc;
3105 NamedDecl *FoundD;
3106 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3107 return std::move(Err);
3108 if (FoundD)
3109 return FoundD;
3110
3111 // If this typedef is not in block scope, determine whether we've
3112 // seen a typedef with the same name (that we can merge with) or any
3113 // other entity by that name (which name lookup could conflict with).
3114 if (!DC->isFunctionOrMethod()) {
3115 SmallVector<NamedDecl *, 4> ConflictingDecls;
3116 unsigned IDNS = Decl::IDNS_Ordinary;
3117 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3118 for (auto *FoundDecl : FoundDecls) {
3119 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3120 continue;
3121 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3122 if (IsStructuralMatch(D, FoundAlias))
3123 return Importer.MapImported(D, FoundAlias);
3124 ConflictingDecls.push_back(FoundDecl);
3125 }
3126 }
3127
3128 if (!ConflictingDecls.empty()) {
3129 ExpectedName NameOrErr = Importer.HandleNameConflict(
3130 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3131 if (NameOrErr)
3132 Name = NameOrErr.get();
3133 else
3134 return NameOrErr.takeError();
3135 }
3136 }
3137
3138 Error Err = Error::success();
3139 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3140 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3141 if (Err)
3142 return std::move(Err);
3143
3144 TypeAliasTemplateDecl *ToAlias;
3145 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3146 Name, ToTemplateParameters, ToTemplatedDecl))
3147 return ToAlias;
3148
3149 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3150
3151 ToAlias->setAccess(D->getAccess());
3152 ToAlias->setLexicalDeclContext(LexicalDC);
3153 LexicalDC->addDeclInternal(ToAlias);
3154 if (DC != Importer.getToContext().getTranslationUnitDecl())
3155 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3156 return ToAlias;
3157}
3158
3160 // Import the major distinguishing characteristics of this label.
3161 DeclContext *DC, *LexicalDC;
3162 DeclarationName Name;
3163 SourceLocation Loc;
3164 NamedDecl *ToD;
3165 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3166 return std::move(Err);
3167 if (ToD)
3168 return ToD;
3169
3170 assert(LexicalDC->isFunctionOrMethod());
3171
3172 LabelDecl *ToLabel;
3173 if (D->isGnuLocal()) {
3174 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3175 if (!BeginLocOrErr)
3176 return BeginLocOrErr.takeError();
3177 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3178 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3179 return ToLabel;
3180
3181 } else {
3182 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3183 Name.getAsIdentifierInfo()))
3184 return ToLabel;
3185
3186 }
3187
3188 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3189 if (!ToStmtOrErr)
3190 return ToStmtOrErr.takeError();
3191
3192 ToLabel->setStmt(*ToStmtOrErr);
3193 ToLabel->setLexicalDeclContext(LexicalDC);
3194 LexicalDC->addDeclInternal(ToLabel);
3195 return ToLabel;
3196}
3197
3199 // Import the major distinguishing characteristics of this enum.
3200 DeclContext *DC, *LexicalDC;
3201 DeclarationName Name;
3202 SourceLocation Loc;
3203 NamedDecl *ToD;
3204 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3205 return std::move(Err);
3206 if (ToD)
3207 return ToD;
3208
3209 // Figure out what enum name we're looking for.
3210 unsigned IDNS = Decl::IDNS_Tag;
3211 DeclarationName SearchName = Name;
3212 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3213 if (Error Err = importInto(
3214 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3215 return std::move(Err);
3216 IDNS = Decl::IDNS_Ordinary;
3217 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3218 IDNS |= Decl::IDNS_Ordinary;
3219
3220 // We may already have an enum of the same name; try to find and match it.
3221 EnumDecl *PrevDecl = nullptr;
3222 if (!DC->isFunctionOrMethod()) {
3223 SmallVector<NamedDecl *, 4> ConflictingDecls;
3224 auto FoundDecls =
3225 Importer.findDeclsInToCtx(DC, SearchName);
3226 for (auto *FoundDecl : FoundDecls) {
3227 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3228 continue;
3229
3230 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3231 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3232 FoundDecl = Tag->getDecl();
3233 }
3234
3235 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3236 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3237 continue;
3238 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3239 EnumDecl *FoundDef = FoundEnum->getDefinition();
3240 if (D->isThisDeclarationADefinition() && FoundDef)
3241 return Importer.MapImported(D, FoundDef);
3242 PrevDecl = FoundEnum->getMostRecentDecl();
3243 break;
3244 }
3245 ConflictingDecls.push_back(FoundDecl);
3246 }
3247 }
3248
3249 // In case of unnamed enums, we try to find an existing similar one, if none
3250 // was found, perform the import always.
3251 // Structural in-equivalence is not detected in this way here, but it may
3252 // be found when the parent decl is imported (if the enum is part of a
3253 // class). To make this totally exact a more difficult solution is needed.
3254 if (SearchName && !ConflictingDecls.empty()) {
3255 ExpectedName NameOrErr = Importer.HandleNameConflict(
3256 SearchName, DC, IDNS, ConflictingDecls.data(),
3257 ConflictingDecls.size());
3258 if (NameOrErr)
3259 Name = NameOrErr.get();
3260 else
3261 return NameOrErr.takeError();
3262 }
3263 }
3264
3265 Error Err = Error::success();
3266 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3267 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3268 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3269 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3270 if (Err)
3271 return std::move(Err);
3272
3273 // Create the enum declaration.
3274 EnumDecl *D2;
3275 if (GetImportedOrCreateDecl(
3276 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3277 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3278 D->isScopedUsingClassTag(), D->isFixed()))
3279 return D2;
3280
3281 D2->setQualifierInfo(ToQualifierLoc);
3282 D2->setIntegerType(ToIntegerType);
3283 D2->setBraceRange(ToBraceRange);
3284 D2->setAccess(D->getAccess());
3285 D2->setLexicalDeclContext(LexicalDC);
3286 addDeclToContexts(D, D2);
3287
3289 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3290 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3291 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3292 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3293 else
3294 return ToInstOrErr.takeError();
3295 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3297 else
3298 return POIOrErr.takeError();
3299 }
3300
3301 // Import the definition
3302 if (D->isCompleteDefinition())
3303 if (Error Err = ImportDefinition(D, D2))
3304 return std::move(Err);
3305
3306 return D2;
3307}
3308
3310 bool IsFriendTemplate = false;
3311 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3312 IsFriendTemplate =
3313 DCXX->getDescribedClassTemplate() &&
3314 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3316 }
3317
3318 // Import the major distinguishing characteristics of this record.
3319 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3320 DeclarationName Name;
3321 SourceLocation Loc;
3322 NamedDecl *ToD = nullptr;
3323 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3324 return std::move(Err);
3325 if (ToD)
3326 return ToD;
3327
3328 // Figure out what structure name we're looking for.
3329 unsigned IDNS = Decl::IDNS_Tag;
3330 DeclarationName SearchName = Name;
3331 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3332 if (Error Err = importInto(
3333 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3334 return std::move(Err);
3335 IDNS = Decl::IDNS_Ordinary;
3336 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3338
3339 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3340 : DC->isDependentContext();
3341 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3342
3343 // We may already have a record of the same name; try to find and match it.
3344 RecordDecl *PrevDecl = nullptr;
3345 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3346 SmallVector<NamedDecl *, 4> ConflictingDecls;
3347 auto FoundDecls =
3348 Importer.findDeclsInToCtx(DC, SearchName);
3349 if (!FoundDecls.empty()) {
3350 // We're going to have to compare D against potentially conflicting Decls,
3351 // so complete it.
3354 }
3355
3356 for (auto *FoundDecl : FoundDecls) {
3357 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3358 continue;
3359
3360 Decl *Found = FoundDecl;
3361 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3362 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3363 Found = Tag->getDecl();
3364 }
3365
3366 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3367 // Do not emit false positive diagnostic in case of unnamed
3368 // struct/union and in case of anonymous structs. Would be false
3369 // because there may be several anonymous/unnamed structs in a class.
3370 // E.g. these are both valid:
3371 // struct A { // unnamed structs
3372 // struct { struct A *next; } entry0;
3373 // struct { struct A *next; } entry1;
3374 // };
3375 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3376 if (!SearchName)
3377 if (!IsStructuralMatch(D, FoundRecord, false))
3378 continue;
3379
3380 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3381 continue;
3382
3383 if (IsStructuralMatch(D, FoundRecord)) {
3384 RecordDecl *FoundDef = FoundRecord->getDefinition();
3385 if (D->isThisDeclarationADefinition() && FoundDef) {
3386 // FIXME: Structural equivalence check should check for same
3387 // user-defined methods.
3388 Importer.MapImported(D, FoundDef);
3389 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3390 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3391 assert(FoundCXX && "Record type mismatch");
3392
3393 if (!Importer.isMinimalImport())
3394 // FoundDef may not have every implicit method that D has
3395 // because implicit methods are created only if they are used.
3396 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3397 return std::move(Err);
3398 }
3399 // FIXME: We can return FoundDef here.
3400 }
3401 PrevDecl = FoundRecord->getMostRecentDecl();
3402 break;
3403 }
3404 ConflictingDecls.push_back(FoundDecl);
3405 } // kind is RecordDecl
3406 } // for
3407
3408 if (!ConflictingDecls.empty() && SearchName) {
3409 ExpectedName NameOrErr = Importer.HandleNameConflict(
3410 SearchName, DC, IDNS, ConflictingDecls.data(),
3411 ConflictingDecls.size());
3412 if (NameOrErr)
3413 Name = NameOrErr.get();
3414 else
3415 return NameOrErr.takeError();
3416 }
3417 }
3418
3419 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3420 if (!BeginLocOrErr)
3421 return BeginLocOrErr.takeError();
3422
3423 // Create the record declaration.
3424 RecordDecl *D2 = nullptr;
3425 CXXRecordDecl *D2CXX = nullptr;
3426 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3427 if (DCXX->isLambda()) {
3428 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3429 if (!TInfoOrErr)
3430 return TInfoOrErr.takeError();
3431 if (GetImportedOrCreateSpecialDecl(
3432 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3433 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3434 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3435 return D2CXX;
3436 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3437 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3438 if (!CDeclOrErr)
3439 return CDeclOrErr.takeError();
3440 Numbering.ContextDecl = *CDeclOrErr;
3441 D2CXX->setLambdaNumbering(Numbering);
3442 } else {
3443 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3444 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3445 Name.getAsIdentifierInfo(),
3446 cast_or_null<CXXRecordDecl>(PrevDecl)))
3447 return D2CXX;
3448 }
3449
3450 D2 = D2CXX;
3451 D2->setAccess(D->getAccess());
3452 D2->setLexicalDeclContext(LexicalDC);
3453 addDeclToContexts(D, D2);
3454
3455 if (ClassTemplateDecl *FromDescribed =
3456 DCXX->getDescribedClassTemplate()) {
3457 ClassTemplateDecl *ToDescribed;
3458 if (Error Err = importInto(ToDescribed, FromDescribed))
3459 return std::move(Err);
3460 D2CXX->setDescribedClassTemplate(ToDescribed);
3461 } else if (MemberSpecializationInfo *MemberInfo =
3462 DCXX->getMemberSpecializationInfo()) {
3464 MemberInfo->getTemplateSpecializationKind();
3466
3467 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3468 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3469 else
3470 return ToInstOrErr.takeError();
3471
3472 if (ExpectedSLoc POIOrErr =
3473 import(MemberInfo->getPointOfInstantiation()))
3475 *POIOrErr);
3476 else
3477 return POIOrErr.takeError();
3478 }
3479
3480 } else {
3481 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3482 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3483 Name.getAsIdentifierInfo(), PrevDecl))
3484 return D2;
3485 D2->setLexicalDeclContext(LexicalDC);
3486 addDeclToContexts(D, D2);
3487 }
3488
3489 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3490 D2->setBraceRange(*BraceRangeOrErr);
3491 else
3492 return BraceRangeOrErr.takeError();
3493 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3494 D2->setQualifierInfo(*QualifierLocOrErr);
3495 else
3496 return QualifierLocOrErr.takeError();
3497
3498 if (D->isAnonymousStructOrUnion())
3499 D2->setAnonymousStructOrUnion(true);
3500
3501 if (D->isCompleteDefinition())
3502 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3503 return std::move(Err);
3504
3505 return D2;
3506}
3507
3509 // Import the major distinguishing characteristics of this enumerator.
3510 DeclContext *DC, *LexicalDC;
3511 DeclarationName Name;
3512 SourceLocation Loc;
3513 NamedDecl *ToD;
3514 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3515 return std::move(Err);
3516 if (ToD)
3517 return ToD;
3518
3519 // Determine whether there are any other declarations with the same name and
3520 // in the same context.
3521 if (!LexicalDC->isFunctionOrMethod()) {
3522 SmallVector<NamedDecl *, 4> ConflictingDecls;
3523 unsigned IDNS = Decl::IDNS_Ordinary;
3524 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3525 for (auto *FoundDecl : FoundDecls) {
3526 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3527 continue;
3528
3529 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3530 if (IsStructuralMatch(D, FoundEnumConstant))
3531 return Importer.MapImported(D, FoundEnumConstant);
3532 ConflictingDecls.push_back(FoundDecl);
3533 }
3534 }
3535
3536 if (!ConflictingDecls.empty()) {
3537 ExpectedName NameOrErr = Importer.HandleNameConflict(
3538 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3539 if (NameOrErr)
3540 Name = NameOrErr.get();
3541 else
3542 return NameOrErr.takeError();
3543 }
3544 }
3545
3546 ExpectedType TypeOrErr = import(D->getType());
3547 if (!TypeOrErr)
3548 return TypeOrErr.takeError();
3549
3550 ExpectedExpr InitOrErr = import(D->getInitExpr());
3551 if (!InitOrErr)
3552 return InitOrErr.takeError();
3553
3554 EnumConstantDecl *ToEnumerator;
3555 if (GetImportedOrCreateDecl(
3556 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3557 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3558 return ToEnumerator;
3559
3560 ToEnumerator->setAccess(D->getAccess());
3561 ToEnumerator->setLexicalDeclContext(LexicalDC);
3562 LexicalDC->addDeclInternal(ToEnumerator);
3563 return ToEnumerator;
3564}
3565
3566template <typename DeclTy>
3568 DeclTy *ToD) {
3569 unsigned int Num = FromD->getNumTemplateParameterLists();
3570 if (Num == 0)
3571 return Error::success();
3573 for (unsigned int I = 0; I < Num; ++I)
3574 if (Expected<TemplateParameterList *> ToTPListOrErr =
3575 import(FromD->getTemplateParameterList(I)))
3576 ToTPLists[I] = *ToTPListOrErr;
3577 else
3578 return ToTPListOrErr.takeError();
3579 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3580 return Error::success();
3581}
3582
3584 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3585 switch (FromFD->getTemplatedKind()) {
3588 return Error::success();
3589
3591 if (Expected<FunctionDecl *> InstFDOrErr =
3592 import(FromFD->getInstantiatedFromDecl()))
3593 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3594 return Error::success();
3597
3598 if (Expected<FunctionDecl *> InstFDOrErr =
3599 import(FromFD->getInstantiatedFromMemberFunction()))
3600 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3601 else
3602 return InstFDOrErr.takeError();
3603
3604 if (ExpectedSLoc POIOrErr = import(
3607 else
3608 return POIOrErr.takeError();
3609
3610 return Error::success();
3611 }
3612
3614 auto FunctionAndArgsOrErr =
3616 if (!FunctionAndArgsOrErr)
3617 return FunctionAndArgsOrErr.takeError();
3618
3620 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3621
3622 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3623 TemplateArgumentListInfo ToTAInfo;
3624 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3625 if (FromTAArgsAsWritten)
3627 *FromTAArgsAsWritten, ToTAInfo))
3628 return Err;
3629
3630 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3631 if (!POIOrErr)
3632 return POIOrErr.takeError();
3633
3634 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3635 return Err;
3636
3637 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3638 ToFD->setFunctionTemplateSpecialization(
3639 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3640 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3641 return Error::success();
3642 }
3643
3645 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3646 UnresolvedSet<8> Candidates;
3647 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3648 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3649 Candidates.addDecl(*ToFTDOrErr);
3650 else
3651 return ToFTDOrErr.takeError();
3652 }
3653
3654 // Import TemplateArgumentListInfo.
3655 TemplateArgumentListInfo ToTAInfo;
3656 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3657 if (FromTAArgsAsWritten)
3658 if (Error Err =
3659 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3660 return Err;
3661
3663 Importer.getToContext(), Candidates,
3664 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3665 return Error::success();
3666 }
3667 }
3668 llvm_unreachable("All cases should be covered!");
3669}
3670
3673 auto FunctionAndArgsOrErr =
3675 if (!FunctionAndArgsOrErr)
3676 return FunctionAndArgsOrErr.takeError();
3677
3679 TemplateArgsTy ToTemplArgs;
3680 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3681 void *InsertPos = nullptr;
3682 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3683 return FoundSpec;
3684}
3685
3687 FunctionDecl *ToFD) {
3688 if (Stmt *FromBody = FromFD->getBody()) {
3689 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3690 ToFD->setBody(*ToBodyOrErr);
3691 else
3692 return ToBodyOrErr.takeError();
3693 }
3694 return Error::success();
3695}
3696
3697// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3698// which is equal to the given DC, or D is equal to DC.
3699static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3700 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3701 if (!DCi)
3702 DCi = D->getDeclContext();
3703 assert(DCi && "Declaration should have a context");
3704 while (DCi != D->getTranslationUnitDecl()) {
3705 if (DCi == DC)
3706 return true;
3707 DCi = DCi->getParent();
3708 }
3709 return false;
3710}
3711
3712// Check if there is a declaration that has 'DC' as parent context and is
3713// referenced from statement 'S' or one of its children. The search is done in
3714// BFS order through children of 'S'.
3715static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3716 SmallVector<const Stmt *> ToProcess;
3717 ToProcess.push_back(S);
3718 while (!ToProcess.empty()) {
3719 const Stmt *CurrentS = ToProcess.pop_back_val();
3720 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3721 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3722 if (const Decl *D = DeclRef->getDecl())
3723 if (isAncestorDeclContextOf(DC, D))
3724 return true;
3725 } else if (const auto *E =
3726 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3727 if (const Decl *D = E->getAssociatedDecl())
3728 if (isAncestorDeclContextOf(DC, D))
3729 return true;
3730 }
3731 }
3732 return false;
3733}
3734
3735namespace {
3736/// Check if a type has any reference to a declaration that is inside the body
3737/// of a function.
3738/// The \c CheckType(QualType) function should be used to determine
3739/// this property.
3740///
3741/// The type visitor visits one type object only (not recursive).
3742/// To find all referenced declarations we must discover all type objects until
3743/// the canonical type is reached (walk over typedef and similar objects). This
3744/// is done by loop over all "sugar" type objects. For every such type we must
3745/// check all declarations that are referenced from it. For this check the
3746/// visitor is used. In the visit functions all referenced declarations except
3747/// the one that follows in the sugar chain (if any) must be checked. For this
3748/// check the same visitor is re-used (it has no state-dependent data).
3749///
3750/// The visit functions have 3 possible return values:
3751/// - True, found a declaration inside \c ParentDC.
3752/// - False, found declarations only outside \c ParentDC and it is not possible
3753/// to find more declarations (the "sugar" chain does not continue).
3754/// - Empty optional value, found no declarations or only outside \c ParentDC,
3755/// but it is possible to find more declarations in the type "sugar" chain.
3756/// The loop over the "sugar" types can be implemented by using type visit
3757/// functions only (call \c CheckType with the desugared type). With the current
3758/// solution no visit function is needed if the type has only a desugared type
3759/// as data.
3760class IsTypeDeclaredInsideVisitor
3761 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3762public:
3763 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3764 : ParentDC(ParentDC) {}
3765
3766 bool CheckType(QualType T) {
3767 // Check the chain of "sugar" types.
3768 // The "sugar" types are typedef or similar types that have the same
3769 // canonical type.
3770 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3771 return *Res;
3772 QualType DsT =
3773 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3774 while (DsT != T) {
3775 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3776 return *Res;
3777 T = DsT;
3778 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3779 }
3780 return false;
3781 }
3782
3783 std::optional<bool> VisitTagType(const TagType *T) {
3784 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3785 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3786 if (checkTemplateArgument(Arg))
3787 return true;
3788 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3789 }
3790
3791 std::optional<bool> VisitPointerType(const PointerType *T) {
3792 return CheckType(T->getPointeeType());
3793 }
3794
3795 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3796 return CheckType(T->getPointeeTypeAsWritten());
3797 }
3798
3799 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3800 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3801 }
3802
3803 std::optional<bool> VisitUsingType(const UsingType *T) {
3804 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3805 }
3806
3807 std::optional<bool>
3808 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3809 for (const auto &Arg : T->template_arguments())
3810 if (checkTemplateArgument(Arg))
3811 return true;
3812 // This type is a "sugar" to a record type, it can have a desugared type.
3813 return {};
3814 }
3815
3816 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3817 return CheckType(T->getBaseType());
3818 }
3819
3820 std::optional<bool>
3821 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3822 // The "associated declaration" can be the same as ParentDC.
3823 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3824 return true;
3825 return {};
3826 }
3827
3828 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3829 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3830 return true;
3831
3832 return CheckType(T->getElementType());
3833 }
3834
3835 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3836 llvm_unreachable(
3837 "Variable array should not occur in deduced return type of a function");
3838 }
3839
3840 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3841 llvm_unreachable("Incomplete array should not occur in deduced return type "
3842 "of a function");
3843 }
3844
3845 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3846 llvm_unreachable("Dependent array should not occur in deduced return type "
3847 "of a function");
3848 }
3849
3850private:
3851 const DeclContext *const ParentDC;
3852
3853 bool checkTemplateArgument(const TemplateArgument &Arg) {
3854 switch (Arg.getKind()) {
3856 return false;
3858 return CheckType(Arg.getIntegralType());
3860 return CheckType(Arg.getAsType());
3862 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3864 // FIXME: The declaration in this case is not allowed to be in a function?
3865 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3867 // FIXME: The type is not allowed to be in the function?
3868 return CheckType(Arg.getNullPtrType());
3870 return CheckType(Arg.getStructuralValueType());
3872 for (const auto &PackArg : Arg.getPackAsArray())
3873 if (checkTemplateArgument(PackArg))
3874 return true;
3875 return false;
3877 // Templates can not be defined locally in functions.
3878 // A template passed as argument can be not in ParentDC.
3879 return false;
3881 // Templates can not be defined locally in functions.
3882 // A template passed as argument can be not in ParentDC.
3883 return false;
3884 }
3885 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3886 };
3887};
3888} // namespace
3889
3890/// This function checks if the given function has a return type that contains
3891/// a reference (in any way) to a declaration inside the same function.
3893 QualType FromTy = D->getType();
3894 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3895 assert(FromFPT && "Must be called on FunctionProtoType");
3896
3897 auto IsCXX11Lambda = [&]() {
3898 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3899 return false;
3900
3901 return isLambdaMethod(D);
3902 };
3903
3904 QualType RetT = FromFPT->getReturnType();
3905 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3906 FunctionDecl *Def = D->getDefinition();
3907 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3908 return Visitor.CheckType(RetT);
3909 }
3910
3911 return false;
3912}
3913
3915ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3916 Expr *ExplicitExpr = ESpec.getExpr();
3917 if (ExplicitExpr)
3918 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3919 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3920}
3921
3923
3925 auto RedeclIt = Redecls.begin();
3926 // Import the first part of the decl chain. I.e. import all previous
3927 // declarations starting from the canonical decl.
3928 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3929 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3930 if (!ToRedeclOrErr)
3931 return ToRedeclOrErr.takeError();
3932 }
3933 assert(*RedeclIt == D);
3934
3935 // Import the major distinguishing characteristics of this function.
3936 DeclContext *DC, *LexicalDC;
3937 DeclarationName Name;
3938 SourceLocation Loc;
3939 NamedDecl *ToD;
3940 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3941 return std::move(Err);
3942 if (ToD)
3943 return ToD;
3944
3945 FunctionDecl *FoundByLookup = nullptr;
3947
3948 // If this is a function template specialization, then try to find the same
3949 // existing specialization in the "to" context. The lookup below will not
3950 // find any specialization, but would find the primary template; thus, we
3951 // have to skip normal lookup in case of specializations.
3952 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3953 if (D->getTemplatedKind() ==
3955 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3956 if (!FoundFunctionOrErr)
3957 return FoundFunctionOrErr.takeError();
3958 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3959 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3960 return Def;
3961 FoundByLookup = FoundFunction;
3962 }
3963 }
3964 // Try to find a function in our own ("to") context with the same name, same
3965 // type, and in the same context as the function we're importing.
3966 else if (!LexicalDC->isFunctionOrMethod()) {
3967 SmallVector<NamedDecl *, 4> ConflictingDecls;
3969 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3970 for (auto *FoundDecl : FoundDecls) {
3971 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3972 continue;
3973
3974 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3975 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3976 continue;
3977
3978 if (IsStructuralMatch(D, FoundFunction)) {
3979 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3980 return Def;
3981 FoundByLookup = FoundFunction;
3982 break;
3983 }
3984 // FIXME: Check for overloading more carefully, e.g., by boosting
3985 // Sema::IsOverload out to the AST library.
3986
3987 // Function overloading is okay in C++.
3988 if (Importer.getToContext().getLangOpts().CPlusPlus)
3989 continue;
3990
3991 // Complain about inconsistent function types.
3992 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3993 << Name << D->getType() << FoundFunction->getType();
3994 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3995 << FoundFunction->getType();
3996 ConflictingDecls.push_back(FoundDecl);
3997 }
3998 }
3999
4000 if (!ConflictingDecls.empty()) {
4001 ExpectedName NameOrErr = Importer.HandleNameConflict(
4002 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4003 if (NameOrErr)
4004 Name = NameOrErr.get();
4005 else
4006 return NameOrErr.takeError();
4007 }
4008 }
4009
4010 // We do not allow more than one in-class declaration of a function. This is
4011 // because AST clients like VTableBuilder asserts on this. VTableBuilder
4012 // assumes there is only one in-class declaration. Building a redecl
4013 // chain would result in more than one in-class declaration for
4014 // overrides (even if they are part of the same redecl chain inside the
4015 // derived class.)
4016 if (FoundByLookup) {
4017 if (isa<CXXMethodDecl>(FoundByLookup)) {
4018 if (D->getLexicalDeclContext() == D->getDeclContext()) {
4019 if (!D->doesThisDeclarationHaveABody()) {
4020 if (FunctionTemplateDecl *DescribedD =
4022 // Handle a "templated" function together with its described
4023 // template. This avoids need for a similar check at import of the
4024 // described template.
4025 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4026 "Templated function mapped to non-templated?");
4027 Importer.MapImported(DescribedD,
4028 FoundByLookup->getDescribedFunctionTemplate());
4029 }
4030 return Importer.MapImported(D, FoundByLookup);
4031 } else {
4032 // Let's continue and build up the redecl chain in this case.
4033 // FIXME Merge the functions into one decl.
4034 }
4035 }
4036 }
4037 }
4038
4039 DeclarationNameInfo NameInfo(Name, Loc);
4040 // Import additional name location/type info.
4041 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4042 return std::move(Err);
4043
4044 QualType FromTy = D->getType();
4045 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4046 // Set to true if we do not import the type of the function as is. There are
4047 // cases when the original type would result in an infinite recursion during
4048 // the import. To avoid an infinite recursion when importing, we create the
4049 // FunctionDecl with a simplified function type and update it only after the
4050 // relevant AST nodes are already imported.
4051 // The type is related to TypeSourceInfo (it references the type), so we must
4052 // do the same with TypeSourceInfo.
4053 bool UsedDifferentProtoType = false;
4054 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4055 QualType FromReturnTy = FromFPT->getReturnType();
4056 // Functions with auto return type may define a struct inside their body
4057 // and the return type could refer to that struct.
4058 // E.g.: auto foo() { struct X{}; return X(); }
4059 // To avoid an infinite recursion when importing, create the FunctionDecl
4060 // with a simplified return type.
4061 // Reuse this approach for auto return types declared as typenames from
4062 // template params, tracked in FindFunctionDeclImportCycle.
4064 Importer.FindFunctionDeclImportCycle.isCycle(D)) {
4065 FromReturnTy = Importer.getFromContext().VoidTy;
4066 UsedDifferentProtoType = true;
4067 }
4068 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4069 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4070 // FunctionDecl that we are importing the FunctionProtoType for.
4071 // To avoid an infinite recursion when importing, create the FunctionDecl
4072 // with a simplified function type.
4073 if (FromEPI.ExceptionSpec.SourceDecl ||
4074 FromEPI.ExceptionSpec.SourceTemplate ||
4075 FromEPI.ExceptionSpec.NoexceptExpr) {
4077 FromEPI = DefaultEPI;
4078 UsedDifferentProtoType = true;
4079 }
4080 FromTy = Importer.getFromContext().getFunctionType(
4081 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4082 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4083 FromTy, D->getBeginLoc());
4084 }
4085
4086 Error Err = Error::success();
4087 auto ScopedReturnTypeDeclCycleDetector =
4088 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
4089 auto T = importChecked(Err, FromTy);
4090 auto TInfo = importChecked(Err, FromTSI);
4091 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4092 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4093 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4094 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4095 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4096 TrailingRequiresClause.ConstraintExpr =
4097 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4098 if (Err)
4099 return std::move(Err);
4100
4101 // Import the function parameters.
4103 for (auto *P : D->parameters()) {
4104 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4105 Parameters.push_back(*ToPOrErr);
4106 else
4107 return ToPOrErr.takeError();
4108 }
4109
4110 // Create the imported function.
4111 FunctionDecl *ToFunction = nullptr;
4112 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4113 ExplicitSpecifier ESpec =
4114 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4115 if (Err)
4116 return std::move(Err);
4117 auto ToInheritedConstructor = InheritedConstructor();
4118 if (FromConstructor->isInheritingConstructor()) {
4119 Expected<InheritedConstructor> ImportedInheritedCtor =
4120 import(FromConstructor->getInheritedConstructor());
4121 if (!ImportedInheritedCtor)
4122 return ImportedInheritedCtor.takeError();
4123 ToInheritedConstructor = *ImportedInheritedCtor;
4124 }
4125 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4126 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4127 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4129 ToInheritedConstructor, TrailingRequiresClause))
4130 return ToFunction;
4131 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4132
4133 Error Err = Error::success();
4134 auto ToOperatorDelete = importChecked(
4135 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4136 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4137 if (Err)
4138 return std::move(Err);
4139
4140 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4141 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4142 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4144 TrailingRequiresClause))
4145 return ToFunction;
4146
4147 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4148
4149 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4150 } else if (CXXConversionDecl *FromConversion =
4151 dyn_cast<CXXConversionDecl>(D)) {
4152 ExplicitSpecifier ESpec =
4153 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4154 if (Err)
4155 return std::move(Err);
4156 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4157 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4158 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4159 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4160 SourceLocation(), TrailingRequiresClause))
4161 return ToFunction;
4162 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4163 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4164 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4165 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4166 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4167 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4168 return ToFunction;
4169 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4170 ExplicitSpecifier ESpec =
4171 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4172 CXXConstructorDecl *Ctor =
4173 importChecked(Err, Guide->getCorrespondingConstructor());
4174 const CXXDeductionGuideDecl *SourceDG =
4175 importChecked(Err, Guide->getSourceDeductionGuide());
4176 if (Err)
4177 return std::move(Err);
4178 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4179 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4180 NameInfo, T, TInfo, ToEndLoc, Ctor,
4181 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4182 SourceDG, Guide->getSourceDeductionGuideKind()))
4183 return ToFunction;
4184 } else {
4185 if (GetImportedOrCreateDecl(
4186 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4187 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4189 D->getConstexprKind(), TrailingRequiresClause))
4190 return ToFunction;
4191 }
4192
4193 // Connect the redecl chain.
4194 if (FoundByLookup) {
4195 auto *Recent = const_cast<FunctionDecl *>(
4196 FoundByLookup->getMostRecentDecl());
4197 ToFunction->setPreviousDecl(Recent);
4198 // FIXME Probably we should merge exception specifications. E.g. In the
4199 // "To" context the existing function may have exception specification with
4200 // noexcept-unevaluated, while the newly imported function may have an
4201 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4202 // decl and its redeclarations may be required.
4203 }
4204
4205 StringLiteral *Msg = D->getDeletedMessage();
4206 if (Msg) {
4207 auto Imported = import(Msg);
4208 if (!Imported)
4209 return Imported.takeError();
4210 Msg = *Imported;
4211 }
4212
4213 ToFunction->setQualifierInfo(ToQualifierLoc);
4214 ToFunction->setAccess(D->getAccess());
4215 ToFunction->setLexicalDeclContext(LexicalDC);
4216 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4217 ToFunction->setTrivial(D->isTrivial());
4218 ToFunction->setIsPureVirtual(D->isPureVirtual());
4219 ToFunction->setDefaulted(D->isDefaulted());
4221 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4227 ToFunction->setRangeEnd(ToEndLoc);
4228 ToFunction->setDefaultLoc(ToDefaultLoc);
4229
4230 if (Msg)
4231 ToFunction->setDefaultedOrDeletedInfo(
4233 Importer.getToContext(), {}, Msg));
4234
4235 // Set the parameters.
4236 for (auto *Param : Parameters) {
4237 Param->setOwningFunction(ToFunction);
4238 ToFunction->addDeclInternal(Param);
4239 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4240 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4241 }
4242 ToFunction->setParams(Parameters);
4243
4244 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4245 // params it refers to.
4246 if (TInfo) {
4247 if (auto ProtoLoc =
4248 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4249 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4250 ProtoLoc.setParam(I, Parameters[I]);
4251 }
4252 }
4253
4254 // Import the describing template function, if any.
4255 if (FromFT) {
4256 auto ToFTOrErr = import(FromFT);
4257 if (!ToFTOrErr)
4258 return ToFTOrErr.takeError();
4259 }
4260
4261 // Import Ctor initializers.
4262 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4263 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4264 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4265 // Import first, then allocate memory and copy if there was no error.
4266 if (Error Err = ImportContainerChecked(
4267 FromConstructor->inits(), CtorInitializers))
4268 return std::move(Err);
4269 auto **Memory =
4270 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4271 llvm::copy(CtorInitializers, Memory);
4272 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4273 ToCtor->setCtorInitializers(Memory);
4274 ToCtor->setNumCtorInitializers(NumInitializers);
4275 }
4276 }
4277
4278 // If it is a template, import all related things.
4279 if (Error Err = ImportTemplateInformation(D, ToFunction))
4280 return std::move(Err);
4281
4282 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4284 FromCXXMethod))
4285 return std::move(Err);
4286
4288 Error Err = ImportFunctionDeclBody(D, ToFunction);
4289
4290 if (Err)
4291 return std::move(Err);
4292 }
4293
4294 // Import and set the original type in case we used another type.
4295 if (UsedDifferentProtoType) {
4296 if (ExpectedType TyOrErr = import(D->getType()))
4297 ToFunction->setType(*TyOrErr);
4298 else
4299 return TyOrErr.takeError();
4300 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4301 ToFunction->setTypeSourceInfo(*TSIOrErr);
4302 else
4303 return TSIOrErr.takeError();
4304 }
4305
4306 // FIXME: Other bits to merge?
4307
4308 addDeclToContexts(D, ToFunction);
4309
4310 // Import the rest of the chain. I.e. import all subsequent declarations.
4311 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4312 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4313 if (!ToRedeclOrErr)
4314 return ToRedeclOrErr.takeError();
4315 }
4316
4317 return ToFunction;
4318}
4319
4323
4327
4331
4335
4340
4342 // Import the major distinguishing characteristics of a variable.
4343 DeclContext *DC, *LexicalDC;
4344 DeclarationName Name;
4345 SourceLocation Loc;
4346 NamedDecl *ToD;
4347 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4348 return std::move(Err);
4349 if (ToD)
4350 return ToD;
4351
4352 // Determine whether we've already imported this field.
4353 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4354 for (auto *FoundDecl : FoundDecls) {
4355 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4356 // For anonymous fields, match up by index.
4357 if (!Name &&
4359 ASTImporter::getFieldIndex(FoundField))
4360 continue;
4361
4362 if (Importer.IsStructurallyEquivalent(D->getType(),
4363 FoundField->getType())) {
4364 Importer.MapImported(D, FoundField);
4365 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4366 // initializer of a FieldDecl might not had been instantiated in the
4367 // "To" context. However, the "From" context might instantiated that,
4368 // thus we have to merge that.
4369 // Note: `hasInClassInitializer()` is not the same as non-null
4370 // `getInClassInitializer()` value.
4371 if (Expr *FromInitializer = D->getInClassInitializer()) {
4372 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4373 // Import of the FromInitializer may result in the setting of
4374 // InClassInitializer. If not, set it here.
4375 assert(FoundField->hasInClassInitializer() &&
4376 "Field should have an in-class initializer if it has an "
4377 "expression for it.");
4378 if (!FoundField->getInClassInitializer())
4379 FoundField->setInClassInitializer(*ToInitializerOrErr);
4380 } else {
4381 return ToInitializerOrErr.takeError();
4382 }
4383 }
4384 return FoundField;
4385 }
4386
4387 // FIXME: Why is this case not handled with calling HandleNameConflict?
4388 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4389 << Name << D->getType() << FoundField->getType();
4390 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4391 << FoundField->getType();
4392
4393 return make_error<ASTImportError>(ASTImportError::NameConflict);
4394 }
4395 }
4396
4397 Error Err = Error::success();
4398 auto ToType = importChecked(Err, D->getType());
4399 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4400 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4401 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4402 if (Err)
4403 return std::move(Err);
4404 const Type *ToCapturedVLAType = nullptr;
4405 if (Error Err = Importer.importInto(
4406 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4407 return std::move(Err);
4408
4409 FieldDecl *ToField;
4410 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4411 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4412 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4413 D->getInClassInitStyle()))
4414 return ToField;
4415
4416 ToField->setAccess(D->getAccess());
4417 ToField->setLexicalDeclContext(LexicalDC);
4418 ToField->setImplicit(D->isImplicit());
4419 if (ToCapturedVLAType)
4420 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4421 LexicalDC->addDeclInternal(ToField);
4422 // Import initializer only after the field was created, it may have recursive
4423 // reference to the field.
4424 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4425 if (Err)
4426 return std::move(Err);
4427 if (ToInitializer) {
4428 auto *AlreadyImported = ToField->getInClassInitializer();
4429 if (AlreadyImported)
4430 assert(ToInitializer == AlreadyImported &&
4431 "Duplicate import of in-class initializer.");
4432 else
4433 ToField->setInClassInitializer(ToInitializer);
4434 }
4435
4436 return ToField;
4437}
4438
4440 // Import the major distinguishing characteristics of a variable.
4441 DeclContext *DC, *LexicalDC;
4442 DeclarationName Name;
4443 SourceLocation Loc;
4444 NamedDecl *ToD;
4445 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4446 return std::move(Err);
4447 if (ToD)
4448 return ToD;
4449
4450 // Determine whether we've already imported this field.
4451 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4452 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4453 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4454 // For anonymous indirect fields, match up by index.
4455 if (!Name &&
4457 ASTImporter::getFieldIndex(FoundField))
4458 continue;
4459
4460 if (Importer.IsStructurallyEquivalent(D->getType(),
4461 FoundField->getType(),
4462 !Name.isEmpty())) {
4463 Importer.MapImported(D, FoundField);
4464 return FoundField;
4465 }
4466
4467 // If there are more anonymous fields to check, continue.
4468 if (!Name && I < N-1)
4469 continue;
4470
4471 // FIXME: Why is this case not handled with calling HandleNameConflict?
4472 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4473 << Name << D->getType() << FoundField->getType();
4474 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4475 << FoundField->getType();
4476
4477 return make_error<ASTImportError>(ASTImportError::NameConflict);
4478 }
4479 }
4480
4481 // Import the type.
4482 auto TypeOrErr = import(D->getType());
4483 if (!TypeOrErr)
4484 return TypeOrErr.takeError();
4485
4486 auto **NamedChain =
4487 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4488
4489 unsigned i = 0;
4490 for (auto *PI : D->chain())
4491 if (Expected<NamedDecl *> ToD = import(PI))
4492 NamedChain[i++] = *ToD;
4493 else
4494 return ToD.takeError();
4495
4496 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4497 IndirectFieldDecl *ToIndirectField;
4498 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4499 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4500 // FIXME here we leak `NamedChain` which is allocated before
4501 return ToIndirectField;
4502
4503 ToIndirectField->setAccess(D->getAccess());
4504 ToIndirectField->setLexicalDeclContext(LexicalDC);
4505 LexicalDC->addDeclInternal(ToIndirectField);
4506 return ToIndirectField;
4507}
4508
4509/// Used as return type of getFriendCountAndPosition.
4511 /// Number of similar looking friends.
4512 unsigned int TotalCount;
4513 /// Index of the specific FriendDecl.
4514 unsigned int IndexOfDecl;
4515};
4516
4517static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4518 FriendDecl *FD2) {
4519 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4520 return false;
4521
4522 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4523 return Importer.IsStructurallyEquivalent(
4524 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4525
4526 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4528 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4529 FD2->getASTContext(), NonEquivalentDecls,
4531 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4532 return Ctx.IsEquivalent(FD1, FD2);
4533}
4534
4536 FriendDecl *FD) {
4537 unsigned int FriendCount = 0;
4538 UnsignedOrNone FriendPosition = std::nullopt;
4539 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4540
4541 for (FriendDecl *FoundFriend : RD->friends()) {
4542 if (FoundFriend == FD) {
4543 FriendPosition = FriendCount;
4544 ++FriendCount;
4545 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4546 ++FriendCount;
4547 }
4548 }
4549
4550 assert(FriendPosition && "Friend decl not found in own parent.");
4551
4552 return {FriendCount, *FriendPosition};
4553}
4554
4556 // Import the major distinguishing characteristics of a declaration.
4557 DeclContext *DC, *LexicalDC;
4558 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4559 return std::move(Err);
4560
4561 // Determine whether we've already imported this decl.
4562 // FriendDecl is not a NamedDecl so we cannot use lookup.
4563 // We try to maintain order and count of redundant friend declarations.
4564 const auto *RD = cast<CXXRecordDecl>(DC);
4565 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4566 for (FriendDecl *ImportedFriend : RD->friends())
4567 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4568 ImportedEquivalentFriends.push_back(ImportedFriend);
4569
4570 FriendCountAndPosition CountAndPosition =
4571 getFriendCountAndPosition(Importer, D);
4572
4573 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4574 "Class with non-matching friends is imported, ODR check wrong?");
4575 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4576 return Importer.MapImported(
4577 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4578
4579 // Not found. Create it.
4580 // The declarations will be put into order later by ImportDeclContext.
4582 if (NamedDecl *FriendD = D->getFriendDecl()) {
4583 NamedDecl *ToFriendD;
4584 if (Error Err = importInto(ToFriendD, FriendD))
4585 return std::move(Err);
4586
4587 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4588 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4589 ToFriendD->setObjectOfFriendDecl(false);
4590
4591 ToFU = ToFriendD;
4592 } else { // The friend is a type, not a decl.
4593 if (auto TSIOrErr = import(D->getFriendType()))
4594 ToFU = *TSIOrErr;
4595 else
4596 return TSIOrErr.takeError();
4597 }
4598
4599 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4600 auto **FromTPLists = D->getTrailingObjects();
4601 for (unsigned I = 0; I < D->NumTPLists; I++) {
4602 if (auto ListOrErr = import(FromTPLists[I]))
4603 ToTPLists[I] = *ListOrErr;
4604 else
4605 return ListOrErr.takeError();
4606 }
4607
4608 auto LocationOrErr = import(D->getLocation());
4609 if (!LocationOrErr)
4610 return LocationOrErr.takeError();
4611 auto FriendLocOrErr = import(D->getFriendLoc());
4612 if (!FriendLocOrErr)
4613 return FriendLocOrErr.takeError();
4614 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4615 if (!EllipsisLocOrErr)
4616 return EllipsisLocOrErr.takeError();
4617
4618 FriendDecl *FrD;
4619 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4620 *LocationOrErr, ToFU, *FriendLocOrErr,
4621 *EllipsisLocOrErr, ToTPLists))
4622 return FrD;
4623
4624 FrD->setAccess(D->getAccess());
4625 FrD->setLexicalDeclContext(LexicalDC);
4626 LexicalDC->addDeclInternal(FrD);
4627 return FrD;
4628}
4629
4631 // Import the major distinguishing characteristics of an ivar.
4632 DeclContext *DC, *LexicalDC;
4633 DeclarationName Name;
4634 SourceLocation Loc;
4635 NamedDecl *ToD;
4636 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4637 return std::move(Err);
4638 if (ToD)
4639 return ToD;
4640
4641 // Determine whether we've already imported this ivar
4642 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4643 for (auto *FoundDecl : FoundDecls) {
4644 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4645 if (Importer.IsStructurallyEquivalent(D->getType(),
4646 FoundIvar->getType())) {
4647 Importer.MapImported(D, FoundIvar);
4648 return FoundIvar;
4649 }
4650
4651 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4652 << Name << D->getType() << FoundIvar->getType();
4653 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4654 << FoundIvar->getType();
4655
4656 return make_error<ASTImportError>(ASTImportError::NameConflict);
4657 }
4658 }
4659
4660 Error Err = Error::success();
4661 auto ToType = importChecked(Err, D->getType());
4662 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4663 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4664 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4665 if (Err)
4666 return std::move(Err);
4667
4668 ObjCIvarDecl *ToIvar;
4669 if (GetImportedOrCreateDecl(
4670 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4671 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4672 ToType, ToTypeSourceInfo,
4673 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4674 return ToIvar;
4675
4676 ToIvar->setLexicalDeclContext(LexicalDC);
4677 LexicalDC->addDeclInternal(ToIvar);
4678 return ToIvar;
4679}
4680
4682
4684 auto RedeclIt = Redecls.begin();
4685 // Import the first part of the decl chain. I.e. import all previous
4686 // declarations starting from the canonical decl.
4687 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4688 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4689 if (!RedeclOrErr)
4690 return RedeclOrErr.takeError();
4691 }
4692 assert(*RedeclIt == D);
4693
4694 // Import the major distinguishing characteristics of a variable.
4695 DeclContext *DC, *LexicalDC;
4696 DeclarationName Name;
4697 SourceLocation Loc;
4698 NamedDecl *ToD;
4699 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4700 return std::move(Err);
4701 if (ToD)
4702 return ToD;
4703
4704 // Try to find a variable in our own ("to") context with the same name and
4705 // in the same context as the variable we're importing.
4706 VarDecl *FoundByLookup = nullptr;
4707 if (D->isFileVarDecl()) {
4708 SmallVector<NamedDecl *, 4> ConflictingDecls;
4709 unsigned IDNS = Decl::IDNS_Ordinary;
4710 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4711 for (auto *FoundDecl : FoundDecls) {
4712 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4713 continue;
4714
4715 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4716 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4717 continue;
4718 if (Importer.IsStructurallyEquivalent(D->getType(),
4719 FoundVar->getType())) {
4720
4721 // The VarDecl in the "From" context has a definition, but in the
4722 // "To" context we already have a definition.
4723 VarDecl *FoundDef = FoundVar->getDefinition();
4724 if (D->isThisDeclarationADefinition() && FoundDef)
4725 // FIXME Check for ODR error if the two definitions have
4726 // different initializers?
4727 return Importer.MapImported(D, FoundDef);
4728
4729 // The VarDecl in the "From" context has an initializer, but in the
4730 // "To" context we already have an initializer.
4731 const VarDecl *FoundDInit = nullptr;
4732 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4733 // FIXME Diagnose ODR error if the two initializers are different?
4734 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4735
4736 FoundByLookup = FoundVar;
4737 break;
4738 }
4739
4740 const ArrayType *FoundArray
4741 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4742 const ArrayType *TArray
4743 = Importer.getToContext().getAsArrayType(D->getType());
4744 if (FoundArray && TArray) {
4745 if (isa<IncompleteArrayType>(FoundArray) &&
4746 isa<ConstantArrayType>(TArray)) {
4747 // Import the type.
4748 if (auto TyOrErr = import(D->getType()))
4749 FoundVar->setType(*TyOrErr);
4750 else
4751 return TyOrErr.takeError();
4752
4753 FoundByLookup = FoundVar;
4754 break;
4755 } else if (isa<IncompleteArrayType>(TArray) &&
4756 isa<ConstantArrayType>(FoundArray)) {
4757 FoundByLookup = FoundVar;
4758 break;
4759 }
4760 }
4761
4762 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4763 << Name << D->getType() << FoundVar->getType();
4764 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4765 << FoundVar->getType();
4766 ConflictingDecls.push_back(FoundDecl);
4767 }
4768 }
4769
4770 if (!ConflictingDecls.empty()) {
4771 ExpectedName NameOrErr = Importer.HandleNameConflict(
4772 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4773 if (NameOrErr)
4774 Name = NameOrErr.get();
4775 else
4776 return NameOrErr.takeError();
4777 }
4778 }
4779
4780 Error Err = Error::success();
4781 auto ToType = importChecked(Err, D->getType());
4782 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4783 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4784 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4785 if (Err)
4786 return std::move(Err);
4787
4788 VarDecl *ToVar;
4789 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4790 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4791 if (Error Err =
4792 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4793 return std::move(Err);
4794 DecompositionDecl *ToDecomp;
4795 if (GetImportedOrCreateDecl(
4796 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4797 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4798 return ToDecomp;
4799 ToVar = ToDecomp;
4800 } else {
4801 // Create the imported variable.
4802 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4803 ToInnerLocStart, Loc,
4804 Name.getAsIdentifierInfo(), ToType,
4805 ToTypeSourceInfo, D->getStorageClass()))
4806 return ToVar;
4807 }
4808
4809 ToVar->setTSCSpec(D->getTSCSpec());
4810 ToVar->setQualifierInfo(ToQualifierLoc);
4811 ToVar->setAccess(D->getAccess());
4812 ToVar->setLexicalDeclContext(LexicalDC);
4813 if (D->isInlineSpecified())
4814 ToVar->setInlineSpecified();
4815 if (D->isInline())
4816 ToVar->setImplicitlyInline();
4817
4818 if (FoundByLookup) {
4819 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4820 ToVar->setPreviousDecl(Recent);
4821 }
4822
4823 // Import the described template, if any.
4824 if (D->getDescribedVarTemplate()) {
4825 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4826 if (!ToVTOrErr)
4827 return ToVTOrErr.takeError();
4829 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4831 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4832 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4833 else
4834 return ToInstOrErr.takeError();
4835 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4837 else
4838 return POIOrErr.takeError();
4839 }
4840
4841 if (Error Err = ImportInitializer(D, ToVar))
4842 return std::move(Err);
4843
4844 if (D->isConstexpr())
4845 ToVar->setConstexpr(true);
4846
4847 addDeclToContexts(D, ToVar);
4848
4849 // Import the rest of the chain. I.e. import all subsequent declarations.
4850 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4851 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4852 if (!RedeclOrErr)
4853 return RedeclOrErr.takeError();
4854 }
4855
4856 return ToVar;
4857}
4858
4860 // Parameters are created in the translation unit's context, then moved
4861 // into the function declaration's context afterward.
4862 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4863
4864 Error Err = Error::success();
4865 auto ToDeclName = importChecked(Err, D->getDeclName());
4866 auto ToLocation = importChecked(Err, D->getLocation());
4867 auto ToType = importChecked(Err, D->getType());
4868 if (Err)
4869 return std::move(Err);
4870
4871 // Create the imported parameter.
4872 ImplicitParamDecl *ToParm = nullptr;
4873 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4874 ToLocation, ToDeclName.getAsIdentifierInfo(),
4875 ToType, D->getParameterKind()))
4876 return ToParm;
4877 return ToParm;
4878}
4879
4881 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4882
4883 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4884 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4885 else
4886 return LocOrErr.takeError();
4887
4889 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4890
4891 if (FromParam->hasUninstantiatedDefaultArg()) {
4892 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4893 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4894 else
4895 return ToDefArgOrErr.takeError();
4896 } else if (FromParam->hasUnparsedDefaultArg()) {
4897 ToParam->setUnparsedDefaultArg();
4898 } else if (FromParam->hasDefaultArg()) {
4899 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4900 ToParam->setDefaultArg(*ToDefArgOrErr);
4901 else
4902 return ToDefArgOrErr.takeError();
4903 }
4904
4905 return Error::success();
4906}
4907
4910 Error Err = Error::success();
4911 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4912 ConstructorUsingShadowDecl *ToShadow =
4913 importChecked(Err, From.getShadowDecl());
4914 if (Err)
4915 return std::move(Err);
4916 return InheritedConstructor(ToShadow, ToBaseCtor);
4917}
4918
4920 // Parameters are created in the translation unit's context, then moved
4921 // into the function declaration's context afterward.
4922 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4923
4924 Error Err = Error::success();
4925 auto ToDeclName = importChecked(Err, D->getDeclName());
4926 auto ToLocation = importChecked(Err, D->getLocation());
4927 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4928 auto ToType = importChecked(Err, D->getType());
4929 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4930 if (Err)
4931 return std::move(Err);
4932
4933 ParmVarDecl *ToParm;
4934 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4935 ToInnerLocStart, ToLocation,
4936 ToDeclName.getAsIdentifierInfo(), ToType,
4937 ToTypeSourceInfo, D->getStorageClass(),
4938 /*DefaultArg*/ nullptr))
4939 return ToParm;
4940
4941 // Set the default argument. It should be no problem if it was already done.
4942 // Do not import the default expression before GetImportedOrCreateDecl call
4943 // to avoid possible infinite import loop because circular dependency.
4944 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4945 return std::move(Err);
4946
4947 if (D->isObjCMethodParameter()) {
4950 } else {
4953 }
4954
4955 return ToParm;
4956}
4957
4959 // Import the major distinguishing characteristics of a method.
4960 DeclContext *DC, *LexicalDC;
4961 DeclarationName Name;
4962 SourceLocation Loc;
4963 NamedDecl *ToD;
4964 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4965 return std::move(Err);
4966 if (ToD)
4967 return ToD;
4968
4969 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4970 for (auto *FoundDecl : FoundDecls) {
4971 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4972 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4973 continue;
4974
4975 // Check return types.
4976 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4977 FoundMethod->getReturnType())) {
4978 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4979 << D->isInstanceMethod() << Name << D->getReturnType()
4980 << FoundMethod->getReturnType();
4981 Importer.ToDiag(FoundMethod->getLocation(),
4982 diag::note_odr_objc_method_here)
4983 << D->isInstanceMethod() << Name;
4984
4985 return make_error<ASTImportError>(ASTImportError::NameConflict);
4986 }
4987
4988 // Check the number of parameters.
4989 if (D->param_size() != FoundMethod->param_size()) {
4990 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4991 << D->isInstanceMethod() << Name
4992 << D->param_size() << FoundMethod->param_size();
4993 Importer.ToDiag(FoundMethod->getLocation(),
4994 diag::note_odr_objc_method_here)
4995 << D->isInstanceMethod() << Name;
4996
4997 return make_error<ASTImportError>(ASTImportError::NameConflict);
4998 }
4999
5000 // Check parameter types.
5002 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
5003 P != PEnd; ++P, ++FoundP) {
5004 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
5005 (*FoundP)->getType())) {
5006 Importer.FromDiag((*P)->getLocation(),
5007 diag::warn_odr_objc_method_param_type_inconsistent)
5008 << D->isInstanceMethod() << Name
5009 << (*P)->getType() << (*FoundP)->getType();
5010 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
5011 << (*FoundP)->getType();
5012
5013 return make_error<ASTImportError>(ASTImportError::NameConflict);
5014 }
5015 }
5016
5017 // Check variadic/non-variadic.
5018 // Check the number of parameters.
5019 if (D->isVariadic() != FoundMethod->isVariadic()) {
5020 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
5021 << D->isInstanceMethod() << Name;
5022 Importer.ToDiag(FoundMethod->getLocation(),
5023 diag::note_odr_objc_method_here)
5024 << D->isInstanceMethod() << Name;
5025
5026 return make_error<ASTImportError>(ASTImportError::NameConflict);
5027 }
5028
5029 // FIXME: Any other bits we need to merge?
5030 return Importer.MapImported(D, FoundMethod);
5031 }
5032 }
5033
5034 Error Err = Error::success();
5035 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5036 auto ToReturnType = importChecked(Err, D->getReturnType());
5037 auto ToReturnTypeSourceInfo =
5039 if (Err)
5040 return std::move(Err);
5041
5042 ObjCMethodDecl *ToMethod;
5043 if (GetImportedOrCreateDecl(
5044 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5045 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5049 return ToMethod;
5050
5051 // FIXME: When we decide to merge method definitions, we'll need to
5052 // deal with implicit parameters.
5053
5054 // Import the parameters
5056 for (auto *FromP : D->parameters()) {
5057 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5058 ToParams.push_back(*ToPOrErr);
5059 else
5060 return ToPOrErr.takeError();
5061 }
5062
5063 // Set the parameters.
5064 for (auto *ToParam : ToParams) {
5065 ToParam->setOwningFunction(ToMethod);
5066 ToMethod->addDeclInternal(ToParam);
5067 }
5068
5070 D->getSelectorLocs(FromSelLocs);
5071 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5072 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5073 return std::move(Err);
5074
5075 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5076
5077 ToMethod->setLexicalDeclContext(LexicalDC);
5078 LexicalDC->addDeclInternal(ToMethod);
5079
5080 // Implicit params are declared when Sema encounters the definition but this
5081 // never happens when the method is imported. Manually declare the implicit
5082 // params now that the MethodDecl knows its class interface.
5083 if (D->getSelfDecl())
5084 ToMethod->createImplicitParams(Importer.getToContext(),
5085 ToMethod->getClassInterface());
5086
5087 return ToMethod;
5088}
5089
5091 // Import the major distinguishing characteristics of a category.
5092 DeclContext *DC, *LexicalDC;
5093 DeclarationName Name;
5094 SourceLocation Loc;
5095 NamedDecl *ToD;
5096 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5097 return std::move(Err);
5098 if (ToD)
5099 return ToD;
5100
5101 Error Err = Error::success();
5102 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5103 auto ToLocation = importChecked(Err, D->getLocation());
5104 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5105 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5106 if (Err)
5107 return std::move(Err);
5108
5110 if (GetImportedOrCreateDecl(
5111 Result, D, Importer.getToContext(), DC, D->getVariance(),
5112 ToVarianceLoc, D->getIndex(),
5113 ToLocation, Name.getAsIdentifierInfo(),
5114 ToColonLoc, ToTypeSourceInfo))
5115 return Result;
5116
5117 // Only import 'ObjCTypeParamType' after the decl is created.
5118 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5119 if (Err)
5120 return std::move(Err);
5121 Result->setTypeForDecl(ToTypeForDecl);
5122 Result->setLexicalDeclContext(LexicalDC);
5123 return Result;
5124}
5125
5127 // Import the major distinguishing characteristics of a category.
5128 DeclContext *DC, *LexicalDC;
5129 DeclarationName Name;
5130 SourceLocation Loc;
5131 NamedDecl *ToD;
5132 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5133 return std::move(Err);
5134 if (ToD)
5135 return ToD;
5136
5137 ObjCInterfaceDecl *ToInterface;
5138 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5139 return std::move(Err);
5140
5141 // Determine if we've already encountered this category.
5142 ObjCCategoryDecl *MergeWithCategory
5143 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5144 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5145 if (!ToCategory) {
5146
5147 Error Err = Error::success();
5148 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5149 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5150 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5151 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5152 if (Err)
5153 return std::move(Err);
5154
5155 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5156 ToAtStartLoc, Loc,
5157 ToCategoryNameLoc,
5158 Name.getAsIdentifierInfo(), ToInterface,
5159 /*TypeParamList=*/nullptr,
5160 ToIvarLBraceLoc,
5161 ToIvarRBraceLoc))
5162 return ToCategory;
5163
5164 ToCategory->setLexicalDeclContext(LexicalDC);
5165 LexicalDC->addDeclInternal(ToCategory);
5166 // Import the type parameter list after MapImported, to avoid
5167 // loops when bringing in their DeclContext.
5168 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5169 ToCategory->setTypeParamList(*PListOrErr);
5170 else
5171 return PListOrErr.takeError();
5172
5173 // Import protocols
5175 SmallVector<SourceLocation, 4> ProtocolLocs;
5177 = D->protocol_loc_begin();
5179 FromProtoEnd = D->protocol_end();
5180 FromProto != FromProtoEnd;
5181 ++FromProto, ++FromProtoLoc) {
5182 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5183 Protocols.push_back(*ToProtoOrErr);
5184 else
5185 return ToProtoOrErr.takeError();
5186
5187 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5188 ProtocolLocs.push_back(*ToProtoLocOrErr);
5189 else
5190 return ToProtoLocOrErr.takeError();
5191 }
5192
5193 // FIXME: If we're merging, make sure that the protocol list is the same.
5194 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5195 ProtocolLocs.data(), Importer.getToContext());
5196
5197 } else {
5198 Importer.MapImported(D, ToCategory);
5199 }
5200
5201 // Import all of the members of this category.
5202 if (Error Err = ImportDeclContext(D))
5203 return std::move(Err);
5204
5205 // If we have an implementation, import it as well.
5206 if (D->getImplementation()) {
5207 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5208 import(D->getImplementation()))
5209 ToCategory->setImplementation(*ToImplOrErr);
5210 else
5211 return ToImplOrErr.takeError();
5212 }
5213
5214 return ToCategory;
5215}
5216
5219 if (To->getDefinition()) {
5221 if (Error Err = ImportDeclContext(From))
5222 return Err;
5223 return Error::success();
5224 }
5225
5226 // Start the protocol definition
5227 To->startDefinition();
5228
5229 // Import protocols
5231 SmallVector<SourceLocation, 4> ProtocolLocs;
5233 From->protocol_loc_begin();
5234 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5235 FromProtoEnd = From->protocol_end();
5236 FromProto != FromProtoEnd;
5237 ++FromProto, ++FromProtoLoc) {
5238 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5239 Protocols.push_back(*ToProtoOrErr);
5240 else
5241 return ToProtoOrErr.takeError();
5242
5243 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5244 ProtocolLocs.push_back(*ToProtoLocOrErr);
5245 else
5246 return ToProtoLocOrErr.takeError();
5247
5248 }
5249
5250 // FIXME: If we're merging, make sure that the protocol list is the same.
5251 To->setProtocolList(Protocols.data(), Protocols.size(),
5252 ProtocolLocs.data(), Importer.getToContext());
5253
5254 if (shouldForceImportDeclContext(Kind)) {
5255 // Import all of the members of this protocol.
5256 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5257 return Err;
5258 }
5259 return Error::success();
5260}
5261
5263 // If this protocol has a definition in the translation unit we're coming
5264 // from, but this particular declaration is not that definition, import the
5265 // definition and map to that.
5267 if (Definition && Definition != D) {
5268 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5269 return Importer.MapImported(D, *ImportedDefOrErr);
5270 else
5271 return ImportedDefOrErr.takeError();
5272 }
5273
5274 // Import the major distinguishing characteristics of a protocol.
5275 DeclContext *DC, *LexicalDC;
5276 DeclarationName Name;
5277 SourceLocation Loc;
5278 NamedDecl *ToD;
5279 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5280 return std::move(Err);
5281 if (ToD)
5282 return ToD;
5283
5284 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5285 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5286 for (auto *FoundDecl : FoundDecls) {
5287 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5288 continue;
5289
5290 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5291 break;
5292 }
5293
5294 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5295 if (!ToProto) {
5296 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5297 if (!ToAtBeginLocOrErr)
5298 return ToAtBeginLocOrErr.takeError();
5299
5300 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5301 Name.getAsIdentifierInfo(), Loc,
5302 *ToAtBeginLocOrErr,
5303 /*PrevDecl=*/nullptr))
5304 return ToProto;
5305 ToProto->setLexicalDeclContext(LexicalDC);
5306 LexicalDC->addDeclInternal(ToProto);
5307 }
5308
5309 Importer.MapImported(D, ToProto);
5310
5312 if (Error Err = ImportDefinition(D, ToProto))
5313 return std::move(Err);
5314
5315 return ToProto;
5316}
5317
5319 DeclContext *DC, *LexicalDC;
5320 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5321 return std::move(Err);
5322
5323 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5324 if (!ExternLocOrErr)
5325 return ExternLocOrErr.takeError();
5326
5327 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5328 if (!LangLocOrErr)
5329 return LangLocOrErr.takeError();
5330
5331 bool HasBraces = D->hasBraces();
5332
5333 LinkageSpecDecl *ToLinkageSpec;
5334 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5335 *ExternLocOrErr, *LangLocOrErr,
5336 D->getLanguage(), HasBraces))
5337 return ToLinkageSpec;
5338
5339 if (HasBraces) {
5340 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5341 if (!RBraceLocOrErr)
5342 return RBraceLocOrErr.takeError();
5343 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5344 }
5345
5346 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5347 LexicalDC->addDeclInternal(ToLinkageSpec);
5348
5349 return ToLinkageSpec;
5350}
5351
5353 BaseUsingDecl *ToSI) {
5354 for (UsingShadowDecl *FromShadow : D->shadows()) {
5355 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5356 ToSI->addShadowDecl(*ToShadowOrErr);
5357 else
5358 // FIXME: We return error here but the definition is already created
5359 // and available with lookups. How to fix this?..
5360 return ToShadowOrErr.takeError();
5361 }
5362 return ToSI;
5363}
5364
5366 DeclContext *DC, *LexicalDC;
5367 DeclarationName Name;
5368 SourceLocation Loc;
5369 NamedDecl *ToD = nullptr;
5370 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5371 return std::move(Err);
5372 if (ToD)
5373 return ToD;
5374
5375 Error Err = Error::success();
5376 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5377 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5378 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5379 if (Err)
5380 return std::move(Err);
5381
5382 DeclarationNameInfo NameInfo(Name, ToLoc);
5383 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5384 return std::move(Err);
5385
5386 UsingDecl *ToUsing;
5387 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5388 ToUsingLoc, ToQualifierLoc, NameInfo,
5389 D->hasTypename()))
5390 return ToUsing;
5391
5392 ToUsing->setLexicalDeclContext(LexicalDC);
5393 LexicalDC->addDeclInternal(ToUsing);
5394
5395 if (NamedDecl *FromPattern =
5396 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5397 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5398 Importer.getToContext().setInstantiatedFromUsingDecl(
5399 ToUsing, *ToPatternOrErr);
5400 else
5401 return ToPatternOrErr.takeError();
5402 }
5403
5404 return ImportUsingShadowDecls(D, ToUsing);
5405}
5406
5408 DeclContext *DC, *LexicalDC;
5409 DeclarationName Name;
5410 SourceLocation Loc;
5411 NamedDecl *ToD = nullptr;
5412 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5413 return std::move(Err);
5414 if (ToD)
5415 return ToD;
5416
5417 Error Err = Error::success();
5418 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5419 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5420 auto ToNameLoc = importChecked(Err, D->getLocation());
5421 auto *ToEnumType = importChecked(Err, D->getEnumType());
5422 if (Err)
5423 return std::move(Err);
5424
5425 UsingEnumDecl *ToUsingEnum;
5426 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5427 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5428 return ToUsingEnum;
5429
5430 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5431 LexicalDC->addDeclInternal(ToUsingEnum);
5432
5433 if (UsingEnumDecl *FromPattern =
5434 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5435 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5436 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5437 *ToPatternOrErr);
5438 else
5439 return ToPatternOrErr.takeError();
5440 }
5441
5442 return ImportUsingShadowDecls(D, ToUsingEnum);
5443}
5444
5446 DeclContext *DC, *LexicalDC;
5447 DeclarationName Name;
5448 SourceLocation Loc;
5449 NamedDecl *ToD = nullptr;
5450 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5451 return std::move(Err);
5452 if (ToD)
5453 return ToD;
5454
5455 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5456 if (!ToIntroducerOrErr)
5457 return ToIntroducerOrErr.takeError();
5458
5459 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5460 if (!ToTargetOrErr)
5461 return ToTargetOrErr.takeError();
5462
5463 UsingShadowDecl *ToShadow;
5464 if (auto *FromConstructorUsingShadow =
5465 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5466 Error Err = Error::success();
5468 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5469 if (Err)
5470 return std::move(Err);
5471 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5472 // is really the "NominatedBaseClassShadowDecl" value if it exists
5473 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5474 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5475 // get the correct values.
5476 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5477 ToShadow, D, Importer.getToContext(), DC, Loc,
5478 cast<UsingDecl>(*ToIntroducerOrErr),
5479 Nominated ? Nominated : *ToTargetOrErr,
5480 FromConstructorUsingShadow->constructsVirtualBase()))
5481 return ToShadow;
5482 } else {
5483 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5484 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5485 return ToShadow;
5486 }
5487
5488 ToShadow->setLexicalDeclContext(LexicalDC);
5489 ToShadow->setAccess(D->getAccess());
5490
5491 if (UsingShadowDecl *FromPattern =
5492 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5493 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5494 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5495 ToShadow, *ToPatternOrErr);
5496 else
5497 // FIXME: We return error here but the definition is already created
5498 // and available with lookups. How to fix this?..
5499 return ToPatternOrErr.takeError();
5500 }
5501
5502 LexicalDC->addDeclInternal(ToShadow);
5503
5504 return ToShadow;
5505}
5506
5508 DeclContext *DC, *LexicalDC;
5509 DeclarationName Name;
5510 SourceLocation Loc;
5511 NamedDecl *ToD = nullptr;
5512 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5513 return std::move(Err);
5514 if (ToD)
5515 return ToD;
5516
5517 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5518 if (!ToComAncestorOrErr)
5519 return ToComAncestorOrErr.takeError();
5520
5521 Error Err = Error::success();
5522 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5523 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5524 auto ToNamespaceKeyLocation =
5526 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5527 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5528 if (Err)
5529 return std::move(Err);
5530
5531 UsingDirectiveDecl *ToUsingDir;
5532 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5533 ToUsingLoc,
5534 ToNamespaceKeyLocation,
5535 ToQualifierLoc,
5536 ToIdentLocation,
5537 ToNominatedNamespace, *ToComAncestorOrErr))
5538 return ToUsingDir;
5539
5540 ToUsingDir->setLexicalDeclContext(LexicalDC);
5541 LexicalDC->addDeclInternal(ToUsingDir);
5542
5543 return ToUsingDir;
5544}
5545
5547 DeclContext *DC, *LexicalDC;
5548 DeclarationName Name;
5549 SourceLocation Loc;
5550 NamedDecl *ToD = nullptr;
5551 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5552 return std::move(Err);
5553 if (ToD)
5554 return ToD;
5555
5556 auto ToInstantiatedFromUsingOrErr =
5557 Importer.Import(D->getInstantiatedFromUsingDecl());
5558 if (!ToInstantiatedFromUsingOrErr)
5559 return ToInstantiatedFromUsingOrErr.takeError();
5560 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5561 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5562 return std::move(Err);
5563
5564 UsingPackDecl *ToUsingPack;
5565 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5566 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5567 Expansions))
5568 return ToUsingPack;
5569
5570 addDeclToContexts(D, ToUsingPack);
5571
5572 return ToUsingPack;
5573}
5574
5577 DeclContext *DC, *LexicalDC;
5578 DeclarationName Name;
5579 SourceLocation Loc;
5580 NamedDecl *ToD = nullptr;
5581 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5582 return std::move(Err);
5583 if (ToD)
5584 return ToD;
5585
5586 Error Err = Error::success();
5587 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5588 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5589 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5590 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5591 if (Err)
5592 return std::move(Err);
5593
5594 DeclarationNameInfo NameInfo(Name, ToLoc);
5595 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5596 return std::move(Err);
5597
5598 UnresolvedUsingValueDecl *ToUsingValue;
5599 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5600 ToUsingLoc, ToQualifierLoc, NameInfo,
5601 ToEllipsisLoc))
5602 return ToUsingValue;
5603
5604 ToUsingValue->setAccess(D->getAccess());
5605 ToUsingValue->setLexicalDeclContext(LexicalDC);
5606 LexicalDC->addDeclInternal(ToUsingValue);
5607
5608 return ToUsingValue;
5609}
5610
5613 DeclContext *DC, *LexicalDC;
5614 DeclarationName Name;
5615 SourceLocation Loc;
5616 NamedDecl *ToD = nullptr;
5617 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5618 return std::move(Err);
5619 if (ToD)
5620 return ToD;
5621
5622 Error Err = Error::success();
5623 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5624 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5625 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5626 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5627 if (Err)
5628 return std::move(Err);
5629
5631 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5632 ToUsingLoc, ToTypenameLoc,
5633 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5634 return ToUsing;
5635
5636 ToUsing->setAccess(D->getAccess());
5637 ToUsing->setLexicalDeclContext(LexicalDC);
5638 LexicalDC->addDeclInternal(ToUsing);
5639
5640 return ToUsing;
5641}
5642
5644 Decl* ToD = nullptr;
5645 switch (D->getBuiltinTemplateKind()) {
5646#define BuiltinTemplate(BTName) \
5647 case BuiltinTemplateKind::BTK##BTName: \
5648 ToD = Importer.getToContext().get##BTName##Decl(); \
5649 break;
5650#include "clang/Basic/BuiltinTemplates.inc"
5651 }
5652 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5653 Importer.MapImported(D, ToD);
5654 return ToD;
5655}
5656
5659 if (To->getDefinition()) {
5660 // Check consistency of superclass.
5661 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5662 if (FromSuper) {
5663 if (auto FromSuperOrErr = import(FromSuper))
5664 FromSuper = *FromSuperOrErr;
5665 else
5666 return FromSuperOrErr.takeError();
5667 }
5668
5669 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5670 if ((bool)FromSuper != (bool)ToSuper ||
5671 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5672 Importer.ToDiag(To->getLocation(),
5673 diag::warn_odr_objc_superclass_inconsistent)
5674 << To->getDeclName();
5675 if (ToSuper)
5676 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5677 << To->getSuperClass()->getDeclName();
5678 else
5679 Importer.ToDiag(To->getLocation(),
5680 diag::note_odr_objc_missing_superclass);
5681 if (From->getSuperClass())
5682 Importer.FromDiag(From->getSuperClassLoc(),
5683 diag::note_odr_objc_superclass)
5684 << From->getSuperClass()->getDeclName();
5685 else
5686 Importer.FromDiag(From->getLocation(),
5687 diag::note_odr_objc_missing_superclass);
5688 }
5689
5691 if (Error Err = ImportDeclContext(From))
5692 return Err;
5693 return Error::success();
5694 }
5695
5696 // Start the definition.
5697 To->startDefinition();
5698
5699 // If this class has a superclass, import it.
5700 if (From->getSuperClass()) {
5701 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5702 To->setSuperClass(*SuperTInfoOrErr);
5703 else
5704 return SuperTInfoOrErr.takeError();
5705 }
5706
5707 // Import protocols
5709 SmallVector<SourceLocation, 4> ProtocolLocs;
5711 From->protocol_loc_begin();
5712
5714 FromProtoEnd = From->protocol_end();
5715 FromProto != FromProtoEnd;
5716 ++FromProto, ++FromProtoLoc) {
5717 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5718 Protocols.push_back(*ToProtoOrErr);
5719 else
5720 return ToProtoOrErr.takeError();
5721
5722 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5723 ProtocolLocs.push_back(*ToProtoLocOrErr);
5724 else
5725 return ToProtoLocOrErr.takeError();
5726
5727 }
5728
5729 // FIXME: If we're merging, make sure that the protocol list is the same.
5730 To->setProtocolList(Protocols.data(), Protocols.size(),
5731 ProtocolLocs.data(), Importer.getToContext());
5732
5733 // Import categories. When the categories themselves are imported, they'll
5734 // hook themselves into this interface.
5735 for (auto *Cat : From->known_categories()) {
5736 auto ToCatOrErr = import(Cat);
5737 if (!ToCatOrErr)
5738 return ToCatOrErr.takeError();
5739 }
5740
5741 // If we have an @implementation, import it as well.
5742 if (From->getImplementation()) {
5743 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5744 import(From->getImplementation()))
5745 To->setImplementation(*ToImplOrErr);
5746 else
5747 return ToImplOrErr.takeError();
5748 }
5749
5750 // Import all of the members of this class.
5751 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5752 return Err;
5753
5754 return Error::success();
5755}
5756
5759 if (!list)
5760 return nullptr;
5761
5763 for (auto *fromTypeParam : *list) {
5764 if (auto toTypeParamOrErr = import(fromTypeParam))
5765 toTypeParams.push_back(*toTypeParamOrErr);
5766 else
5767 return toTypeParamOrErr.takeError();
5768 }
5769
5770 auto LAngleLocOrErr = import(list->getLAngleLoc());
5771 if (!LAngleLocOrErr)
5772 return LAngleLocOrErr.takeError();
5773
5774 auto RAngleLocOrErr = import(list->getRAngleLoc());
5775 if (!RAngleLocOrErr)
5776 return RAngleLocOrErr.takeError();
5777
5778 return ObjCTypeParamList::create(Importer.getToContext(),
5779 *LAngleLocOrErr,
5780 toTypeParams,
5781 *RAngleLocOrErr);
5782}
5783
5785 // If this class has a definition in the translation unit we're coming from,
5786 // but this particular declaration is not that definition, import the
5787 // definition and map to that.
5789 if (Definition && Definition != D) {
5790 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5791 return Importer.MapImported(D, *ImportedDefOrErr);
5792 else
5793 return ImportedDefOrErr.takeError();
5794 }
5795
5796 // Import the major distinguishing characteristics of an @interface.
5797 DeclContext *DC, *LexicalDC;
5798 DeclarationName Name;
5799 SourceLocation Loc;
5800 NamedDecl *ToD;
5801 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5802 return std::move(Err);
5803 if (ToD)
5804 return ToD;
5805
5806 // Look for an existing interface with the same name.
5807 ObjCInterfaceDecl *MergeWithIface = nullptr;
5808 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5809 for (auto *FoundDecl : FoundDecls) {
5810 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5811 continue;
5812
5813 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5814 break;
5815 }
5816
5817 // Create an interface declaration, if one does not already exist.
5818 ObjCInterfaceDecl *ToIface = MergeWithIface;
5819 if (!ToIface) {
5820 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5821 if (!AtBeginLocOrErr)
5822 return AtBeginLocOrErr.takeError();
5823
5824 if (GetImportedOrCreateDecl(
5825 ToIface, D, Importer.getToContext(), DC,
5826 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5827 /*TypeParamList=*/nullptr,
5828 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5829 return ToIface;
5830 ToIface->setLexicalDeclContext(LexicalDC);
5831 LexicalDC->addDeclInternal(ToIface);
5832 }
5833 Importer.MapImported(D, ToIface);
5834 // Import the type parameter list after MapImported, to avoid
5835 // loops when bringing in their DeclContext.
5836 if (auto ToPListOrErr =
5838 ToIface->setTypeParamList(*ToPListOrErr);
5839 else
5840 return ToPListOrErr.takeError();
5841
5843 if (Error Err = ImportDefinition(D, ToIface))
5844 return std::move(Err);
5845
5846 return ToIface;
5847}
5848
5851 ObjCCategoryDecl *Category;
5852 if (Error Err = importInto(Category, D->getCategoryDecl()))
5853 return std::move(Err);
5854
5855 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5856 if (!ToImpl) {
5857 DeclContext *DC, *LexicalDC;
5858 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5859 return std::move(Err);
5860
5861 Error Err = Error::success();
5862 auto ToLocation = importChecked(Err, D->getLocation());
5863 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5864 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5865 if (Err)
5866 return std::move(Err);
5867
5868 if (GetImportedOrCreateDecl(
5869 ToImpl, D, Importer.getToContext(), DC,
5870 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5871 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5872 return ToImpl;
5873
5874 ToImpl->setLexicalDeclContext(LexicalDC);
5875 LexicalDC->addDeclInternal(ToImpl);
5876 Category->setImplementation(ToImpl);
5877 }
5878
5879 Importer.MapImported(D, ToImpl);
5880 if (Error Err = ImportDeclContext(D))
5881 return std::move(Err);
5882
5883 return ToImpl;
5884}
5885
5888 // Find the corresponding interface.
5889 ObjCInterfaceDecl *Iface;
5890 if (Error Err = importInto(Iface, D->getClassInterface()))
5891 return std::move(Err);
5892
5893 // Import the superclass, if any.
5894 ObjCInterfaceDecl *Super;
5895 if (Error Err = importInto(Super, D->getSuperClass()))
5896 return std::move(Err);
5897
5899 if (!Impl) {
5900 // We haven't imported an implementation yet. Create a new @implementation
5901 // now.
5902 DeclContext *DC, *LexicalDC;
5903 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5904 return std::move(Err);
5905
5906 Error Err = Error::success();
5907 auto ToLocation = importChecked(Err, D->getLocation());
5908 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5909 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5910 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5911 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5912 if (Err)
5913 return std::move(Err);
5914
5915 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5916 DC, Iface, Super,
5917 ToLocation,
5918 ToAtStartLoc,
5919 ToSuperClassLoc,
5920 ToIvarLBraceLoc,
5921 ToIvarRBraceLoc))
5922 return Impl;
5923
5924 Impl->setLexicalDeclContext(LexicalDC);
5925
5926 // Associate the implementation with the class it implements.
5927 Iface->setImplementation(Impl);
5928 Importer.MapImported(D, Iface->getImplementation());
5929 } else {
5930 Importer.MapImported(D, Iface->getImplementation());
5931
5932 // Verify that the existing @implementation has the same superclass.
5933 if ((Super && !Impl->getSuperClass()) ||
5934 (!Super && Impl->getSuperClass()) ||
5935 (Super && Impl->getSuperClass() &&
5937 Impl->getSuperClass()))) {
5938 Importer.ToDiag(Impl->getLocation(),
5939 diag::warn_odr_objc_superclass_inconsistent)
5940 << Iface->getDeclName();
5941 // FIXME: It would be nice to have the location of the superclass
5942 // below.
5943 if (Impl->getSuperClass())
5944 Importer.ToDiag(Impl->getLocation(),
5945 diag::note_odr_objc_superclass)
5946 << Impl->getSuperClass()->getDeclName();
5947 else
5948 Importer.ToDiag(Impl->getLocation(),
5949 diag::note_odr_objc_missing_superclass);
5950 if (D->getSuperClass())
5951 Importer.FromDiag(D->getLocation(),
5952 diag::note_odr_objc_superclass)
5953 << D->getSuperClass()->getDeclName();
5954 else
5955 Importer.FromDiag(D->getLocation(),
5956 diag::note_odr_objc_missing_superclass);
5957
5958 return make_error<ASTImportError>(ASTImportError::NameConflict);
5959 }
5960 }
5961
5962 // Import all of the members of this @implementation.
5963 if (Error Err = ImportDeclContext(D))
5964 return std::move(Err);
5965
5966 return Impl;
5967}
5968
5970 // Import the major distinguishing characteristics of an @property.
5971 DeclContext *DC, *LexicalDC;
5972 DeclarationName Name;
5973 SourceLocation Loc;
5974 NamedDecl *ToD;
5975 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5976 return std::move(Err);
5977 if (ToD)
5978 return ToD;
5979
5980 // Check whether we have already imported this property.
5981 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5982 for (auto *FoundDecl : FoundDecls) {
5983 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5984 // Instance and class properties can share the same name but are different
5985 // declarations.
5986 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5987 continue;
5988
5989 // Check property types.
5990 if (!Importer.IsStructurallyEquivalent(D->getType(),
5991 FoundProp->getType())) {
5992 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5993 << Name << D->getType() << FoundProp->getType();
5994 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5995 << FoundProp->getType();
5996
5997 return make_error<ASTImportError>(ASTImportError::NameConflict);
5998 }
5999
6000 // FIXME: Check property attributes, getters, setters, etc.?
6001
6002 // Consider these properties to be equivalent.
6003 Importer.MapImported(D, FoundProp);
6004 return FoundProp;
6005 }
6006 }
6007
6008 Error Err = Error::success();
6009 auto ToType = importChecked(Err, D->getType());
6010 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6011 auto ToAtLoc = importChecked(Err, D->getAtLoc());
6012 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
6013 if (Err)
6014 return std::move(Err);
6015
6016 // Create the new property.
6017 ObjCPropertyDecl *ToProperty;
6018 if (GetImportedOrCreateDecl(
6019 ToProperty, D, Importer.getToContext(), DC, Loc,
6020 Name.getAsIdentifierInfo(), ToAtLoc,
6021 ToLParenLoc, ToType,
6022 ToTypeSourceInfo, D->getPropertyImplementation()))
6023 return ToProperty;
6024
6025 auto ToGetterName = importChecked(Err, D->getGetterName());
6026 auto ToSetterName = importChecked(Err, D->getSetterName());
6027 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6028 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6029 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6030 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6031 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6032 if (Err)
6033 return std::move(Err);
6034
6035 ToProperty->setLexicalDeclContext(LexicalDC);
6036 LexicalDC->addDeclInternal(ToProperty);
6037
6041 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6042 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6043 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6044 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6045 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6046 return ToProperty;
6047}
6048
6052 if (Error Err = importInto(Property, D->getPropertyDecl()))
6053 return std::move(Err);
6054
6055 DeclContext *DC, *LexicalDC;
6056 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6057 return std::move(Err);
6058
6059 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6060
6061 // Import the ivar (for an @synthesize).
6062 ObjCIvarDecl *Ivar = nullptr;
6063 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6064 return std::move(Err);
6065
6066 ObjCPropertyImplDecl *ToImpl
6067 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6068 Property->getQueryKind());
6069 if (!ToImpl) {
6070
6071 Error Err = Error::success();
6072 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6073 auto ToLocation = importChecked(Err, D->getLocation());
6074 auto ToPropertyIvarDeclLoc =
6076 if (Err)
6077 return std::move(Err);
6078
6079 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6080 ToBeginLoc,
6081 ToLocation, Property,
6082 D->getPropertyImplementation(), Ivar,
6083 ToPropertyIvarDeclLoc))
6084 return ToImpl;
6085
6086 ToImpl->setLexicalDeclContext(LexicalDC);
6087 LexicalDC->addDeclInternal(ToImpl);
6088 } else {
6089 // Check that we have the same kind of property implementation (@synthesize
6090 // vs. @dynamic).
6092 Importer.ToDiag(ToImpl->getLocation(),
6093 diag::warn_odr_objc_property_impl_kind_inconsistent)
6094 << Property->getDeclName()
6095 << (ToImpl->getPropertyImplementation()
6097 Importer.FromDiag(D->getLocation(),
6098 diag::note_odr_objc_property_impl_kind)
6099 << D->getPropertyDecl()->getDeclName()
6101
6102 return make_error<ASTImportError>(ASTImportError::NameConflict);
6103 }
6104
6105 // For @synthesize, check that we have the same
6107 Ivar != ToImpl->getPropertyIvarDecl()) {
6108 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6109 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6110 << Property->getDeclName()
6111 << ToImpl->getPropertyIvarDecl()->getDeclName()
6112 << Ivar->getDeclName();
6113 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6114 diag::note_odr_objc_synthesize_ivar_here)
6116
6117 return make_error<ASTImportError>(ASTImportError::NameConflict);
6118 }
6119
6120 // Merge the existing implementation with the new implementation.
6121 Importer.MapImported(D, ToImpl);
6122 }
6123
6124 return ToImpl;
6125}
6126
6129 // For template arguments, we adopt the translation unit as our declaration
6130 // context. This context will be fixed when (during) the actual template
6131 // declaration is created.
6132
6133 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6134 if (!BeginLocOrErr)
6135 return BeginLocOrErr.takeError();
6136
6137 ExpectedSLoc LocationOrErr = import(D->getLocation());
6138 if (!LocationOrErr)
6139 return LocationOrErr.takeError();
6140
6141 TemplateTypeParmDecl *ToD = nullptr;
6142 if (GetImportedOrCreateDecl(
6143 ToD, D, Importer.getToContext(),
6144 Importer.getToContext().getTranslationUnitDecl(),
6145 *BeginLocOrErr, *LocationOrErr,
6146 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6148 D->hasTypeConstraint()))
6149 return ToD;
6150
6151 // Import the type-constraint
6152 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6153
6154 Error Err = Error::success();
6155 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6156 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6157 if (Err)
6158 return std::move(Err);
6159
6160 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6161 }
6162
6163 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6164 return Err;
6165
6166 return ToD;
6167}
6168
6171
6172 Error Err = Error::success();
6173 auto ToDeclName = importChecked(Err, D->getDeclName());
6174 auto ToLocation = importChecked(Err, D->getLocation());
6175 auto ToType = importChecked(Err, D->getType());
6176 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6177 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6178 if (Err)
6179 return std::move(Err);
6180
6181 NonTypeTemplateParmDecl *ToD = nullptr;
6182 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6183 Importer.getToContext().getTranslationUnitDecl(),
6184 ToInnerLocStart, ToLocation, D->getDepth(),
6185 D->getPosition(),
6186 ToDeclName.getAsIdentifierInfo(), ToType,
6187 D->isParameterPack(), ToTypeSourceInfo))
6188 return ToD;
6189
6190 Err = importTemplateParameterDefaultArgument(D, ToD);
6191 if (Err)
6192 return Err;
6193
6194 return ToD;
6195}
6196
6199 bool IsCanonical = false;
6200 if (auto *CanonD = Importer.getFromContext()
6201 .findCanonicalTemplateTemplateParmDeclInternal(D);
6202 CanonD == D)
6203 IsCanonical = true;
6204
6205 // Import the name of this declaration.
6206 auto NameOrErr = import(D->getDeclName());
6207 if (!NameOrErr)
6208 return NameOrErr.takeError();
6209
6210 // Import the location of this declaration.
6211 ExpectedSLoc LocationOrErr = import(D->getLocation());
6212 if (!LocationOrErr)
6213 return LocationOrErr.takeError();
6214
6215 // Import template parameters.
6216 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6217 if (!TemplateParamsOrErr)
6218 return TemplateParamsOrErr.takeError();
6219
6220 TemplateTemplateParmDecl *ToD = nullptr;
6221 if (GetImportedOrCreateDecl(
6222 ToD, D, Importer.getToContext(),
6223 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6224 D->getDepth(), D->getPosition(), D->isParameterPack(),
6225 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6226 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6227 return ToD;
6228
6229 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6230 return Err;
6231
6232 if (IsCanonical)
6233 return Importer.getToContext()
6234 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6235
6236 return ToD;
6237}
6238
6239// Returns the definition for a (forward) declaration of a TemplateDecl, if
6240// it has any definition in the redecl chain.
6241template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6242 assert(D->getTemplatedDecl() && "Should be called on templates only");
6243 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6244 if (!ToTemplatedDef)
6245 return nullptr;
6246 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6247 return cast_or_null<T>(TemplateWithDef);
6248}
6249
6251
6252 // Import the major distinguishing characteristics of this class template.
6253 DeclContext *DC, *LexicalDC;
6254 DeclarationName Name;
6255 SourceLocation Loc;
6256 NamedDecl *ToD;
6257 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6258 return std::move(Err);
6259 if (ToD)
6260 return ToD;
6261
6262 // Should check if a declaration is friend in a dependent context.
6263 // Such templates are not linked together in a declaration chain.
6264 // The ASTImporter strategy is to map existing forward declarations to
6265 // imported ones only if strictly necessary, otherwise import these as new
6266 // forward declarations. In case of the "dependent friend" declarations, new
6267 // declarations are created, but not linked in a declaration chain.
6268 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6269 return TD->getFriendObjectKind() != Decl::FOK_None &&
6270 TD->getLexicalDeclContext()->isDependentContext();
6271 };
6272 bool DependentFriend = IsDependentFriend(D);
6273
6274 ClassTemplateDecl *FoundByLookup = nullptr;
6275
6276 // We may already have a template of the same name; try to find and match it.
6277 if (!DC->isFunctionOrMethod()) {
6278 SmallVector<NamedDecl *, 4> ConflictingDecls;
6279 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6280 for (auto *FoundDecl : FoundDecls) {
6281 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6283 continue;
6284
6285 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6286 if (FoundTemplate) {
6287 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6288 continue;
6289
6290 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6291 bool IgnoreTemplateParmDepth =
6292 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6294 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6295 IgnoreTemplateParmDepth)) {
6296 if (DependentFriend || IsDependentFriend(FoundTemplate))
6297 continue;
6298
6299 ClassTemplateDecl *TemplateWithDef =
6300 getTemplateDefinition(FoundTemplate);
6301 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6302 return Importer.MapImported(D, TemplateWithDef);
6303 if (!FoundByLookup)
6304 FoundByLookup = FoundTemplate;
6305 // Search in all matches because there may be multiple decl chains,
6306 // see ASTTests test ImportExistingFriendClassTemplateDef.
6307 continue;
6308 }
6309 // When importing a friend, it is possible that multiple declarations
6310 // with same name can co-exist in specific cases (if a template contains
6311 // a friend template and has a specialization). For this case the
6312 // declarations should match, except that the "template depth" is
6313 // different. No linking of previous declaration is needed in this case.
6314 // FIXME: This condition may need refinement.
6315 if (D->getFriendObjectKind() != Decl::FOK_None &&
6316 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6317 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6318 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6319 /*IgnoreTemplateParmDepth=*/true))
6320 continue;
6321
6322 ConflictingDecls.push_back(FoundDecl);
6323 }
6324 }
6325
6326 if (!ConflictingDecls.empty()) {
6327 ExpectedName NameOrErr = Importer.HandleNameConflict(
6328 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6329 ConflictingDecls.size());
6330 if (NameOrErr)
6331 Name = NameOrErr.get();
6332 else
6333 return NameOrErr.takeError();
6334 }
6335 }
6336
6337 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6338
6339 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6340 if (!TemplateParamsOrErr)
6341 return TemplateParamsOrErr.takeError();
6342
6343 // Create the declaration that is being templated.
6344 CXXRecordDecl *ToTemplated;
6345 if (Error Err = importInto(ToTemplated, FromTemplated))
6346 return std::move(Err);
6347
6348 // Create the class template declaration itself.
6350 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6351 *TemplateParamsOrErr, ToTemplated))
6352 return D2;
6353
6354 ToTemplated->setDescribedClassTemplate(D2);
6355
6356 D2->setAccess(D->getAccess());
6357 D2->setLexicalDeclContext(LexicalDC);
6358
6359 addDeclToContexts(D, D2);
6360 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6361
6362 if (FoundByLookup) {
6363 auto *Recent =
6364 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6365
6366 // It is possible that during the import of the class template definition
6367 // we start the import of a fwd friend decl of the very same class template
6368 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6369 // had been created earlier and by that time the lookup could not find
6370 // anything existing, so it has no previous decl. Later, (still during the
6371 // import of the fwd friend decl) we start to import the definition again
6372 // and this time the lookup finds the previous fwd friend class template.
6373 // In this case we must set up the previous decl for the templated decl.
6374 if (!ToTemplated->getPreviousDecl()) {
6375 assert(FoundByLookup->getTemplatedDecl() &&
6376 "Found decl must have its templated decl set");
6377 CXXRecordDecl *PrevTemplated =
6378 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6379 if (ToTemplated != PrevTemplated)
6380 ToTemplated->setPreviousDecl(PrevTemplated);
6381 }
6382
6383 D2->setPreviousDecl(Recent);
6384 }
6385
6386 return D2;
6387}
6388
6391 ClassTemplateDecl *ClassTemplate;
6392 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6393 return std::move(Err);
6394
6395 // Import the context of this declaration.
6396 DeclContext *DC, *LexicalDC;
6397 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6398 return std::move(Err);
6399
6400 // Import template arguments.
6402 if (Error Err =
6403 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6404 return std::move(Err);
6405 // Try to find an existing specialization with these template arguments and
6406 // template parameter list.
6407 void *InsertPos = nullptr;
6408 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6410 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6411
6412 // Import template parameters.
6413 TemplateParameterList *ToTPList = nullptr;
6414
6415 if (PartialSpec) {
6416 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6417 if (!ToTPListOrErr)
6418 return ToTPListOrErr.takeError();
6419 ToTPList = *ToTPListOrErr;
6420 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6421 *ToTPListOrErr,
6422 InsertPos);
6423 } else
6424 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6425
6426 if (PrevDecl) {
6427 if (IsStructuralMatch(D, PrevDecl)) {
6428 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6429 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6430 Importer.MapImported(D, PrevDefinition);
6431 // Import those default field initializers which have been
6432 // instantiated in the "From" context, but not in the "To" context.
6433 for (auto *FromField : D->fields()) {
6434 auto ToOrErr = import(FromField);
6435 if (!ToOrErr)
6436 return ToOrErr.takeError();
6437 }
6438
6439 // Import those methods which have been instantiated in the
6440 // "From" context, but not in the "To" context.
6441 for (CXXMethodDecl *FromM : D->methods()) {
6442 auto ToOrErr = import(FromM);
6443 if (!ToOrErr)
6444 return ToOrErr.takeError();
6445 }
6446
6447 // TODO Import instantiated default arguments.
6448 // TODO Import instantiated exception specifications.
6449 //
6450 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6451 // what else could be fused during an AST merge.
6452 return PrevDefinition;
6453 }
6454 } else { // ODR violation.
6455 // FIXME HandleNameConflict
6456 return make_error<ASTImportError>(ASTImportError::NameConflict);
6457 }
6458 }
6459
6460 // Import the location of this declaration.
6461 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6462 if (!BeginLocOrErr)
6463 return BeginLocOrErr.takeError();
6464 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6465 if (!IdLocOrErr)
6466 return IdLocOrErr.takeError();
6467
6468 // Import TemplateArgumentListInfo.
6469 TemplateArgumentListInfo ToTAInfo;
6470 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6471 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6472 return std::move(Err);
6473 }
6474
6475 // Create the specialization.
6476 ClassTemplateSpecializationDecl *D2 = nullptr;
6477 if (PartialSpec) {
6478 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6479 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6480 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6481 /*CanonInjectedTST=*/CanQualType(),
6482 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6483 return D2;
6484
6485 // Update InsertPos, because preceding import calls may have invalidated
6486 // it by adding new specializations.
6488 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6489 InsertPos))
6490 // Add this partial specialization to the class template.
6491 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6493 import(PartialSpec->getInstantiatedFromMember()))
6494 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6495 else
6496 return ToInstOrErr.takeError();
6497
6498 updateLookupTableForTemplateParameters(*ToTPList);
6499 } else { // Not a partial specialization.
6500 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6501 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6502 TemplateArgs, D->hasStrictPackMatch(),
6503 PrevDecl))
6504 return D2;
6505
6506 // Update InsertPos, because preceding import calls may have invalidated
6507 // it by adding new specializations.
6508 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6509 // Add this specialization to the class template.
6510 ClassTemplate->AddSpecialization(D2, InsertPos);
6511 }
6512
6514
6515 // Set the context of this specialization/instantiation.
6516 D2->setLexicalDeclContext(LexicalDC);
6517
6518 // Add to the DC only if it was an explicit specialization/instantiation.
6520 LexicalDC->addDeclInternal(D2);
6521 }
6522
6523 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6524 D2->setBraceRange(*BraceRangeOrErr);
6525 else
6526 return BraceRangeOrErr.takeError();
6527
6528 if (Error Err = ImportTemplateParameterLists(D, D2))
6529 return std::move(Err);
6530
6531 // Import the qualifier, if any.
6532 if (auto LocOrErr = import(D->getQualifierLoc()))
6533 D2->setQualifierInfo(*LocOrErr);
6534 else
6535 return LocOrErr.takeError();
6536
6537 if (D->getTemplateArgsAsWritten())
6538 D2->setTemplateArgsAsWritten(ToTAInfo);
6539
6540 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6541 D2->setTemplateKeywordLoc(*LocOrErr);
6542 else
6543 return LocOrErr.takeError();
6544
6545 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6546 D2->setExternKeywordLoc(*LocOrErr);
6547 else
6548 return LocOrErr.takeError();
6549
6550 if (D->getPointOfInstantiation().isValid()) {
6551 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6552 D2->setPointOfInstantiation(*POIOrErr);
6553 else
6554 return POIOrErr.takeError();
6555 }
6556
6558
6559 if (auto P = D->getInstantiatedFrom()) {
6560 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6561 if (auto CTDorErr = import(CTD))
6562 D2->setInstantiationOf(*CTDorErr);
6563 } else {
6565 auto CTPSDOrErr = import(CTPSD);
6566 if (!CTPSDOrErr)
6567 return CTPSDOrErr.takeError();
6569 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6570 for (unsigned I = 0; I < DArgs.size(); ++I) {
6571 const TemplateArgument &DArg = DArgs[I];
6572 if (auto ArgOrErr = import(DArg))
6573 D2ArgsVec[I] = *ArgOrErr;
6574 else
6575 return ArgOrErr.takeError();
6576 }
6578 *CTPSDOrErr,
6579 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6580 }
6581 }
6582
6583 if (D->isCompleteDefinition())
6584 if (Error Err = ImportDefinition(D, D2))
6585 return std::move(Err);
6586
6587 return D2;
6588}
6589
6591 // Import the major distinguishing characteristics of this variable template.
6592 DeclContext *DC, *LexicalDC;
6593 DeclarationName Name;
6594 SourceLocation Loc;
6595 NamedDecl *ToD;
6596 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6597 return std::move(Err);
6598 if (ToD)
6599 return ToD;
6600
6601 // We may already have a template of the same name; try to find and match it.
6602 assert(!DC->isFunctionOrMethod() &&
6603 "Variable templates cannot be declared at function scope");
6604
6605 SmallVector<NamedDecl *, 4> ConflictingDecls;
6606 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6607 VarTemplateDecl *FoundByLookup = nullptr;
6608 for (auto *FoundDecl : FoundDecls) {
6609 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6610 continue;
6611
6612 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6613 // Use the templated decl, some linkage flags are set only there.
6614 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6615 D->getTemplatedDecl()))
6616 continue;
6617 if (IsStructuralMatch(D, FoundTemplate)) {
6618 // FIXME Check for ODR error if the two definitions have
6619 // different initializers?
6620 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6621 if (D->getDeclContext()->isRecord()) {
6622 assert(FoundTemplate->getDeclContext()->isRecord() &&
6623 "Member variable template imported as non-member, "
6624 "inconsistent imported AST?");
6625 if (FoundDef)
6626 return Importer.MapImported(D, FoundDef);
6628 return Importer.MapImported(D, FoundTemplate);
6629 } else {
6630 if (FoundDef && D->isThisDeclarationADefinition())
6631 return Importer.MapImported(D, FoundDef);
6632 }
6633 FoundByLookup = FoundTemplate;
6634 break;
6635 }
6636 ConflictingDecls.push_back(FoundDecl);
6637 }
6638 }
6639
6640 if (!ConflictingDecls.empty()) {
6641 ExpectedName NameOrErr = Importer.HandleNameConflict(
6642 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6643 ConflictingDecls.size());
6644 if (NameOrErr)
6645 Name = NameOrErr.get();
6646 else
6647 return NameOrErr.takeError();
6648 }
6649
6650 VarDecl *DTemplated = D->getTemplatedDecl();
6651
6652 // Import the type.
6653 // FIXME: Value not used?
6654 ExpectedType TypeOrErr = import(DTemplated->getType());
6655 if (!TypeOrErr)
6656 return TypeOrErr.takeError();
6657
6658 // Create the declaration that is being templated.
6659 VarDecl *ToTemplated;
6660 if (Error Err = importInto(ToTemplated, DTemplated))
6661 return std::move(Err);
6662
6663 // Create the variable template declaration itself.
6664 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6665 if (!TemplateParamsOrErr)
6666 return TemplateParamsOrErr.takeError();
6667
6668 VarTemplateDecl *ToVarTD;
6669 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6670 Name, *TemplateParamsOrErr, ToTemplated))
6671 return ToVarTD;
6672
6673 ToTemplated->setDescribedVarTemplate(ToVarTD);
6674
6675 ToVarTD->setAccess(D->getAccess());
6676 ToVarTD->setLexicalDeclContext(LexicalDC);
6677 LexicalDC->addDeclInternal(ToVarTD);
6678 if (DC != Importer.getToContext().getTranslationUnitDecl())
6679 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6680
6681 if (FoundByLookup) {
6682 auto *Recent =
6683 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6684 if (!ToTemplated->getPreviousDecl()) {
6685 auto *PrevTemplated =
6686 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6687 if (ToTemplated != PrevTemplated)
6688 ToTemplated->setPreviousDecl(PrevTemplated);
6689 }
6690 ToVarTD->setPreviousDecl(Recent);
6691 }
6692
6693 return ToVarTD;
6694}
6695
6698 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6699 // in an analog way (but specialized for this case).
6700
6702 auto RedeclIt = Redecls.begin();
6703 // Import the first part of the decl chain. I.e. import all previous
6704 // declarations starting from the canonical decl.
6705 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6706 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6707 if (!RedeclOrErr)
6708 return RedeclOrErr.takeError();
6709 }
6710 assert(*RedeclIt == D);
6711
6712 VarTemplateDecl *VarTemplate = nullptr;
6714 return std::move(Err);
6715
6716 // Import the context of this declaration.
6717 DeclContext *DC, *LexicalDC;
6718 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6719 return std::move(Err);
6720
6721 // Import the location of this declaration.
6722 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6723 if (!BeginLocOrErr)
6724 return BeginLocOrErr.takeError();
6725
6726 auto IdLocOrErr = import(D->getLocation());
6727 if (!IdLocOrErr)
6728 return IdLocOrErr.takeError();
6729
6730 // Import template arguments.
6732 if (Error Err =
6733 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6734 return std::move(Err);
6735
6736 // Try to find an existing specialization with these template arguments.
6737 void *InsertPos = nullptr;
6738 VarTemplateSpecializationDecl *FoundSpecialization =
6739 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6740 if (FoundSpecialization) {
6741 if (IsStructuralMatch(D, FoundSpecialization)) {
6742 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6743 if (D->getDeclContext()->isRecord()) {
6744 // In a record, it is allowed only to have one optional declaration and
6745 // one definition of the (static or constexpr) variable template.
6746 assert(
6747 FoundSpecialization->getDeclContext()->isRecord() &&
6748 "Member variable template specialization imported as non-member, "
6749 "inconsistent imported AST?");
6750 if (FoundDef)
6751 return Importer.MapImported(D, FoundDef);
6753 return Importer.MapImported(D, FoundSpecialization);
6754 } else {
6755 // If definition is imported and there is already one, map to it.
6756 // Otherwise create a new variable and link it to the existing.
6757 if (FoundDef && D->isThisDeclarationADefinition())
6758 return Importer.MapImported(D, FoundDef);
6759 }
6760 } else {
6761 return make_error<ASTImportError>(ASTImportError::NameConflict);
6762 }
6763 }
6764
6765 VarTemplateSpecializationDecl *D2 = nullptr;
6766
6767 TemplateArgumentListInfo ToTAInfo;
6768 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6769 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6770 return std::move(Err);
6771 }
6772
6773 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6774 // Create a new specialization.
6775 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6776 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6777 if (!ToTPListOrErr)
6778 return ToTPListOrErr.takeError();
6779
6780 PartVarSpecDecl *ToPartial;
6781 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6782 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6783 VarTemplate, QualType(), nullptr,
6784 D->getStorageClass(), TemplateArgs))
6785 return ToPartial;
6786
6787 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6788 import(FromPartial->getInstantiatedFromMember()))
6789 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6790 else
6791 return ToInstOrErr.takeError();
6792
6793 if (FromPartial->isMemberSpecialization())
6794 ToPartial->setMemberSpecialization();
6795
6796 D2 = ToPartial;
6797
6798 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6799 // to adopt template parameters.
6800 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6801 } else { // Full specialization
6802 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6803 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6804 QualType(), nullptr, D->getStorageClass(),
6805 TemplateArgs))
6806 return D2;
6807 }
6808
6809 // Update InsertPos, because preceding import calls may have invalidated
6810 // it by adding new specializations.
6811 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6812 VarTemplate->AddSpecialization(D2, InsertPos);
6813
6814 QualType T;
6815 if (Error Err = importInto(T, D->getType()))
6816 return std::move(Err);
6817 D2->setType(T);
6818
6819 auto TInfoOrErr = import(D->getTypeSourceInfo());
6820 if (!TInfoOrErr)
6821 return TInfoOrErr.takeError();
6822 D2->setTypeSourceInfo(*TInfoOrErr);
6823
6824 if (D->getPointOfInstantiation().isValid()) {
6825 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6826 D2->setPointOfInstantiation(*POIOrErr);
6827 else
6828 return POIOrErr.takeError();
6829 }
6830
6832
6833 if (D->getTemplateArgsAsWritten())
6834 D2->setTemplateArgsAsWritten(ToTAInfo);
6835
6836 if (auto LocOrErr = import(D->getQualifierLoc()))
6837 D2->setQualifierInfo(*LocOrErr);
6838 else
6839 return LocOrErr.takeError();
6840
6841 if (D->isConstexpr())
6842 D2->setConstexpr(true);
6843
6844 D2->setAccess(D->getAccess());
6845
6846 if (Error Err = ImportInitializer(D, D2))
6847 return std::move(Err);
6848
6849 if (FoundSpecialization)
6850 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6851
6852 addDeclToContexts(D, D2);
6853
6854 // Import the rest of the chain. I.e. import all subsequent declarations.
6855 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6856 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6857 if (!RedeclOrErr)
6858 return RedeclOrErr.takeError();
6859 }
6860
6861 return D2;
6862}
6863
6866 DeclContext *DC, *LexicalDC;
6867 DeclarationName Name;
6868 SourceLocation Loc;
6869 NamedDecl *ToD;
6870
6871 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6872 return std::move(Err);
6873
6874 if (ToD)
6875 return ToD;
6876
6877 const FunctionTemplateDecl *FoundByLookup = nullptr;
6878
6879 // Try to find a function in our own ("to") context with the same name, same
6880 // type, and in the same context as the function we're importing.
6881 // FIXME Split this into a separate function.
6882 if (!LexicalDC->isFunctionOrMethod()) {
6884 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6885 for (auto *FoundDecl : FoundDecls) {
6886 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6887 continue;
6888
6889 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6890 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6891 continue;
6892 if (IsStructuralMatch(D, FoundTemplate)) {
6893 FunctionTemplateDecl *TemplateWithDef =
6894 getTemplateDefinition(FoundTemplate);
6895 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6896 return Importer.MapImported(D, TemplateWithDef);
6897
6898 FoundByLookup = FoundTemplate;
6899 break;
6900 // TODO: handle conflicting names
6901 }
6902 }
6903 }
6904 }
6905
6906 auto ParamsOrErr = import(D->getTemplateParameters());
6907 if (!ParamsOrErr)
6908 return ParamsOrErr.takeError();
6909 TemplateParameterList *Params = *ParamsOrErr;
6910
6911 FunctionDecl *TemplatedFD;
6912 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6913 return std::move(Err);
6914
6915 // At creation of the template the template parameters are "adopted"
6916 // (DeclContext is changed). After this possible change the lookup table
6917 // must be updated.
6918 // At deduction guides the DeclContext of the template parameters may be
6919 // different from what we would expect, it may be the class template, or a
6920 // probably different CXXDeductionGuideDecl. This may come from the fact that
6921 // the template parameter objects may be shared between deduction guides or
6922 // the class template, and at creation of multiple FunctionTemplateDecl
6923 // objects (for deduction guides) the same parameters are re-used. The
6924 // "adoption" happens multiple times with different parent, even recursively
6925 // for TemplateTemplateParmDecl. The same happens at import when the
6926 // FunctionTemplateDecl objects are created, but in different order.
6927 // In this way the DeclContext of these template parameters is not necessarily
6928 // the same as in the "from" context.
6930 OldParamDC.reserve(Params->size());
6931 llvm::transform(*Params, std::back_inserter(OldParamDC),
6932 [](NamedDecl *ND) { return ND->getDeclContext(); });
6933
6934 FunctionTemplateDecl *ToFunc;
6935 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6936 Params, TemplatedFD))
6937 return ToFunc;
6938
6939 // Fail if TemplatedFD is already part of a template.
6940 // The template should have been found by structural equivalence check before,
6941 // or ToFunc should be already imported.
6942 // If not, there is AST incompatibility that can be caused by previous import
6943 // errors. (NameConflict is not exact here.)
6944 if (TemplatedFD->getDescribedTemplate())
6945 return make_error<ASTImportError>(ASTImportError::NameConflict);
6946
6947 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6948
6949 ToFunc->setAccess(D->getAccess());
6950 ToFunc->setLexicalDeclContext(LexicalDC);
6951 addDeclToContexts(D, ToFunc);
6952
6953 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6954 if (LT && !OldParamDC.empty()) {
6955 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6956 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6957 }
6958
6959 if (FoundByLookup) {
6960 auto *Recent =
6961 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6962 if (!TemplatedFD->getPreviousDecl()) {
6963 assert(FoundByLookup->getTemplatedDecl() &&
6964 "Found decl must have its templated decl set");
6965 auto *PrevTemplated =
6966 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6967 if (TemplatedFD != PrevTemplated)
6968 TemplatedFD->setPreviousDecl(PrevTemplated);
6969 }
6970 ToFunc->setPreviousDecl(Recent);
6971 }
6972
6973 return ToFunc;
6974}
6975
6977 DeclContext *DC, *LexicalDC;
6978 Error Err = ImportDeclContext(D, DC, LexicalDC);
6979 auto LocationOrErr = importChecked(Err, D->getLocation());
6980 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6981 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6982 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6983 if (Err)
6984 return std::move(Err);
6985
6986 ConceptDecl *To;
6987 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6988 NameDeclOrErr, ToTemplateParameters,
6989 ConstraintExpr))
6990 return To;
6991 To->setLexicalDeclContext(LexicalDC);
6992 LexicalDC->addDeclInternal(To);
6993 return To;
6994}
6995
6998 DeclContext *DC, *LexicalDC;
6999 Error Err = ImportDeclContext(D, DC, LexicalDC);
7000 auto RequiresLoc = importChecked(Err, D->getLocation());
7001 if (Err)
7002 return std::move(Err);
7003
7005 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
7006 return To;
7007 To->setLexicalDeclContext(LexicalDC);
7008 LexicalDC->addDeclInternal(To);
7009 return To;
7010}
7011
7014 DeclContext *DC, *LexicalDC;
7015 Error Err = ImportDeclContext(D, DC, LexicalDC);
7016 auto ToSL = importChecked(Err, D->getLocation());
7017 if (Err)
7018 return std::move(Err);
7019
7021 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
7022 return std::move(Err);
7023
7025 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
7026 return To;
7027 To->setLexicalDeclContext(LexicalDC);
7028 LexicalDC->addDeclInternal(To);
7029 return To;
7030}
7031
7032//----------------------------------------------------------------------------
7033// Import Statements
7034//----------------------------------------------------------------------------
7035
7037 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7038 << S->getStmtClassName();
7039 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7040}
7041
7042
7044 if (Importer.returnWithErrorInTest())
7045 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7047 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7048 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7049 // ToII is nullptr when no symbolic name is given for output operand
7050 // see ParseStmtAsm::ParseAsmOperandsOpt
7051 Names.push_back(ToII);
7052 }
7053
7054 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7055 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7056 // ToII is nullptr when no symbolic name is given for input operand
7057 // see ParseStmtAsm::ParseAsmOperandsOpt
7058 Names.push_back(ToII);
7059 }
7060
7061 SmallVector<Expr *, 4> Clobbers;
7062 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7063 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7064 Clobbers.push_back(*ClobberOrErr);
7065 else
7066 return ClobberOrErr.takeError();
7067
7068 }
7069
7070 SmallVector<Expr *, 4> Constraints;
7071 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7072 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7073 Constraints.push_back(*OutputOrErr);
7074 else
7075 return OutputOrErr.takeError();
7076 }
7077
7078 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7079 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7080 Constraints.push_back(*InputOrErr);
7081 else
7082 return InputOrErr.takeError();
7083 }
7084
7086 S->getNumLabels());
7087 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7088 return std::move(Err);
7089
7090 if (Error Err =
7091 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7092 return std::move(Err);
7093
7094 if (Error Err = ImportArrayChecked(
7095 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7096 return std::move(Err);
7097
7098 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7099 if (!AsmLocOrErr)
7100 return AsmLocOrErr.takeError();
7101 auto AsmStrOrErr = import(S->getAsmStringExpr());
7102 if (!AsmStrOrErr)
7103 return AsmStrOrErr.takeError();
7104 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7105 if (!RParenLocOrErr)
7106 return RParenLocOrErr.takeError();
7107
7108 return new (Importer.getToContext()) GCCAsmStmt(
7109 Importer.getToContext(),
7110 *AsmLocOrErr,
7111 S->isSimple(),
7112 S->isVolatile(),
7113 S->getNumOutputs(),
7114 S->getNumInputs(),
7115 Names.data(),
7116 Constraints.data(),
7117 Exprs.data(),
7118 *AsmStrOrErr,
7119 S->getNumClobbers(),
7120 Clobbers.data(),
7121 S->getNumLabels(),
7122 *RParenLocOrErr);
7123}
7124
7126
7127 Error Err = Error::success();
7128 auto ToDG = importChecked(Err, S->getDeclGroup());
7129 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7130 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7131 if (Err)
7132 return std::move(Err);
7133 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7134}
7135
7137 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7138 if (!ToSemiLocOrErr)
7139 return ToSemiLocOrErr.takeError();
7140 return new (Importer.getToContext()) NullStmt(
7141 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7142}
7143
7145 SmallVector<Stmt *, 8> ToStmts(S->size());
7146
7147 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7148 return std::move(Err);
7149
7150 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7151 if (!ToLBracLocOrErr)
7152 return ToLBracLocOrErr.takeError();
7153
7154 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7155 if (!ToRBracLocOrErr)
7156 return ToRBracLocOrErr.takeError();
7157
7158 FPOptionsOverride FPO =
7160 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7161 *ToLBracLocOrErr, *ToRBracLocOrErr);
7162}
7163
7165
7166 Error Err = Error::success();
7167 auto ToLHS = importChecked(Err, S->getLHS());
7168 auto ToRHS = importChecked(Err, S->getRHS());
7169 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7170 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7171 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7172 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7173 if (Err)
7174 return std::move(Err);
7175
7176 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7177 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7178 ToStmt->setSubStmt(ToSubStmt);
7179
7180 return ToStmt;
7181}
7182
7184
7185 Error Err = Error::success();
7186 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7187 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7188 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7189 if (Err)
7190 return std::move(Err);
7191
7192 return new (Importer.getToContext()) DefaultStmt(
7193 ToDefaultLoc, ToColonLoc, ToSubStmt);
7194}
7195
7197
7198 Error Err = Error::success();
7199 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7200 auto ToLabelDecl = importChecked(Err, S->getDecl());
7201 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7202 if (Err)
7203 return std::move(Err);
7204
7205 return new (Importer.getToContext()) LabelStmt(
7206 ToIdentLoc, ToLabelDecl, ToSubStmt);
7207}
7208
7210 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7211 if (!ToAttrLocOrErr)
7212 return ToAttrLocOrErr.takeError();
7213 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7214 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7215 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7216 return std::move(Err);
7217 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7218 if (!ToSubStmtOrErr)
7219 return ToSubStmtOrErr.takeError();
7220
7222 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7223}
7224
7226
7227 Error Err = Error::success();
7228 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7229 auto ToInit = importChecked(Err, S->getInit());
7230 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7231 auto ToCond = importChecked(Err, S->getCond());
7232 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7233 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7234 auto ToThen = importChecked(Err, S->getThen());
7235 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7236 auto ToElse = importChecked(Err, S->getElse());
7237 if (Err)
7238 return std::move(Err);
7239
7240 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7241 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7242 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7243}
7244
7246
7247 Error Err = Error::success();
7248 auto ToInit = importChecked(Err, S->getInit());
7249 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7250 auto ToCond = importChecked(Err, S->getCond());
7251 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7252 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7253 auto ToBody = importChecked(Err, S->getBody());
7254 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7255 if (Err)
7256 return std::move(Err);
7257
7258 auto *ToStmt =
7259 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7260 ToCond, ToLParenLoc, ToRParenLoc);
7261 ToStmt->setBody(ToBody);
7262 ToStmt->setSwitchLoc(ToSwitchLoc);
7263
7264 // Now we have to re-chain the cases.
7265 SwitchCase *LastChainedSwitchCase = nullptr;
7266 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7267 SC = SC->getNextSwitchCase()) {
7268 Expected<SwitchCase *> ToSCOrErr = import(SC);
7269 if (!ToSCOrErr)
7270 return ToSCOrErr.takeError();
7271 if (LastChainedSwitchCase)
7272 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7273 else
7274 ToStmt->setSwitchCaseList(*ToSCOrErr);
7275 LastChainedSwitchCase = *ToSCOrErr;
7276 }
7277
7278 return ToStmt;
7279}
7280
7282
7283 Error Err = Error::success();
7284 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7285 auto ToCond = importChecked(Err, S->getCond());
7286 auto ToBody = importChecked(Err, S->getBody());
7287 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7288 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7289 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7290 if (Err)
7291 return std::move(Err);
7292
7293 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7294 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7295}
7296
7298
7299 Error Err = Error::success();
7300 auto ToBody = importChecked(Err, S->getBody());
7301 auto ToCond = importChecked(Err, S->getCond());
7302 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7303 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7304 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7305 if (Err)
7306 return std::move(Err);
7307
7308 return new (Importer.getToContext()) DoStmt(
7309 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7310}
7311
7313
7314 Error Err = Error::success();
7315 auto ToInit = importChecked(Err, S->getInit());
7316 auto ToCond = importChecked(Err, S->getCond());
7317 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7318 auto ToInc = importChecked(Err, S->getInc());
7319 auto ToBody = importChecked(Err, S->getBody());
7320 auto ToForLoc = importChecked(Err, S->getForLoc());
7321 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7322 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7323 if (Err)
7324 return std::move(Err);
7325
7326 return new (Importer.getToContext()) ForStmt(
7327 Importer.getToContext(),
7328 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7329 ToRParenLoc);
7330}
7331
7333
7334 Error Err = Error::success();
7335 auto ToLabel = importChecked(Err, S->getLabel());
7336 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7337 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7338 if (Err)
7339 return std::move(Err);
7340
7341 return new (Importer.getToContext()) GotoStmt(
7342 ToLabel, ToGotoLoc, ToLabelLoc);
7343}
7344
7346
7347 Error Err = Error::success();
7348 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7349 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7350 auto ToTarget = importChecked(Err, S->getTarget());
7351 if (Err)
7352 return std::move(Err);
7353
7354 return new (Importer.getToContext()) IndirectGotoStmt(
7355 ToGotoLoc, ToStarLoc, ToTarget);
7356}
7357
7358template <typename StmtClass>
7360 ASTImporter &Importer, StmtClass *S) {
7361 Error Err = Error::success();
7362 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7363 auto ToLabelLoc = S->hasLabelTarget()
7364 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7365 : SourceLocation();
7366 auto ToDecl = S->hasLabelTarget()
7367 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7368 : nullptr;
7369 if (Err)
7370 return std::move(Err);
7371 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7372}
7373
7377
7381
7383
7384 Error Err = Error::success();
7385 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7386 auto ToRetValue = importChecked(Err, S->getRetValue());
7387 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7388 if (Err)
7389 return std::move(Err);
7390
7391 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7392 ToNRVOCandidate);
7393}
7394
7396
7397 Error Err = Error::success();
7398 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7399 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7400 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7401 if (Err)
7402 return std::move(Err);
7403
7404 return new (Importer.getToContext()) CXXCatchStmt (
7405 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7406}
7407
7409 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7410 if (!ToTryLocOrErr)
7411 return ToTryLocOrErr.takeError();
7412
7413 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7414 if (!ToTryBlockOrErr)
7415 return ToTryBlockOrErr.takeError();
7416
7417 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7418 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7419 CXXCatchStmt *FromHandler = S->getHandler(HI);
7420 if (auto ToHandlerOrErr = import(FromHandler))
7421 ToHandlers[HI] = *ToHandlerOrErr;
7422 else
7423 return ToHandlerOrErr.takeError();
7424 }
7425
7426 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7427 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7428}
7429
7431
7432 Error Err = Error::success();
7433 auto ToInit = importChecked(Err, S->getInit());
7434 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7435 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7436 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7437 auto ToCond = importChecked(Err, S->getCond());
7438 auto ToInc = importChecked(Err, S->getInc());
7439 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7440 auto ToBody = importChecked(Err, S->getBody());
7441 auto ToForLoc = importChecked(Err, S->getForLoc());
7442 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7443 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7444 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7445 if (Err)
7446 return std::move(Err);
7447
7448 return new (Importer.getToContext()) CXXForRangeStmt(
7449 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7450 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7451}
7452
7455 Error Err = Error::success();
7456 auto ToElement = importChecked(Err, S->getElement());
7457 auto ToCollection = importChecked(Err, S->getCollection());
7458 auto ToBody = importChecked(Err, S->getBody());
7459 auto ToForLoc = importChecked(Err, S->getForLoc());
7460 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7461 if (Err)
7462 return std::move(Err);
7463
7464 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7465 ToCollection,
7466 ToBody,
7467 ToForLoc,
7468 ToRParenLoc);
7469}
7470
7472
7473 Error Err = Error::success();
7474 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7475 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7476 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7477 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7478 if (Err)
7479 return std::move(Err);
7480
7481 return new (Importer.getToContext()) ObjCAtCatchStmt (
7482 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7483}
7484
7486 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7487 if (!ToAtFinallyLocOrErr)
7488 return ToAtFinallyLocOrErr.takeError();
7489 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7490 if (!ToAtFinallyStmtOrErr)
7491 return ToAtFinallyStmtOrErr.takeError();
7492 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7493 *ToAtFinallyStmtOrErr);
7494}
7495
7497
7498 Error Err = Error::success();
7499 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7500 auto ToTryBody = importChecked(Err, S->getTryBody());
7501 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7502 if (Err)
7503 return std::move(Err);
7504
7505 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7506 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7507 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7508 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7509 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7510 else
7511 return ToCatchStmtOrErr.takeError();
7512 }
7513
7514 return ObjCAtTryStmt::Create(Importer.getToContext(),
7515 ToAtTryLoc, ToTryBody,
7516 ToCatchStmts.begin(), ToCatchStmts.size(),
7517 ToFinallyStmt);
7518}
7519
7522
7523 Error Err = Error::success();
7524 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7525 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7526 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7527 if (Err)
7528 return std::move(Err);
7529
7530 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7531 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7532}
7533
7535 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7536 if (!ToThrowLocOrErr)
7537 return ToThrowLocOrErr.takeError();
7538 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7539 if (!ToThrowExprOrErr)
7540 return ToThrowExprOrErr.takeError();
7541 return new (Importer.getToContext()) ObjCAtThrowStmt(
7542 *ToThrowLocOrErr, *ToThrowExprOrErr);
7543}
7544
7547 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7548 if (!ToAtLocOrErr)
7549 return ToAtLocOrErr.takeError();
7550 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7551 if (!ToSubStmtOrErr)
7552 return ToSubStmtOrErr.takeError();
7553 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7554 *ToSubStmtOrErr);
7555}
7556
7557//----------------------------------------------------------------------------
7558// Import Expressions
7559//----------------------------------------------------------------------------
7561 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7562 << E->getStmtClassName();
7563 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7564}
7565
7567 Error Err = Error::success();
7568 auto ToType = importChecked(Err, E->getType());
7569 auto BLoc = importChecked(Err, E->getBeginLoc());
7570 auto RParenLoc = importChecked(Err, E->getEndLoc());
7571 if (Err)
7572 return std::move(Err);
7573 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7574 if (!ParentContextOrErr)
7575 return ParentContextOrErr.takeError();
7576
7577 return new (Importer.getToContext())
7578 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7579 RParenLoc, *ParentContextOrErr);
7580}
7581
7583
7584 Error Err = Error::success();
7585 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7586 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7587 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7588 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7589 auto ToType = importChecked(Err, E->getType());
7590 if (Err)
7591 return std::move(Err);
7592
7593 return new (Importer.getToContext()) VAArgExpr(
7594 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7595 E->isMicrosoftABI());
7596}
7597
7599
7600 Error Err = Error::success();
7601 auto ToCond = importChecked(Err, E->getCond());
7602 auto ToLHS = importChecked(Err, E->getLHS());
7603 auto ToRHS = importChecked(Err, E->getRHS());
7604 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7605 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7606 auto ToType = importChecked(Err, E->getType());
7607 if (Err)
7608 return std::move(Err);
7609
7611 ExprObjectKind OK = E->getObjectKind();
7612
7613 // The value of CondIsTrue only matters if the value is not
7614 // condition-dependent.
7615 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7616
7617 return new (Importer.getToContext())
7618 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7619 ToRParenLoc, CondIsTrue);
7620}
7621
7623 Error Err = Error::success();
7624 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7625 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7626 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7627 auto ToType = importChecked(Err, E->getType());
7628 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7629 if (Err)
7630 return std::move(Err);
7631
7633 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7634 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7636}
7637
7639 Error Err = Error::success();
7640 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7641 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7642 auto ToType = importChecked(Err, E->getType());
7643 const unsigned NumSubExprs = E->getNumSubExprs();
7644
7646 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7647 ToSubExprs.resize(NumSubExprs);
7648
7649 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7650 return std::move(Err);
7651
7652 return new (Importer.getToContext()) ShuffleVectorExpr(
7653 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7654}
7655
7657 ExpectedType TypeOrErr = import(E->getType());
7658 if (!TypeOrErr)
7659 return TypeOrErr.takeError();
7660
7661 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7662 if (!BeginLocOrErr)
7663 return BeginLocOrErr.takeError();
7664
7665 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7666}
7667
7670 Error Err = Error::success();
7671 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7672 Expr *ToControllingExpr = nullptr;
7673 TypeSourceInfo *ToControllingType = nullptr;
7674 if (E->isExprPredicate())
7675 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7676 else
7677 ToControllingType = importChecked(Err, E->getControllingType());
7678 assert((ToControllingExpr || ToControllingType) &&
7679 "Either the controlling expr or type must be nonnull");
7680 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7681 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7682 if (Err)
7683 return std::move(Err);
7684
7686 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7687 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7688 return std::move(Err);
7689
7690 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7691 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7692 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7693 return std::move(Err);
7694
7695 const ASTContext &ToCtx = Importer.getToContext();
7696 if (E->isResultDependent()) {
7697 if (ToControllingExpr) {
7699 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7700 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7702 }
7704 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7705 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7707 }
7708
7709 if (ToControllingExpr) {
7711 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7712 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7714 }
7716 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7717 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7719}
7720
7722
7723 Error Err = Error::success();
7724 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7725 auto ToType = importChecked(Err, E->getType());
7726 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7727 if (Err)
7728 return std::move(Err);
7729
7730 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7731 E->getIdentKind(), E->isTransparent(),
7732 ToFunctionName);
7733}
7734
7736
7737 Error Err = Error::success();
7738 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7739 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7740 auto ToDecl = importChecked(Err, E->getDecl());
7741 auto ToLocation = importChecked(Err, E->getLocation());
7742 auto ToType = importChecked(Err, E->getType());
7743 if (Err)
7744 return std::move(Err);
7745
7746 NamedDecl *ToFoundD = nullptr;
7747 if (E->getDecl() != E->getFoundDecl()) {
7748 auto FoundDOrErr = import(E->getFoundDecl());
7749 if (!FoundDOrErr)
7750 return FoundDOrErr.takeError();
7751 ToFoundD = *FoundDOrErr;
7752 }
7753
7754 TemplateArgumentListInfo ToTAInfo;
7755 TemplateArgumentListInfo *ToResInfo = nullptr;
7756 if (E->hasExplicitTemplateArgs()) {
7757 if (Error Err =
7759 E->template_arguments(), ToTAInfo))
7760 return std::move(Err);
7761 ToResInfo = &ToTAInfo;
7762 }
7763
7764 auto *ToE = DeclRefExpr::Create(
7765 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7766 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7767 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7768 if (E->hadMultipleCandidates())
7769 ToE->setHadMultipleCandidates(true);
7770 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7771 return ToE;
7772}
7773
7775 ExpectedType TypeOrErr = import(E->getType());
7776 if (!TypeOrErr)
7777 return TypeOrErr.takeError();
7778
7779 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7780}
7781
7783 ExpectedExpr ToInitOrErr = import(E->getInit());
7784 if (!ToInitOrErr)
7785 return ToInitOrErr.takeError();
7786
7787 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7788 if (!ToEqualOrColonLocOrErr)
7789 return ToEqualOrColonLocOrErr.takeError();
7790
7791 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7792 // List elements from the second, the first is Init itself
7793 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7794 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7795 ToIndexExprs[I - 1] = *ToArgOrErr;
7796 else
7797 return ToArgOrErr.takeError();
7798 }
7799
7800 SmallVector<Designator, 4> ToDesignators(E->size());
7801 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7802 return std::move(Err);
7803
7805 Importer.getToContext(), ToDesignators,
7806 ToIndexExprs, *ToEqualOrColonLocOrErr,
7807 E->usesGNUSyntax(), *ToInitOrErr);
7808}
7809
7812 ExpectedType ToTypeOrErr = import(E->getType());
7813 if (!ToTypeOrErr)
7814 return ToTypeOrErr.takeError();
7815
7816 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7817 if (!ToLocationOrErr)
7818 return ToLocationOrErr.takeError();
7819
7820 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7821 *ToTypeOrErr, *ToLocationOrErr);
7822}
7823
7825 ExpectedType ToTypeOrErr = import(E->getType());
7826 if (!ToTypeOrErr)
7827 return ToTypeOrErr.takeError();
7828
7829 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7830 if (!ToLocationOrErr)
7831 return ToLocationOrErr.takeError();
7832
7834 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7835}
7836
7837
7839 ExpectedType ToTypeOrErr = import(E->getType());
7840 if (!ToTypeOrErr)
7841 return ToTypeOrErr.takeError();
7842
7843 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7844 if (!ToLocationOrErr)
7845 return ToLocationOrErr.takeError();
7846
7848 Importer.getToContext(), E->getValue(), E->isExact(),
7849 *ToTypeOrErr, *ToLocationOrErr);
7850}
7851
7853 auto ToTypeOrErr = import(E->getType());
7854 if (!ToTypeOrErr)
7855 return ToTypeOrErr.takeError();
7856
7857 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7858 if (!ToSubExprOrErr)
7859 return ToSubExprOrErr.takeError();
7860
7861 return new (Importer.getToContext()) ImaginaryLiteral(
7862 *ToSubExprOrErr, *ToTypeOrErr);
7863}
7864
7866 auto ToTypeOrErr = import(E->getType());
7867 if (!ToTypeOrErr)
7868 return ToTypeOrErr.takeError();
7869
7870 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7871 if (!ToLocationOrErr)
7872 return ToLocationOrErr.takeError();
7873
7874 return new (Importer.getToContext()) FixedPointLiteral(
7875 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7876 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7877}
7878
7880 ExpectedType ToTypeOrErr = import(E->getType());
7881 if (!ToTypeOrErr)
7882 return ToTypeOrErr.takeError();
7883
7884 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7885 if (!ToLocationOrErr)
7886 return ToLocationOrErr.takeError();
7887
7888 return new (Importer.getToContext()) CharacterLiteral(
7889 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7890}
7891
7893 ExpectedType ToTypeOrErr = import(E->getType());
7894 if (!ToTypeOrErr)
7895 return ToTypeOrErr.takeError();
7896
7898 if (Error Err = ImportArrayChecked(
7899 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7900 return std::move(Err);
7901
7902 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7903 E->getKind(), E->isPascal(), *ToTypeOrErr,
7904 ToLocations);
7905}
7906
7908
7909 Error Err = Error::success();
7910 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7911 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7912 auto ToType = importChecked(Err, E->getType());
7913 auto ToInitializer = importChecked(Err, E->getInitializer());
7914 if (Err)
7915 return std::move(Err);
7916
7917 return new (Importer.getToContext()) CompoundLiteralExpr(
7918 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7919 ToInitializer, E->isFileScope());
7920}
7921
7923
7924 Error Err = Error::success();
7925 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7926 auto ToType = importChecked(Err, E->getType());
7927 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7928 if (Err)
7929 return std::move(Err);
7930
7932 if (Error Err = ImportArrayChecked(
7933 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7934 ToExprs.begin()))
7935 return std::move(Err);
7936
7937 return new (Importer.getToContext()) AtomicExpr(
7938
7939 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7940}
7941
7943 Error Err = Error::success();
7944 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7945 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7946 auto ToLabel = importChecked(Err, E->getLabel());
7947 auto ToType = importChecked(Err, E->getType());
7948 if (Err)
7949 return std::move(Err);
7950
7951 return new (Importer.getToContext()) AddrLabelExpr(
7952 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7953}
7955 Error Err = Error::success();
7956 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7957 auto ToResult = importChecked(Err, E->getAPValueResult());
7958 if (Err)
7959 return std::move(Err);
7960
7961 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7962}
7964 Error Err = Error::success();
7965 auto ToLParen = importChecked(Err, E->getLParen());
7966 auto ToRParen = importChecked(Err, E->getRParen());
7967 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7968 if (Err)
7969 return std::move(Err);
7970
7971 return new (Importer.getToContext())
7972 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7973}
7974
7976 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7977 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7978 return std::move(Err);
7979
7980 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7981 if (!ToLParenLocOrErr)
7982 return ToLParenLocOrErr.takeError();
7983
7984 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7985 if (!ToRParenLocOrErr)
7986 return ToRParenLocOrErr.takeError();
7987
7988 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7989 ToExprs, *ToRParenLocOrErr);
7990}
7991
7993 Error Err = Error::success();
7994 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7995 auto ToType = importChecked(Err, E->getType());
7996 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7997 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7998 if (Err)
7999 return std::move(Err);
8000
8001 return new (Importer.getToContext())
8002 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8003 E->getTemplateDepth());
8004}
8005
8007 Error Err = Error::success();
8008 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8009 auto ToType = importChecked(Err, E->getType());
8010 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8011 if (Err)
8012 return std::move(Err);
8013
8014 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8015 E->hasStoredFPFeatures());
8016 UO->setType(ToType);
8017 UO->setSubExpr(ToSubExpr);
8018 UO->setOpcode(E->getOpcode());
8019 UO->setOperatorLoc(ToOperatorLoc);
8020 UO->setCanOverflow(E->canOverflow());
8021 if (E->hasStoredFPFeatures())
8022 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8023
8024 return UO;
8025}
8026
8028
8030 Error Err = Error::success();
8031 auto ToType = importChecked(Err, E->getType());
8032 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8033 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8034 if (Err)
8035 return std::move(Err);
8036
8037 if (E->isArgumentType()) {
8038 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8039 import(E->getArgumentTypeInfo());
8040 if (!ToArgumentTypeInfoOrErr)
8041 return ToArgumentTypeInfoOrErr.takeError();
8042
8043 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8044 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8045 ToRParenLoc);
8046 }
8047
8048 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8049 if (!ToArgumentExprOrErr)
8050 return ToArgumentExprOrErr.takeError();
8051
8052 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8053 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8054}
8055
8057 Error Err = Error::success();
8058 auto ToLHS = importChecked(Err, E->getLHS());
8059 auto ToRHS = importChecked(Err, E->getRHS());
8060 auto ToType = importChecked(Err, E->getType());
8061 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8062 if (Err)
8063 return std::move(Err);
8064
8066 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8067 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8068 E->getFPFeatures());
8069}
8070
8072 Error Err = Error::success();
8073 auto ToCond = importChecked(Err, E->getCond());
8074 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8075 auto ToLHS = importChecked(Err, E->getLHS());
8076 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8077 auto ToRHS = importChecked(Err, E->getRHS());
8078 auto ToType = importChecked(Err, E->getType());
8079 if (Err)
8080 return std::move(Err);
8081
8082 return new (Importer.getToContext()) ConditionalOperator(
8083 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8084 E->getValueKind(), E->getObjectKind());
8085}
8086
8089 Error Err = Error::success();
8090 auto ToCommon = importChecked(Err, E->getCommon());
8091 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8092 auto ToCond = importChecked(Err, E->getCond());
8093 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8094 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8095 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8096 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8097 auto ToType = importChecked(Err, E->getType());
8098 if (Err)
8099 return std::move(Err);
8100
8101 return new (Importer.getToContext()) BinaryConditionalOperator(
8102 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8103 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8104 E->getObjectKind());
8105}
8106
8109 Error Err = Error::success();
8110 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8111 if (Err)
8112 return std::move(Err);
8113
8114 return new (Importer.getToContext())
8115 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8116}
8117
8119 Error Err = Error::success();
8120 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8121 auto ToQueriedTypeSourceInfo =
8123 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8124 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8125 auto ToType = importChecked(Err, E->getType());
8126 if (Err)
8127 return std::move(Err);
8128
8129 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8130 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8131 ToDimensionExpression, ToEndLoc, ToType);
8132}
8133
8135 Error Err = Error::success();
8136 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8137 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8138 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8139 auto ToType = importChecked(Err, E->getType());
8140 if (Err)
8141 return std::move(Err);
8142
8143 return new (Importer.getToContext()) ExpressionTraitExpr(
8144 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8145 ToEndLoc, ToType);
8146}
8147
8149 Error Err = Error::success();
8150 auto ToLocation = importChecked(Err, E->getLocation());
8151 auto ToType = importChecked(Err, E->getType());
8152 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8153 if (Err)
8154 return std::move(Err);
8155
8156 return new (Importer.getToContext()) OpaqueValueExpr(
8157 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8158}
8159
8161 Error Err = Error::success();
8162 auto ToLHS = importChecked(Err, E->getLHS());
8163 auto ToRHS = importChecked(Err, E->getRHS());
8164 auto ToType = importChecked(Err, E->getType());
8165 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8166 if (Err)
8167 return std::move(Err);
8168
8169 return new (Importer.getToContext()) ArraySubscriptExpr(
8170 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8171 ToRBracketLoc);
8172}
8173
8176 Error Err = Error::success();
8177 auto ToLHS = importChecked(Err, E->getLHS());
8178 auto ToRHS = importChecked(Err, E->getRHS());
8179 auto ToType = importChecked(Err, E->getType());
8180 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8181 auto ToComputationResultType =
8183 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8184 if (Err)
8185 return std::move(Err);
8186
8188 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8189 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8190 E->getFPFeatures(),
8191 ToComputationLHSType, ToComputationResultType);
8192}
8193
8196 CXXCastPath Path;
8197 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8198 if (auto SpecOrErr = import(*I))
8199 Path.push_back(*SpecOrErr);
8200 else
8201 return SpecOrErr.takeError();
8202 }
8203 return Path;
8204}
8205
8207 ExpectedType ToTypeOrErr = import(E->getType());
8208 if (!ToTypeOrErr)
8209 return ToTypeOrErr.takeError();
8210
8211 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8212 if (!ToSubExprOrErr)
8213 return ToSubExprOrErr.takeError();
8214
8215 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8216 if (!ToBasePathOrErr)
8217 return ToBasePathOrErr.takeError();
8218
8220 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8221 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8222}
8223
8225 Error Err = Error::success();
8226 auto ToType = importChecked(Err, E->getType());
8227 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8228 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8229 if (Err)
8230 return std::move(Err);
8231
8232 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8233 if (!ToBasePathOrErr)
8234 return ToBasePathOrErr.takeError();
8235 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8236
8237 switch (E->getStmtClass()) {
8238 case Stmt::CStyleCastExprClass: {
8239 auto *CCE = cast<CStyleCastExpr>(E);
8240 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8241 if (!ToLParenLocOrErr)
8242 return ToLParenLocOrErr.takeError();
8243 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8244 if (!ToRParenLocOrErr)
8245 return ToRParenLocOrErr.takeError();
8247 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8248 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8249 *ToLParenLocOrErr, *ToRParenLocOrErr);
8250 }
8251
8252 case Stmt::CXXFunctionalCastExprClass: {
8253 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8254 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8255 if (!ToLParenLocOrErr)
8256 return ToLParenLocOrErr.takeError();
8257 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8258 if (!ToRParenLocOrErr)
8259 return ToRParenLocOrErr.takeError();
8261 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8262 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8263 *ToLParenLocOrErr, *ToRParenLocOrErr);
8264 }
8265
8266 case Stmt::ObjCBridgedCastExprClass: {
8267 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8268 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8269 if (!ToLParenLocOrErr)
8270 return ToLParenLocOrErr.takeError();
8271 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8272 if (!ToBridgeKeywordLocOrErr)
8273 return ToBridgeKeywordLocOrErr.takeError();
8274 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8275 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8276 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8277 }
8278 case Stmt::BuiltinBitCastExprClass: {
8279 auto *BBC = cast<BuiltinBitCastExpr>(E);
8280 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8281 if (!ToKWLocOrErr)
8282 return ToKWLocOrErr.takeError();
8283 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8284 if (!ToRParenLocOrErr)
8285 return ToRParenLocOrErr.takeError();
8286 return new (Importer.getToContext()) BuiltinBitCastExpr(
8287 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8288 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8289 }
8290 default:
8291 llvm_unreachable("Cast expression of unsupported type!");
8292 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8293 }
8294}
8295
8298 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8299 const OffsetOfNode &FromNode = E->getComponent(I);
8300
8301 SourceLocation ToBeginLoc, ToEndLoc;
8302
8303 if (FromNode.getKind() != OffsetOfNode::Base) {
8304 Error Err = Error::success();
8305 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8306 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8307 if (Err)
8308 return std::move(Err);
8309 }
8310
8311 switch (FromNode.getKind()) {
8313 ToNodes.push_back(
8314 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8315 break;
8316 case OffsetOfNode::Base: {
8317 auto ToBSOrErr = import(FromNode.getBase());
8318 if (!ToBSOrErr)
8319 return ToBSOrErr.takeError();
8320 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8321 break;
8322 }
8323 case OffsetOfNode::Field: {
8324 auto ToFieldOrErr = import(FromNode.getField());
8325 if (!ToFieldOrErr)
8326 return ToFieldOrErr.takeError();
8327 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8328 break;
8329 }
8331 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8332 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8333 break;
8334 }
8335 }
8336 }
8337
8339 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8340 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8341 if (!ToIndexExprOrErr)
8342 return ToIndexExprOrErr.takeError();
8343 ToExprs[I] = *ToIndexExprOrErr;
8344 }
8345
8346 Error Err = Error::success();
8347 auto ToType = importChecked(Err, E->getType());
8348 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8349 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8350 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8351 if (Err)
8352 return std::move(Err);
8353
8354 return OffsetOfExpr::Create(
8355 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8356 ToExprs, ToRParenLoc);
8357}
8358
8360 Error Err = Error::success();
8361 auto ToType = importChecked(Err, E->getType());
8362 auto ToOperand = importChecked(Err, E->getOperand());
8363 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8364 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8365 if (Err)
8366 return std::move(Err);
8367
8368 CanThrowResult ToCanThrow;
8369 if (E->isValueDependent())
8370 ToCanThrow = CT_Dependent;
8371 else
8372 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8373
8374 return new (Importer.getToContext()) CXXNoexceptExpr(
8375 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8376}
8377
8379 Error Err = Error::success();
8380 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8381 auto ToType = importChecked(Err, E->getType());
8382 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8383 if (Err)
8384 return std::move(Err);
8385
8386 return new (Importer.getToContext()) CXXThrowExpr(
8387 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8388}
8389
8391 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8392 if (!ToUsedLocOrErr)
8393 return ToUsedLocOrErr.takeError();
8394
8395 auto ToParamOrErr = import(E->getParam());
8396 if (!ToParamOrErr)
8397 return ToParamOrErr.takeError();
8398
8399 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8400 if (!UsedContextOrErr)
8401 return UsedContextOrErr.takeError();
8402
8403 // Import the default arg if it was not imported yet.
8404 // This is needed because it can happen that during the import of the
8405 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8406 // encountered here. The default argument for a ParmVarDecl is set in the
8407 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8408 // see VisitParmVarDecl).
8409 ParmVarDecl *ToParam = *ToParamOrErr;
8410 if (!ToParam->getDefaultArg()) {
8411 std::optional<ParmVarDecl *> FromParam =
8412 Importer.getImportedFromDecl(ToParam);
8413 assert(FromParam && "ParmVarDecl was not imported?");
8414
8415 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8416 return std::move(Err);
8417 }
8418 Expr *RewrittenInit = nullptr;
8419 if (E->hasRewrittenInit()) {
8420 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8421 if (!ExprOrErr)
8422 return ExprOrErr.takeError();
8423 RewrittenInit = ExprOrErr.get();
8424 }
8425 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8426 *ToParamOrErr, RewrittenInit,
8427 *UsedContextOrErr);
8428}
8429
8432 Error Err = Error::success();
8433 auto ToType = importChecked(Err, E->getType());
8434 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8435 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8436 if (Err)
8437 return std::move(Err);
8438
8439 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8440 ToType, ToTypeSourceInfo, ToRParenLoc);
8441}
8442
8445 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8446 if (!ToSubExprOrErr)
8447 return ToSubExprOrErr.takeError();
8448
8449 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8450 if (!ToDtorOrErr)
8451 return ToDtorOrErr.takeError();
8452
8453 ASTContext &ToCtx = Importer.getToContext();
8454 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8455 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8456}
8457
8459
8461 Error Err = Error::success();
8462 auto ToConstructor = importChecked(Err, E->getConstructor());
8463 auto ToType = importChecked(Err, E->getType());
8464 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8465 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8466 if (Err)
8467 return std::move(Err);
8468
8470 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8471 return std::move(Err);
8472
8474 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8475 ToParenOrBraceRange, E->hadMultipleCandidates(),
8478}
8479
8482 DeclContext *DC, *LexicalDC;
8483 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8484 return std::move(Err);
8485
8486 Error Err = Error::success();
8487 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8488 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8489 if (Err)
8490 return std::move(Err);
8491 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8492
8494 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8495 D->getManglingNumber()))
8496 return To;
8497
8498 To->setLexicalDeclContext(LexicalDC);
8499 LexicalDC->addDeclInternal(To);
8500 return To;
8501}
8502
8505 Error Err = Error::success();
8506 auto ToType = importChecked(Err, E->getType());
8507 Expr *ToTemporaryExpr = importChecked(
8508 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8509 auto ToMaterializedDecl =
8511 if (Err)
8512 return std::move(Err);
8513
8514 if (!ToTemporaryExpr)
8515 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8516
8517 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8518 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8519 ToMaterializedDecl);
8520
8521 return ToMTE;
8522}
8523
8525 Error Err = Error::success();
8526 auto *ToPattern = importChecked(Err, E->getPattern());
8527 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8528 if (Err)
8529 return std::move(Err);
8530
8531 return new (Importer.getToContext())
8532 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8533}
8534
8536 Error Err = Error::success();
8537 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8538 auto ToPack = importChecked(Err, E->getPack());
8539 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8540 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8541 if (Err)
8542 return std::move(Err);
8543
8544 UnsignedOrNone Length = std::nullopt;
8545 if (!E->isValueDependent())
8546 Length = E->getPackLength();
8547
8548 SmallVector<TemplateArgument, 8> ToPartialArguments;
8549 if (E->isPartiallySubstituted()) {
8551 ToPartialArguments))
8552 return std::move(Err);
8553 }
8554
8556 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8557 Length, ToPartialArguments);
8558}
8559
8560
8562 Error Err = Error::success();
8563 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8564 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8565 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8566 auto ToArraySize = importChecked(Err, E->getArraySize());
8567 auto ToInitializer = importChecked(Err, E->getInitializer());
8568 auto ToType = importChecked(Err, E->getType());
8569 auto ToAllocatedTypeSourceInfo =
8571 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8572 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8573 if (Err)
8574 return std::move(Err);
8575
8576 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8577 if (Error Err =
8578 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8579 return std::move(Err);
8580
8581 return CXXNewExpr::Create(
8582 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8583 ToOperatorDelete, E->implicitAllocationParameters(),
8584 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8585 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8586 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8587}
8588
8590 Error Err = Error::success();
8591 auto ToType = importChecked(Err, E->getType());
8592 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8593 auto ToArgument = importChecked(Err, E->getArgument());
8594 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8595 if (Err)
8596 return std::move(Err);
8597
8598 return new (Importer.getToContext()) CXXDeleteExpr(
8599 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8600 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8601 ToBeginLoc);
8602}
8603
8605 Error Err = Error::success();
8606 auto ToType = importChecked(Err, E->getType());
8607 auto ToLocation = importChecked(Err, E->getLocation());
8608 auto ToConstructor = importChecked(Err, E->getConstructor());
8609 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8610 if (Err)
8611 return std::move(Err);
8612
8614 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8615 return std::move(Err);
8616
8618 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8619 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8622 ToParenOrBraceRange);
8624 return ToE;
8625}
8626
8628 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8629 if (!ToSubExprOrErr)
8630 return ToSubExprOrErr.takeError();
8631
8633 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8634 return std::move(Err);
8635
8637 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8638 ToObjects);
8639}
8640
8642 Error Err = Error::success();
8643 auto ToCallee = importChecked(Err, E->getCallee());
8644 auto ToType = importChecked(Err, E->getType());
8645 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8646 if (Err)
8647 return std::move(Err);
8648
8650 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8651 return std::move(Err);
8652
8653 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8654 ToType, E->getValueKind(), ToRParenLoc,
8655 E->getFPFeatures());
8656}
8657
8659 ExpectedType ToTypeOrErr = import(E->getType());
8660 if (!ToTypeOrErr)
8661 return ToTypeOrErr.takeError();
8662
8663 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8664 if (!ToLocationOrErr)
8665 return ToLocationOrErr.takeError();
8666
8667 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8668 *ToTypeOrErr, E->isImplicit());
8669}
8670
8672 ExpectedType ToTypeOrErr = import(E->getType());
8673 if (!ToTypeOrErr)
8674 return ToTypeOrErr.takeError();
8675
8676 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8677 if (!ToLocationOrErr)
8678 return ToLocationOrErr.takeError();
8679
8680 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8681 *ToTypeOrErr, *ToLocationOrErr);
8682}
8683
8685 Error Err = Error::success();
8686 auto ToBase = importChecked(Err, E->getBase());
8687 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8688 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8689 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8690 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8691 auto ToType = importChecked(Err, E->getType());
8692 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8693 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8694 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8695 if (Err)
8696 return std::move(Err);
8697
8698 DeclAccessPair ToFoundDecl =
8700
8701 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8702
8703 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8704 if (E->hasExplicitTemplateArgs()) {
8705 if (Error Err =
8707 E->template_arguments(), ToTAInfo))
8708 return std::move(Err);
8709 ResInfo = &ToTAInfo;
8710 }
8711
8712 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8713 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8714 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8715 ResInfo, ToType, E->getValueKind(),
8716 E->getObjectKind(), E->isNonOdrUse());
8717}
8718
8721 Error Err = Error::success();
8722 auto ToBase = importChecked(Err, E->getBase());
8723 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8724 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8725 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8726 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8727 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8728 if (Err)
8729 return std::move(Err);
8730
8732 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8733 const IdentifierInfo *ToII = Importer.Import(FromII);
8734 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8735 if (!ToDestroyedTypeLocOrErr)
8736 return ToDestroyedTypeLocOrErr.takeError();
8737 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8738 } else {
8739 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8740 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8741 else
8742 return ToTIOrErr.takeError();
8743 }
8744
8745 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8746 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8747 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8748}
8749
8752 Error Err = Error::success();
8753 auto ToType = importChecked(Err, E->getType());
8754 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8755 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8756 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8757 auto ToFirstQualifierFoundInScope =
8759 if (Err)
8760 return std::move(Err);
8761
8762 Expr *ToBase = nullptr;
8763 if (!E->isImplicitAccess()) {
8764 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8765 ToBase = *ToBaseOrErr;
8766 else
8767 return ToBaseOrErr.takeError();
8768 }
8769
8770 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8771
8772 if (E->hasExplicitTemplateArgs()) {
8773 if (Error Err =
8775 E->template_arguments(), ToTAInfo))
8776 return std::move(Err);
8777 ResInfo = &ToTAInfo;
8778 }
8779 auto ToMember = importChecked(Err, E->getMember());
8780 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8781 if (Err)
8782 return std::move(Err);
8783 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8784
8785 // Import additional name location/type info.
8786 if (Error Err =
8787 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8788 return std::move(Err);
8789
8791 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8792 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8793 ToMemberNameInfo, ResInfo);
8794}
8795
8798 Error Err = Error::success();
8799 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8800 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8801 auto ToDeclName = importChecked(Err, E->getDeclName());
8802 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8803 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8804 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8805 if (Err)
8806 return std::move(Err);
8807
8808 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8809 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8810 return std::move(Err);
8811
8812 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8813 TemplateArgumentListInfo *ResInfo = nullptr;
8814 if (E->hasExplicitTemplateArgs()) {
8815 if (Error Err =
8817 return std::move(Err);
8818 ResInfo = &ToTAInfo;
8819 }
8820
8822 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8823 ToNameInfo, ResInfo);
8824}
8825
8828 Error Err = Error::success();
8829 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8830 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8831 auto ToType = importChecked(Err, E->getType());
8832 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8833 if (Err)
8834 return std::move(Err);
8835
8837 if (Error Err =
8838 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8839 return std::move(Err);
8840
8842 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8843 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8844}
8845
8848 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8849 if (!ToNamingClassOrErr)
8850 return ToNamingClassOrErr.takeError();
8851
8852 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8853 if (!ToQualifierLocOrErr)
8854 return ToQualifierLocOrErr.takeError();
8855
8856 Error Err = Error::success();
8857 auto ToName = importChecked(Err, E->getName());
8858 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8859 if (Err)
8860 return std::move(Err);
8861 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8862
8863 // Import additional name location/type info.
8864 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8865 return std::move(Err);
8866
8867 UnresolvedSet<8> ToDecls;
8868 for (auto *D : E->decls())
8869 if (auto ToDOrErr = import(D))
8870 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8871 else
8872 return ToDOrErr.takeError();
8873
8874 if (E->hasExplicitTemplateArgs()) {
8875 TemplateArgumentListInfo ToTAInfo;
8878 ToTAInfo))
8879 return std::move(Err);
8880
8881 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8882 if (!ToTemplateKeywordLocOrErr)
8883 return ToTemplateKeywordLocOrErr.takeError();
8884
8885 const bool KnownDependent =
8886 (E->getDependence() & ExprDependence::TypeValue) ==
8887 ExprDependence::TypeValue;
8889 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8890 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8891 ToDecls.begin(), ToDecls.end(), KnownDependent,
8892 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8893 }
8894
8896 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8897 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8898 /*KnownDependent=*/E->isTypeDependent(),
8899 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8900}
8901
8904 Error Err = Error::success();
8905 auto ToType = importChecked(Err, E->getType());
8906 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8907 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8908 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8909 auto ToName = importChecked(Err, E->getName());
8910 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8911 if (Err)
8912 return std::move(Err);
8913
8914 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8915 // Import additional name location/type info.
8916 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8917 return std::move(Err);
8918
8919 UnresolvedSet<8> ToDecls;
8920 for (Decl *D : E->decls())
8921 if (auto ToDOrErr = import(D))
8922 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8923 else
8924 return ToDOrErr.takeError();
8925
8926 TemplateArgumentListInfo ToTAInfo;
8927 TemplateArgumentListInfo *ResInfo = nullptr;
8928 if (E->hasExplicitTemplateArgs()) {
8929 TemplateArgumentListInfo FromTAInfo;
8930 E->copyTemplateArgumentsInto(FromTAInfo);
8931 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8932 return std::move(Err);
8933 ResInfo = &ToTAInfo;
8934 }
8935
8936 Expr *ToBase = nullptr;
8937 if (!E->isImplicitAccess()) {
8938 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8939 ToBase = *ToBaseOrErr;
8940 else
8941 return ToBaseOrErr.takeError();
8942 }
8943
8945 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8946 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8947 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8948}
8949
8951 Error Err = Error::success();
8952 auto ToCallee = importChecked(Err, E->getCallee());
8953 auto ToType = importChecked(Err, E->getType());
8954 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8955 if (Err)
8956 return std::move(Err);
8957
8958 unsigned NumArgs = E->getNumArgs();
8959 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8960 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8961 return std::move(Err);
8962
8963 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8965 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8966 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8967 OCE->getADLCallKind());
8968 }
8969
8970 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8971 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8972 /*MinNumArgs=*/0, E->getADLCallKind());
8973}
8974
8976 CXXRecordDecl *FromClass = E->getLambdaClass();
8977 auto ToClassOrErr = import(FromClass);
8978 if (!ToClassOrErr)
8979 return ToClassOrErr.takeError();
8980 CXXRecordDecl *ToClass = *ToClassOrErr;
8981
8982 auto ToCallOpOrErr = import(E->getCallOperator());
8983 if (!ToCallOpOrErr)
8984 return ToCallOpOrErr.takeError();
8985
8986 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8987 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8988 return std::move(Err);
8989
8990 Error Err = Error::success();
8991 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8992 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8993 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8994 if (Err)
8995 return std::move(Err);
8996
8997 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8998 E->getCaptureDefault(), ToCaptureDefaultLoc,
9000 E->hasExplicitResultType(), ToCaptureInits,
9001 ToEndLoc, E->containsUnexpandedParameterPack());
9002}
9003
9004
9006 Error Err = Error::success();
9007 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9008 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9009 auto ToType = importChecked(Err, E->getType());
9010 if (Err)
9011 return std::move(Err);
9012
9013 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9014 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9015 return std::move(Err);
9016
9017 ASTContext &ToCtx = Importer.getToContext();
9018 InitListExpr *To = new (ToCtx) InitListExpr(
9019 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
9020 To->setType(ToType);
9021
9022 if (E->hasArrayFiller()) {
9023 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9024 To->setArrayFiller(*ToFillerOrErr);
9025 else
9026 return ToFillerOrErr.takeError();
9027 }
9028
9029 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9030 if (auto ToFDOrErr = import(FromFD))
9031 To->setInitializedFieldInUnion(*ToFDOrErr);
9032 else
9033 return ToFDOrErr.takeError();
9034 }
9035
9036 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9037 if (auto ToSyntFormOrErr = import(SyntForm))
9038 To->setSyntacticForm(*ToSyntFormOrErr);
9039 else
9040 return ToSyntFormOrErr.takeError();
9041 }
9042
9043 // Copy InitListExprBitfields, which are not handled in the ctor of
9044 // InitListExpr.
9046
9047 return To;
9048}
9049
9052 ExpectedType ToTypeOrErr = import(E->getType());
9053 if (!ToTypeOrErr)
9054 return ToTypeOrErr.takeError();
9055
9056 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9057 if (!ToSubExprOrErr)
9058 return ToSubExprOrErr.takeError();
9059
9060 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9061 *ToTypeOrErr, *ToSubExprOrErr);
9062}
9063
9066 Error Err = Error::success();
9067 auto ToLocation = importChecked(Err, E->getLocation());
9068 auto ToType = importChecked(Err, E->getType());
9069 auto ToConstructor = importChecked(Err, E->getConstructor());
9070 if (Err)
9071 return std::move(Err);
9072
9073 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9074 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9075 E->inheritedFromVBase());
9076}
9077
9079 Error Err = Error::success();
9080 auto ToType = importChecked(Err, E->getType());
9081 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9082 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9083 if (Err)
9084 return std::move(Err);
9085
9086 return new (Importer.getToContext()) ArrayInitLoopExpr(
9087 ToType, ToCommonExpr, ToSubExpr);
9088}
9089
9091 ExpectedType ToTypeOrErr = import(E->getType());
9092 if (!ToTypeOrErr)
9093 return ToTypeOrErr.takeError();
9094 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9095}
9096
9098 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9099 if (!ToBeginLocOrErr)
9100 return ToBeginLocOrErr.takeError();
9101
9102 auto ToFieldOrErr = import(E->getField());
9103 if (!ToFieldOrErr)
9104 return ToFieldOrErr.takeError();
9105
9106 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9107 if (!UsedContextOrErr)
9108 return UsedContextOrErr.takeError();
9109
9110 FieldDecl *ToField = *ToFieldOrErr;
9111 assert(ToField->hasInClassInitializer() &&
9112 "Field should have in-class initializer if there is a default init "
9113 "expression that uses it.");
9114 if (!ToField->getInClassInitializer()) {
9115 // The in-class initializer may be not yet set in "To" AST even if the
9116 // field is already there. This must be set here to make construction of
9117 // CXXDefaultInitExpr work.
9118 auto ToInClassInitializerOrErr =
9119 import(E->getField()->getInClassInitializer());
9120 if (!ToInClassInitializerOrErr)
9121 return ToInClassInitializerOrErr.takeError();
9122 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9123 }
9124
9125 Expr *RewrittenInit = nullptr;
9126 if (E->hasRewrittenInit()) {
9127 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9128 if (!ExprOrErr)
9129 return ExprOrErr.takeError();
9130 RewrittenInit = ExprOrErr.get();
9131 }
9132
9133 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9134 ToField, *UsedContextOrErr, RewrittenInit);
9135}
9136
9138 Error Err = Error::success();
9139 auto ToType = importChecked(Err, E->getType());
9140 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9141 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9142 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9143 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9144 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9145 if (Err)
9146 return std::move(Err);
9147
9149 CastKind CK = E->getCastKind();
9150 auto ToBasePathOrErr = ImportCastPath(E);
9151 if (!ToBasePathOrErr)
9152 return ToBasePathOrErr.takeError();
9153
9154 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9156 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9157 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9158 ToAngleBrackets);
9159 } else if (isa<CXXDynamicCastExpr>(E)) {
9161 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9162 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9163 } else if (isa<CXXReinterpretCastExpr>(E)) {
9165 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9166 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9167 } else if (isa<CXXConstCastExpr>(E)) {
9169 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9170 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9171 } else {
9172 llvm_unreachable("Unknown cast type");
9173 return make_error<ASTImportError>();
9174 }
9175}
9176
9179 Error Err = Error::success();
9180 auto ToType = importChecked(Err, E->getType());
9181 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9182 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9183 auto ToReplacement = importChecked(Err, E->getReplacement());
9184 if (Err)
9185 return std::move(Err);
9186
9187 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9188 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9190 E->getFinal());
9191}
9192
9194 Error Err = Error::success();
9195 auto ToType = importChecked(Err, E->getType());
9196 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9197 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9198 if (Err)
9199 return std::move(Err);
9200
9202 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9203 return std::move(Err);
9204
9205 if (E->isStoredAsBoolean()) {
9206 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9207 // Value is always false.
9208 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9209 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9210 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9211 }
9212 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9213 E->getTrait(), ToArgs, ToEndLoc,
9214 E->getAPValue());
9215}
9216
9218 ExpectedType ToTypeOrErr = import(E->getType());
9219 if (!ToTypeOrErr)
9220 return ToTypeOrErr.takeError();
9221
9222 auto ToSourceRangeOrErr = import(E->getSourceRange());
9223 if (!ToSourceRangeOrErr)
9224 return ToSourceRangeOrErr.takeError();
9225
9226 if (E->isTypeOperand()) {
9227 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9228 return new (Importer.getToContext()) CXXTypeidExpr(
9229 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9230 else
9231 return ToTSIOrErr.takeError();
9232 }
9233
9234 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9235 if (!ToExprOperandOrErr)
9236 return ToExprOperandOrErr.takeError();
9237
9238 return new (Importer.getToContext()) CXXTypeidExpr(
9239 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9240}
9241
9243 Error Err = Error::success();
9244
9245 QualType ToType = importChecked(Err, E->getType());
9246 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9247 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9248 Expr *ToLHS = importChecked(Err, E->getLHS());
9249 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9250 Expr *ToRHS = importChecked(Err, E->getRHS());
9251 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9252
9253 if (Err)
9254 return std::move(Err);
9255
9256 return new (Importer.getToContext())
9257 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9258 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9259}
9260
9262 Error Err = Error::success();
9263 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9264 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9265 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9266
9267 auto Body = importChecked(Err, E->getBody());
9268 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9269 if (Err)
9270 return std::move(Err);
9271 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9272 if (Error Err =
9273 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9274 return std::move(Err);
9276 E->getRequirements().size());
9277 if (Error Err =
9278 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9279 return std::move(Err);
9280 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9281 LParenLoc, LocalParameters, RParenLoc,
9282 Requirements, RBraceLoc);
9283}
9284
9287 Error Err = Error::success();
9288 auto CL = importChecked(Err, E->getConceptReference());
9289 auto CSD = importChecked(Err, E->getSpecializationDecl());
9290 if (Err)
9291 return std::move(Err);
9292 if (E->isValueDependent())
9294 Importer.getToContext(), CL,
9295 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9296 ConstraintSatisfaction Satisfaction;
9297 if (Error Err =
9299 return std::move(Err);
9301 Importer.getToContext(), CL,
9302 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9303}
9304
9307 Error Err = Error::success();
9308 auto ToType = importChecked(Err, E->getType());
9309 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9310 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9311 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9312 if (Err)
9313 return std::move(Err);
9314
9315 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9316 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9317 E->getIndex(), E->getFinal());
9318}
9319
9322 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9323 return std::move(Err);
9324 auto ToSyntOrErr = import(E->getSyntacticForm());
9325 if (!ToSyntOrErr)
9326 return ToSyntOrErr.takeError();
9327 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9328 ToSemantics, E->getResultExprIndex());
9329}
9330
9333 Error Err = Error::success();
9334 auto ToType = importChecked(Err, E->getType());
9335 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9336 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9337 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9338 if (Err)
9339 return std::move(Err);
9340
9341 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9342 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9343 return std::move(Err);
9344 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9345 E->getUserSpecifiedInitExprs().size(),
9346 ToInitLoc, ToBeginLoc, ToEndLoc);
9347}
9348
9350 CXXMethodDecl *FromMethod) {
9351 Error ImportErrors = Error::success();
9352 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9353 if (auto ImportedOrErr = import(FromOverriddenMethod))
9355 (*ImportedOrErr)->getCanonicalDecl()));
9356 else
9357 ImportErrors =
9358 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9359 }
9360 return ImportErrors;
9361}
9362
9364 ASTContext &FromContext, FileManager &FromFileManager,
9365 bool MinimalImport,
9366 std::shared_ptr<ASTImporterSharedState> SharedState)
9367 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9368 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9369 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9370
9371 // Create a default state without the lookup table: LLDB case.
9372 if (!SharedState) {
9373 this->SharedState = std::make_shared<ASTImporterSharedState>();
9374 }
9375
9376 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9377 ToContext.getTranslationUnitDecl();
9378}
9379
9380ASTImporter::~ASTImporter() = default;
9381
9383 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9384 "Try to get field index for non-field.");
9385
9386 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9387 if (!Owner)
9388 return std::nullopt;
9389
9390 unsigned Index = 0;
9391 for (const auto *D : Owner->decls()) {
9392 if (D == F)
9393 return Index;
9394
9396 ++Index;
9397 }
9398
9399 llvm_unreachable("Field was not found in its parent context.");
9400
9401 return std::nullopt;
9402}
9403
9404ASTImporter::FoundDeclsTy
9405ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9406 // We search in the redecl context because of transparent contexts.
9407 // E.g. a simple C language enum is a transparent context:
9408 // enum E { A, B };
9409 // Now if we had a global variable in the TU
9410 // int A;
9411 // then the enum constant 'A' and the variable 'A' violates ODR.
9412 // We can diagnose this only if we search in the redecl context.
9413 DeclContext *ReDC = DC->getRedeclContext();
9414 if (SharedState->getLookupTable()) {
9415 if (ReDC->isNamespace()) {
9416 // Namespaces can be reopened.
9417 // Lookup table does not handle this, we must search here in all linked
9418 // namespaces.
9419 FoundDeclsTy Result;
9420 SmallVector<Decl *, 2> NSChain =
9422 dyn_cast<NamespaceDecl>(ReDC));
9423 for (auto *D : NSChain) {
9425 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9426 Name);
9428 }
9429 return Result;
9430 } else {
9432 SharedState->getLookupTable()->lookup(ReDC, Name);
9433 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9434 }
9435 } else {
9436 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9437 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9438 // We must search by the slow case of localUncachedLookup because that is
9439 // working even if there is no LookupPtr for the DC. We could use
9440 // DC::buildLookup() to create the LookupPtr, but that would load external
9441 // decls again, we must avoid that case.
9442 // Also, even if we had the LookupPtr, we must find Decls which are not
9443 // in the LookupPtr, so we need the slow case.
9444 // These cases are handled in ASTImporterLookupTable, but we cannot use
9445 // that with LLDB since that traverses through the AST which initiates the
9446 // load of external decls again via DC::decls(). And again, we must avoid
9447 // loading external decls during the import.
9448 if (Result.empty())
9449 ReDC->localUncachedLookup(Name, Result);
9450 return Result;
9451 }
9452}
9453
9454void ASTImporter::AddToLookupTable(Decl *ToD) {
9455 SharedState->addDeclToLookup(ToD);
9456}
9457
9459 // Import the decl using ASTNodeImporter.
9460 ASTNodeImporter Importer(*this);
9461 return Importer.Visit(FromD);
9462}
9463
9465 MapImported(FromD, ToD);
9466}
9467
9470 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9471 if (Expected<Expr *> R = Import(CLE))
9473 }
9474
9475 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9476 // ASTNodeImporter.
9477 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9478}
9479
9481 if (!FromT)
9482 return FromT;
9483
9484 // Check whether we've already imported this type.
9485 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9486 ImportedTypes.find(FromT);
9487 if (Pos != ImportedTypes.end())
9488 return Pos->second;
9489
9490 // Import the type.
9491 ASTNodeImporter Importer(*this);
9492 ExpectedType ToTOrErr = Importer.Visit(FromT);
9493 if (!ToTOrErr)
9494 return ToTOrErr.takeError();
9495
9496 // Record the imported type.
9497 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9498
9499 return ToTOrErr->getTypePtr();
9500}
9501
9503 if (FromT.isNull())
9504 return QualType{};
9505
9506 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9507 if (!ToTyOrErr)
9508 return ToTyOrErr.takeError();
9509
9510 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9511}
9512
9514 if (!FromTSI)
9515 return FromTSI;
9516
9517 // FIXME: For now we just create a "trivial" type source info based
9518 // on the type and a single location. Implement a real version of this.
9519 ExpectedType TOrErr = Import(FromTSI->getType());
9520 if (!TOrErr)
9521 return TOrErr.takeError();
9522 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9523 if (!BeginLocOrErr)
9524 return BeginLocOrErr.takeError();
9525
9526 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9527}
9528
9529namespace {
9530// To use this object, it should be created before the new attribute is created,
9531// and destructed after it is created. The construction already performs the
9532// import of the data.
9533template <typename T> struct AttrArgImporter {
9534 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9535 AttrArgImporter(AttrArgImporter<T> &&) = default;
9536 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9537 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9538
9539 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9540 : To(I.importChecked(Err, From)) {}
9541
9542 const T &value() { return To; }
9543
9544private:
9545 T To;
9546};
9547
9548// To use this object, it should be created before the new attribute is created,
9549// and destructed after it is created. The construction already performs the
9550// import of the data. The array data is accessible in a pointer form, this form
9551// is used by the attribute classes. This object should be created once for the
9552// array data to be imported (the array size is not imported, just copied).
9553template <typename T> struct AttrArgArrayImporter {
9554 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9555 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9556 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9557 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9558
9559 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9560 const llvm::iterator_range<T *> &From,
9561 unsigned ArraySize) {
9562 if (Err)
9563 return;
9564 To.reserve(ArraySize);
9565 Err = I.ImportContainerChecked(From, To);
9566 }
9567
9568 T *value() { return To.data(); }
9569
9570private:
9571 llvm::SmallVector<T, 2> To;
9572};
9573
9574class AttrImporter {
9575 Error Err{Error::success()};
9576 Attr *ToAttr = nullptr;
9577 ASTImporter &Importer;
9578 ASTNodeImporter NImporter;
9579
9580public:
9581 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9582
9583 // Useful for accessing the imported attribute.
9584 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9585 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9586
9587 // Create an "importer" for an attribute parameter.
9588 // Result of the 'value()' of that object is to be passed to the function
9589 // 'importAttr', in the order that is expected by the attribute class.
9590 template <class T> AttrArgImporter<T> importArg(const T &From) {
9591 return AttrArgImporter<T>(NImporter, Err, From);
9592 }
9593
9594 // Create an "importer" for an attribute parameter that has array type.
9595 // Result of the 'value()' of that object is to be passed to the function
9596 // 'importAttr', then the size of the array as next argument.
9597 template <typename T>
9598 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9599 unsigned ArraySize) {
9600 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9601 }
9602
9603 // Create an attribute object with the specified arguments.
9604 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9605 // should be values that are passed to the 'Create' function of the attribute.
9606 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9607 // used here.) As much data is copied or imported from the old attribute
9608 // as possible. The passed arguments should be already imported.
9609 // If an import error happens, the internal error is set to it, and any
9610 // further import attempt is ignored.
9611 template <typename T, typename... Arg>
9612 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9613 static_assert(std::is_base_of<Attr, T>::value,
9614 "T should be subclass of Attr.");
9615 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9616
9617 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9618 const IdentifierInfo *ToScopeName =
9619 Importer.Import(FromAttr->getScopeName());
9620 SourceRange ToAttrRange =
9621 NImporter.importChecked(Err, FromAttr->getRange());
9622 SourceLocation ToScopeLoc =
9623 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9624
9625 if (Err)
9626 return;
9627
9628 AttributeCommonInfo ToI(
9629 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9630 FromAttr->getParsedKind(), FromAttr->getForm());
9631 // The "SemanticSpelling" is not needed to be passed to the constructor.
9632 // That value is recalculated from the SpellingListIndex if needed.
9633 ToAttr = T::Create(Importer.getToContext(),
9634 std::forward<Arg>(ImportedArg)..., ToI);
9635
9636 ToAttr->setImplicit(FromAttr->isImplicit());
9637 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9638 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9639 ToInheritableAttr->setInherited(FromAttr->isInherited());
9640 }
9641
9642 // Create a clone of the 'FromAttr' and import its source range only.
9643 // This causes objects with invalid references to be created if the 'FromAttr'
9644 // contains other data that should be imported.
9645 void cloneAttr(const Attr *FromAttr) {
9646 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9647
9648 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9649 if (Err)
9650 return;
9651
9652 ToAttr = FromAttr->clone(Importer.getToContext());
9653 ToAttr->setRange(ToRange);
9654 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9655 }
9656
9657 // Get the result of the previous import attempt (can be used only once).
9658 llvm::Expected<Attr *> getResult() && {
9659 if (Err)
9660 return std::move(Err);
9661 assert(ToAttr && "Attribute should be created.");
9662 return ToAttr;
9663 }
9664};
9665} // namespace
9666
9668 AttrImporter AI(*this);
9669
9670 // FIXME: Is there some kind of AttrVisitor to use here?
9671 switch (FromAttr->getKind()) {
9672 case attr::Aligned: {
9673 auto *From = cast<AlignedAttr>(FromAttr);
9674 if (From->isAlignmentExpr())
9675 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9676 else
9677 AI.importAttr(From, false,
9678 AI.importArg(From->getAlignmentType()).value());
9679 break;
9680 }
9681
9682 case attr::AlignValue: {
9683 auto *From = cast<AlignValueAttr>(FromAttr);
9684 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9685 break;
9686 }
9687
9688 case attr::Format: {
9689 const auto *From = cast<FormatAttr>(FromAttr);
9690 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9691 From->getFirstArg());
9692 break;
9693 }
9694
9695 case attr::EnableIf: {
9696 const auto *From = cast<EnableIfAttr>(FromAttr);
9697 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9698 From->getMessage());
9699 break;
9700 }
9701
9702 case attr::AssertCapability: {
9703 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9704 AI.importAttr(From,
9705 AI.importArrayArg(From->args(), From->args_size()).value(),
9706 From->args_size());
9707 break;
9708 }
9709 case attr::AcquireCapability: {
9710 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9711 AI.importAttr(From,
9712 AI.importArrayArg(From->args(), From->args_size()).value(),
9713 From->args_size());
9714 break;
9715 }
9716 case attr::TryAcquireCapability: {
9717 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9718 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9719 AI.importArrayArg(From->args(), From->args_size()).value(),
9720 From->args_size());
9721 break;
9722 }
9723 case attr::ReleaseCapability: {
9724 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9725 AI.importAttr(From,
9726 AI.importArrayArg(From->args(), From->args_size()).value(),
9727 From->args_size());
9728 break;
9729 }
9730 case attr::RequiresCapability: {
9731 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9732 AI.importAttr(From,
9733 AI.importArrayArg(From->args(), From->args_size()).value(),
9734 From->args_size());
9735 break;
9736 }
9737 case attr::GuardedBy: {
9738 const auto *From = cast<GuardedByAttr>(FromAttr);
9739 AI.importAttr(From, AI.importArg(From->getArg()).value());
9740 break;
9741 }
9742 case attr::PtGuardedBy: {
9743 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9744 AI.importAttr(From, AI.importArg(From->getArg()).value());
9745 break;
9746 }
9747 case attr::AcquiredAfter: {
9748 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9749 AI.importAttr(From,
9750 AI.importArrayArg(From->args(), From->args_size()).value(),
9751 From->args_size());
9752 break;
9753 }
9754 case attr::AcquiredBefore: {
9755 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9756 AI.importAttr(From,
9757 AI.importArrayArg(From->args(), From->args_size()).value(),
9758 From->args_size());
9759 break;
9760 }
9761 case attr::LockReturned: {
9762 const auto *From = cast<LockReturnedAttr>(FromAttr);
9763 AI.importAttr(From, AI.importArg(From->getArg()).value());
9764 break;
9765 }
9766 case attr::LocksExcluded: {
9767 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9768 AI.importAttr(From,
9769 AI.importArrayArg(From->args(), From->args_size()).value(),
9770 From->args_size());
9771 break;
9772 }
9773 default: {
9774 // The default branch works for attributes that have no arguments to import.
9775 // FIXME: Handle every attribute type that has arguments of type to import
9776 // (most often Expr* or Decl* or type) in the switch above.
9777 AI.cloneAttr(FromAttr);
9778 break;
9779 }
9780 }
9781
9782 return std::move(AI).getResult();
9783}
9784
9786 return ImportedDecls.lookup(FromD);
9787}
9788
9790 auto FromDPos = ImportedFromDecls.find(ToD);
9791 if (FromDPos == ImportedFromDecls.end())
9792 return nullptr;
9793 return FromDPos->second->getTranslationUnitDecl();
9794}
9795
9797 if (!FromD)
9798 return nullptr;
9799
9800 // Push FromD to the stack, and remove that when we return.
9801 ImportPath.push(FromD);
9802 auto ImportPathBuilder =
9803 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9804
9805 // Check whether there was a previous failed import.
9806 // If yes return the existing error.
9807 if (auto Error = getImportDeclErrorIfAny(FromD))
9808 return make_error<ASTImportError>(*Error);
9809
9810 // Check whether we've already imported this declaration.
9811 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9812 if (ToD) {
9813 // Already imported (possibly from another TU) and with an error.
9814 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9815 setImportDeclError(FromD, *Error);
9816 return make_error<ASTImportError>(*Error);
9817 }
9818
9819 // If FromD has some updated flags after last import, apply it.
9820 updateFlags(FromD, ToD);
9821 // If we encounter a cycle during an import then we save the relevant part
9822 // of the import path associated to the Decl.
9823 if (ImportPath.hasCycleAtBack())
9824 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9825 return ToD;
9826 }
9827
9828 // Import the declaration.
9829 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9830 if (!ToDOrErr) {
9831 // Failed to import.
9832
9833 auto Pos = ImportedDecls.find(FromD);
9834 if (Pos != ImportedDecls.end()) {
9835 // Import failed after the object was created.
9836 // Remove all references to it.
9837 auto *ToD = Pos->second;
9838 ImportedDecls.erase(Pos);
9839
9840 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9841 // (e.g. with namespaces) that several decls from the 'from' context are
9842 // mapped to the same decl in the 'to' context. If we removed entries
9843 // from the LookupTable here then we may end up removing them multiple
9844 // times.
9845
9846 // The Lookuptable contains decls only which are in the 'to' context.
9847 // Remove from the Lookuptable only if it is *imported* into the 'to'
9848 // context (and do not remove it if it was added during the initial
9849 // traverse of the 'to' context).
9850 auto PosF = ImportedFromDecls.find(ToD);
9851 if (PosF != ImportedFromDecls.end()) {
9852 // In the case of TypedefNameDecl we create the Decl first and only
9853 // then we import and set its DeclContext. So, the DC might not be set
9854 // when we reach here.
9855 if (ToD->getDeclContext())
9856 SharedState->removeDeclFromLookup(ToD);
9857 ImportedFromDecls.erase(PosF);
9858 }
9859
9860 // FIXME: AST may contain remaining references to the failed object.
9861 // However, the ImportDeclErrors in the shared state contains all the
9862 // failed objects together with their error.
9863 }
9864
9865 // Error encountered for the first time.
9866 // After takeError the error is not usable any more in ToDOrErr.
9867 // Get a copy of the error object (any more simple solution for this?).
9868 ASTImportError ErrOut;
9869 handleAllErrors(ToDOrErr.takeError(),
9870 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9871 setImportDeclError(FromD, ErrOut);
9872 // Set the error for the mapped to Decl, which is in the "to" context.
9873 if (Pos != ImportedDecls.end())
9874 SharedState->setImportDeclError(Pos->second, ErrOut);
9875
9876 // Set the error for all nodes which have been created before we
9877 // recognized the error.
9878 for (const auto &Path : SavedImportPaths[FromD]) {
9879 // The import path contains import-dependency nodes first.
9880 // Save the node that was imported as dependency of the current node.
9881 Decl *PrevFromDi = FromD;
9882 for (Decl *FromDi : Path) {
9883 // Begin and end of the path equals 'FromD', skip it.
9884 if (FromDi == FromD)
9885 continue;
9886 // We should not set import error on a node and all following nodes in
9887 // the path if child import errors are ignored.
9888 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9889 PrevFromDi))
9890 break;
9891 PrevFromDi = FromDi;
9892 setImportDeclError(FromDi, ErrOut);
9893 //FIXME Should we remove these Decls from ImportedDecls?
9894 // Set the error for the mapped to Decl, which is in the "to" context.
9895 auto Ii = ImportedDecls.find(FromDi);
9896 if (Ii != ImportedDecls.end())
9897 SharedState->setImportDeclError(Ii->second, ErrOut);
9898 // FIXME Should we remove these Decls from the LookupTable,
9899 // and from ImportedFromDecls?
9900 }
9901 }
9902 SavedImportPaths.erase(FromD);
9903
9904 // Do not return ToDOrErr, error was taken out of it.
9905 return make_error<ASTImportError>(ErrOut);
9906 }
9907
9908 ToD = *ToDOrErr;
9909
9910 // FIXME: Handle the "already imported with error" case. We can get here
9911 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9912 // previously failed create was requested).
9913 // Later GetImportedOrCreateDecl can be updated to return the error.
9914 if (!ToD) {
9915 auto Err = getImportDeclErrorIfAny(FromD);
9916 assert(Err);
9917 return make_error<ASTImportError>(*Err);
9918 }
9919
9920 // We could import from the current TU without error. But previously we
9921 // already had imported a Decl as `ToD` from another TU (with another
9922 // ASTImporter object) and with an error.
9923 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9924 setImportDeclError(FromD, *Error);
9925 return make_error<ASTImportError>(*Error);
9926 }
9927 // Make sure that ImportImpl registered the imported decl.
9928 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9929
9930 if (FromD->hasAttrs())
9931 for (const Attr *FromAttr : FromD->getAttrs()) {
9932 auto ToAttrOrErr = Import(FromAttr);
9933 if (ToAttrOrErr)
9934 ToD->addAttr(*ToAttrOrErr);
9935 else
9936 return ToAttrOrErr.takeError();
9937 }
9938
9939 // Notify subclasses.
9940 Imported(FromD, ToD);
9941
9942 updateFlags(FromD, ToD);
9943 SavedImportPaths.erase(FromD);
9944 return ToDOrErr;
9945}
9946
9949 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9950}
9951
9953 if (!FromDC)
9954 return FromDC;
9955
9956 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9957 if (!ToDCOrErr)
9958 return ToDCOrErr.takeError();
9959 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9960
9961 // When we're using a record/enum/Objective-C class/protocol as a context, we
9962 // need it to have a definition.
9963 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9964 auto *FromRecord = cast<RecordDecl>(FromDC);
9965 if (ToRecord->isCompleteDefinition())
9966 return ToDC;
9967
9968 // If FromRecord is not defined we need to force it to be.
9969 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9970 // it will start the definition but we never finish it.
9971 // If there are base classes they won't be imported and we will
9972 // be missing anything that we inherit from those bases.
9973 if (FromRecord->getASTContext().getExternalSource() &&
9974 !FromRecord->isCompleteDefinition())
9975 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9976
9977 if (FromRecord->isCompleteDefinition())
9978 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9979 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9980 return std::move(Err);
9981 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9982 auto *FromEnum = cast<EnumDecl>(FromDC);
9983 if (ToEnum->isCompleteDefinition()) {
9984 // Do nothing.
9985 } else if (FromEnum->isCompleteDefinition()) {
9986 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9987 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9988 return std::move(Err);
9989 } else {
9990 CompleteDecl(ToEnum);
9991 }
9992 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9993 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9994 if (ToClass->getDefinition()) {
9995 // Do nothing.
9996 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9997 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9998 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9999 return std::move(Err);
10000 } else {
10001 CompleteDecl(ToClass);
10002 }
10003 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10004 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10005 if (ToProto->getDefinition()) {
10006 // Do nothing.
10007 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10008 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10009 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10010 return std::move(Err);
10011 } else {
10012 CompleteDecl(ToProto);
10013 }
10014 }
10015
10016 return ToDC;
10017}
10018
10020 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10021 return cast_or_null<Expr>(*ToSOrErr);
10022 else
10023 return ToSOrErr.takeError();
10024}
10025
10027 if (!FromS)
10028 return nullptr;
10029
10030 // Check whether we've already imported this statement.
10031 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10032 if (Pos != ImportedStmts.end())
10033 return Pos->second;
10034
10035 // Import the statement.
10036 ASTNodeImporter Importer(*this);
10037 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10038 if (!ToSOrErr)
10039 return ToSOrErr;
10040
10041 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10042 auto *FromE = cast<Expr>(FromS);
10043 // Copy ExprBitfields, which may not be handled in Expr subclasses
10044 // constructors.
10045 ToE->setValueKind(FromE->getValueKind());
10046 ToE->setObjectKind(FromE->getObjectKind());
10047 ToE->setDependence(FromE->getDependence());
10048 }
10049
10050 // Record the imported statement object.
10051 ImportedStmts[FromS] = *ToSOrErr;
10052 return ToSOrErr;
10053}
10054
10056 switch (FromNNS.getKind()) {
10059 return FromNNS;
10061 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10062 auto NSOrErr = Import(Namespace);
10063 if (!NSOrErr)
10064 return NSOrErr.takeError();
10065 auto PrefixOrErr = Import(Prefix);
10066 if (!PrefixOrErr)
10067 return PrefixOrErr.takeError();
10068 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10069 *PrefixOrErr);
10070 }
10072 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10073 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10074 else
10075 return RDOrErr.takeError();
10077 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10078 return NestedNameSpecifier(*TyOrErr);
10079 } else {
10080 return TyOrErr.takeError();
10081 }
10082 }
10083 llvm_unreachable("Invalid nested name specifier kind");
10084}
10085
10088 // Copied from NestedNameSpecifier mostly.
10090 NestedNameSpecifierLoc NNS = FromNNS;
10091
10092 // Push each of the nested-name-specifiers's onto a stack for
10093 // serialization in reverse order.
10094 while (NNS) {
10095 NestedNames.push_back(NNS);
10096 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10097 }
10098
10100
10101 while (!NestedNames.empty()) {
10102 NNS = NestedNames.pop_back_val();
10103 NestedNameSpecifier Spec = std::nullopt;
10104 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10105 return std::move(Err);
10106
10107 NestedNameSpecifier::Kind Kind = Spec.getKind();
10108
10109 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10111 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10112 return std::move(Err);
10113
10115 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10116 return std::move(Err);
10117 }
10118
10119 switch (Kind) {
10121 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10122 ToLocalBeginLoc, ToLocalEndLoc);
10123 break;
10124
10126 SourceLocation ToTLoc;
10127 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10128 return std::move(Err);
10130 QualType(Spec.getAsType(), 0), ToTLoc);
10131 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10132 break;
10133 }
10134
10136 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10137 break;
10138
10140 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10141 if (!ToSourceRangeOrErr)
10142 return ToSourceRangeOrErr.takeError();
10143
10144 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10145 ToSourceRangeOrErr->getBegin(),
10146 ToSourceRangeOrErr->getEnd());
10147 break;
10148 }
10150 llvm_unreachable("unexpected null nested name specifier");
10151 }
10152 }
10153
10154 return Builder.getWithLocInContext(getToContext());
10155}
10156
10158 switch (From.getKind()) {
10160 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10161 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10162 else
10163 return ToTemplateOrErr.takeError();
10164
10167 UnresolvedSet<2> ToTemplates;
10168 for (auto *I : *FromStorage) {
10169 if (auto ToOrErr = Import(I))
10170 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10171 else
10172 return ToOrErr.takeError();
10173 }
10174 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10175 ToTemplates.end());
10176 }
10177
10180 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10181 if (!DeclNameOrErr)
10182 return DeclNameOrErr.takeError();
10183 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10184 }
10185
10188 auto QualifierOrErr = Import(QTN->getQualifier());
10189 if (!QualifierOrErr)
10190 return QualifierOrErr.takeError();
10191 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10192 if (!TNOrErr)
10193 return TNOrErr.takeError();
10194 return ToContext.getQualifiedTemplateName(
10195 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10196 }
10197
10200 auto QualifierOrErr = Import(DTN->getQualifier());
10201 if (!QualifierOrErr)
10202 return QualifierOrErr.takeError();
10203 return ToContext.getDependentTemplateName(
10204 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10205 }
10206
10210 auto ReplacementOrErr = Import(Subst->getReplacement());
10211 if (!ReplacementOrErr)
10212 return ReplacementOrErr.takeError();
10213
10214 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10215 if (!AssociatedDeclOrErr)
10216 return AssociatedDeclOrErr.takeError();
10217
10218 return ToContext.getSubstTemplateTemplateParm(
10219 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10220 Subst->getPackIndex(), Subst->getFinal());
10221 }
10222
10226 ASTNodeImporter Importer(*this);
10227 auto ArgPackOrErr =
10228 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10229 if (!ArgPackOrErr)
10230 return ArgPackOrErr.takeError();
10231
10232 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10233 if (!AssociatedDeclOrErr)
10234 return AssociatedDeclOrErr.takeError();
10235
10236 return ToContext.getSubstTemplateTemplateParmPack(
10237 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10238 SubstPack->getFinal());
10239 }
10241 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10242 if (!UsingOrError)
10243 return UsingOrError.takeError();
10244 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10245 }
10247 llvm_unreachable("Unexpected DeducedTemplate");
10248 }
10249
10250 llvm_unreachable("Invalid template name kind");
10251}
10252
10254 if (FromLoc.isInvalid())
10255 return SourceLocation{};
10256
10257 SourceManager &FromSM = FromContext.getSourceManager();
10258 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10259
10260 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10261 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10262 if (!ToFileIDOrErr)
10263 return ToFileIDOrErr.takeError();
10264 SourceManager &ToSM = ToContext.getSourceManager();
10265 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10266}
10267
10269 SourceLocation ToBegin, ToEnd;
10270 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10271 return std::move(Err);
10272 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10273 return std::move(Err);
10274
10275 return SourceRange(ToBegin, ToEnd);
10276}
10277
10279 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10280 if (Pos != ImportedFileIDs.end())
10281 return Pos->second;
10282
10283 SourceManager &FromSM = FromContext.getSourceManager();
10284 SourceManager &ToSM = ToContext.getSourceManager();
10285 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10286
10287 // Map the FromID to the "to" source manager.
10288 FileID ToID;
10289 if (FromSLoc.isExpansion()) {
10290 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10291 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10292 if (!ToSpLoc)
10293 return ToSpLoc.takeError();
10294 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10295 if (!ToExLocS)
10296 return ToExLocS.takeError();
10297 unsigned ExLength = FromSM.getFileIDSize(FromID);
10298 SourceLocation MLoc;
10299 if (FromEx.isMacroArgExpansion()) {
10300 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10301 } else {
10302 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10303 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10304 FromEx.isExpansionTokenRange());
10305 else
10306 return ToExLocE.takeError();
10307 }
10308 ToID = ToSM.getFileID(MLoc);
10309 } else {
10310 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10311
10312 if (!IsBuiltin && !Cache->BufferOverridden) {
10313 // Include location of this file.
10314 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10315 if (!ToIncludeLoc)
10316 return ToIncludeLoc.takeError();
10317
10318 // Every FileID that is not the main FileID needs to have a valid include
10319 // location so that the include chain points to the main FileID. When
10320 // importing the main FileID (which has no include location), we need to
10321 // create a fake include location in the main file to keep this property
10322 // intact.
10323 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10324 if (FromID == FromSM.getMainFileID())
10325 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10326
10327 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10328 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10329 // the disk again
10330 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10331 // than mmap the files several times.
10332 auto Entry =
10333 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10334 // FIXME: The filename may be a virtual name that does probably not
10335 // point to a valid file and we get no Entry here. In this case try with
10336 // the memory buffer below.
10337 if (Entry)
10338 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10339 FromSLoc.getFile().getFileCharacteristic());
10340 }
10341 }
10342
10343 if (ToID.isInvalid() || IsBuiltin) {
10344 // FIXME: We want to re-use the existing MemoryBuffer!
10345 std::optional<llvm::MemoryBufferRef> FromBuf =
10346 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10347 FromSM.getFileManager(), SourceLocation{});
10348 if (!FromBuf)
10349 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10350
10351 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10352 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10353 FromBuf->getBufferIdentifier());
10354 ToID = ToSM.createFileID(std::move(ToBuf),
10355 FromSLoc.getFile().getFileCharacteristic());
10356 }
10357 }
10358
10359 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10360
10361 ImportedFileIDs[FromID] = ToID;
10362 return ToID;
10363}
10364
10366 ExpectedExpr ToExprOrErr = Import(From->getInit());
10367 if (!ToExprOrErr)
10368 return ToExprOrErr.takeError();
10369
10370 auto LParenLocOrErr = Import(From->getLParenLoc());
10371 if (!LParenLocOrErr)
10372 return LParenLocOrErr.takeError();
10373
10374 auto RParenLocOrErr = Import(From->getRParenLoc());
10375 if (!RParenLocOrErr)
10376 return RParenLocOrErr.takeError();
10377
10378 if (From->isBaseInitializer()) {
10379 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10380 if (!ToTInfoOrErr)
10381 return ToTInfoOrErr.takeError();
10382
10383 SourceLocation EllipsisLoc;
10384 if (From->isPackExpansion())
10385 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10386 return std::move(Err);
10387
10388 return new (ToContext) CXXCtorInitializer(
10389 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10390 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10391 } else if (From->isMemberInitializer()) {
10392 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10393 if (!ToFieldOrErr)
10394 return ToFieldOrErr.takeError();
10395
10396 auto MemberLocOrErr = Import(From->getMemberLocation());
10397 if (!MemberLocOrErr)
10398 return MemberLocOrErr.takeError();
10399
10400 return new (ToContext) CXXCtorInitializer(
10401 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10402 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10403 } else if (From->isIndirectMemberInitializer()) {
10404 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10405 if (!ToIFieldOrErr)
10406 return ToIFieldOrErr.takeError();
10407
10408 auto MemberLocOrErr = Import(From->getMemberLocation());
10409 if (!MemberLocOrErr)
10410 return MemberLocOrErr.takeError();
10411
10412 return new (ToContext) CXXCtorInitializer(
10413 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10414 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10415 } else if (From->isDelegatingInitializer()) {
10416 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10417 if (!ToTInfoOrErr)
10418 return ToTInfoOrErr.takeError();
10419
10420 return new (ToContext)
10421 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10422 *ToExprOrErr, *RParenLocOrErr);
10423 } else {
10424 // FIXME: assert?
10425 return make_error<ASTImportError>();
10426 }
10427}
10428
10431 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10432 if (Pos != ImportedCXXBaseSpecifiers.end())
10433 return Pos->second;
10434
10435 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10436 if (!ToSourceRange)
10437 return ToSourceRange.takeError();
10439 if (!ToTSI)
10440 return ToTSI.takeError();
10441 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10442 if (!ToEllipsisLoc)
10443 return ToEllipsisLoc.takeError();
10444 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10445 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10446 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10447 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10448 return Imported;
10449}
10450
10452 ASTNodeImporter Importer(*this);
10453 return Importer.ImportAPValue(FromValue);
10454}
10455
10457 ExpectedDecl ToOrErr = Import(From);
10458 if (!ToOrErr)
10459 return ToOrErr.takeError();
10460 Decl *To = *ToOrErr;
10461
10462 auto *FromDC = cast<DeclContext>(From);
10463 ASTNodeImporter Importer(*this);
10464
10465 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10466 if (!ToRecord->getDefinition()) {
10467 return Importer.ImportDefinition(
10468 cast<RecordDecl>(FromDC), ToRecord,
10470 }
10471 }
10472
10473 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10474 if (!ToEnum->getDefinition()) {
10475 return Importer.ImportDefinition(
10477 }
10478 }
10479
10480 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10481 if (!ToIFace->getDefinition()) {
10482 return Importer.ImportDefinition(
10483 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10485 }
10486 }
10487
10488 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10489 if (!ToProto->getDefinition()) {
10490 return Importer.ImportDefinition(
10491 cast<ObjCProtocolDecl>(FromDC), ToProto,
10493 }
10494 }
10495
10496 return Importer.ImportDeclContext(FromDC, true);
10497}
10498
10500 if (!FromName)
10501 return DeclarationName{};
10502
10503 switch (FromName.getNameKind()) {
10505 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10506
10510 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10511 return DeclarationName(*ToSelOrErr);
10512 else
10513 return ToSelOrErr.takeError();
10514
10516 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10517 return ToContext.DeclarationNames.getCXXConstructorName(
10518 ToContext.getCanonicalType(*ToTyOrErr));
10519 else
10520 return ToTyOrErr.takeError();
10521 }
10522
10524 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10525 return ToContext.DeclarationNames.getCXXDestructorName(
10526 ToContext.getCanonicalType(*ToTyOrErr));
10527 else
10528 return ToTyOrErr.takeError();
10529 }
10530
10532 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10533 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10534 cast<TemplateDecl>(*ToTemplateOrErr));
10535 else
10536 return ToTemplateOrErr.takeError();
10537 }
10538
10540 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10541 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10542 ToContext.getCanonicalType(*ToTyOrErr));
10543 else
10544 return ToTyOrErr.takeError();
10545 }
10546
10548 return ToContext.DeclarationNames.getCXXOperatorName(
10549 FromName.getCXXOverloadedOperator());
10550
10552 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10553 Import(FromName.getCXXLiteralIdentifier()));
10554
10556 // FIXME: STATICS!
10558 }
10559
10560 llvm_unreachable("Invalid DeclarationName Kind!");
10561}
10562
10564 if (!FromId)
10565 return nullptr;
10566
10567 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10568
10569 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10570 ToId->setBuiltinID(FromId->getBuiltinID());
10571
10572 return ToId;
10573}
10574
10577 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10578 return Import(FromII);
10579 return FromIO.getOperator();
10580}
10581
10583 if (FromSel.isNull())
10584 return Selector{};
10585
10587 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10588 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10589 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10590 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10591}
10592
10596 llvm::Error Err = llvm::Error::success();
10597 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10598 for (unsigned Idx = 0; Idx < Size; Idx++) {
10599 APValue Tmp = importChecked(Err, From[Idx]);
10600 To[Idx] = Tmp;
10601 }
10602 };
10603 switch (FromValue.getKind()) {
10604 case APValue::None:
10606 case APValue::Int:
10607 case APValue::Float:
10611 Result = FromValue;
10612 break;
10613 case APValue::Vector: {
10614 Result.MakeVector();
10616 Result.setVectorUninit(FromValue.getVectorLength());
10617 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10618 Elts.data(), FromValue.getVectorLength());
10619 break;
10620 }
10621 case APValue::Array:
10622 Result.MakeArray(FromValue.getArrayInitializedElts(),
10623 FromValue.getArraySize());
10624 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10625 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10626 FromValue.getArrayInitializedElts());
10627 break;
10628 case APValue::Struct:
10629 Result.MakeStruct(FromValue.getStructNumBases(),
10630 FromValue.getStructNumFields());
10631 ImportLoop(
10632 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10633 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10634 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10635 break;
10636 case APValue::Union: {
10637 Result.MakeUnion();
10638 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10639 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10640 if (Err)
10641 return std::move(Err);
10642 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10643 break;
10644 }
10646 Result.MakeAddrLabelDiff();
10647 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10648 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10649 if (Err)
10650 return std::move(Err);
10651 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10652 cast<AddrLabelExpr>(ImpRHS));
10653 break;
10654 }
10656 const Decl *ImpMemPtrDecl =
10657 importChecked(Err, FromValue.getMemberPointerDecl());
10658 if (Err)
10659 return std::move(Err);
10661 Result.setMemberPointerUninit(
10662 cast<const ValueDecl>(ImpMemPtrDecl),
10664 FromValue.getMemberPointerPath().size());
10665 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10666 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10667 Idx++) {
10668 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10669 if (Err)
10670 return std::move(Err);
10671 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10672 }
10673 break;
10674 }
10675 case APValue::LValue:
10677 QualType FromElemTy;
10678 if (FromValue.getLValueBase()) {
10679 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10680 "in C++20 dynamic allocation are transient so they shouldn't "
10681 "appear in the AST");
10682 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10683 if (const auto *E =
10684 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10685 FromElemTy = E->getType();
10686 const Expr *ImpExpr = importChecked(Err, E);
10687 if (Err)
10688 return std::move(Err);
10689 Base = APValue::LValueBase(ImpExpr,
10690 FromValue.getLValueBase().getCallIndex(),
10691 FromValue.getLValueBase().getVersion());
10692 } else {
10693 FromElemTy =
10694 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10695 const Decl *ImpDecl = importChecked(
10696 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10697 if (Err)
10698 return std::move(Err);
10700 FromValue.getLValueBase().getCallIndex(),
10701 FromValue.getLValueBase().getVersion());
10702 }
10703 } else {
10704 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10705 const Type *ImpTypeInfo = importChecked(
10706 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10707 QualType ImpType =
10708 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10709 if (Err)
10710 return std::move(Err);
10712 ImpType);
10713 }
10714 }
10715 CharUnits Offset = FromValue.getLValueOffset();
10716 unsigned PathLength = FromValue.getLValuePath().size();
10717 Result.MakeLValue();
10718 if (FromValue.hasLValuePath()) {
10719 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10720 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10721 FromValue.isNullPointer());
10723 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10724 if (FromElemTy->isRecordType()) {
10725 const Decl *FromDecl =
10726 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10727 const Decl *ImpDecl = importChecked(Err, FromDecl);
10728 if (Err)
10729 return std::move(Err);
10730 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10731 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10732 else
10733 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10735 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10736 } else {
10737 FromElemTy =
10738 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10739 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10740 FromPath[LoopIdx].getAsArrayIndex());
10741 }
10742 }
10743 } else
10744 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10745 FromValue.isNullPointer());
10746 }
10747 if (Err)
10748 return std::move(Err);
10749 return Result;
10750}
10751
10753 DeclContext *DC,
10754 unsigned IDNS,
10755 NamedDecl **Decls,
10756 unsigned NumDecls) {
10757 if (ODRHandling == ODRHandlingType::Conservative)
10758 // Report error at any name conflict.
10759 return make_error<ASTImportError>(ASTImportError::NameConflict);
10760 else
10761 // Allow to create the new Decl with the same name.
10762 return Name;
10763}
10764
10766 if (LastDiagFromFrom)
10767 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10768 FromContext.getDiagnostics());
10769 LastDiagFromFrom = false;
10770 return ToContext.getDiagnostics().Report(Loc, DiagID);
10771}
10772
10774 if (!LastDiagFromFrom)
10775 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10776 ToContext.getDiagnostics());
10777 LastDiagFromFrom = true;
10778 return FromContext.getDiagnostics().Report(Loc, DiagID);
10779}
10780
10782 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10783 if (!ID->getDefinition())
10784 ID->startDefinition();
10785 }
10786 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10787 if (!PD->getDefinition())
10788 PD->startDefinition();
10789 }
10790 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10791 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10792 TD->startDefinition();
10793 TD->setCompleteDefinition(true);
10794 }
10795 }
10796 else {
10797 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10798 }
10799}
10800
10802 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10803 assert((Inserted || Pos->second == To) &&
10804 "Try to import an already imported Decl");
10805 if (!Inserted)
10806 return Pos->second;
10807 // This mapping should be maintained only in this function. Therefore do not
10808 // check for additional consistency.
10809 ImportedFromDecls[To] = From;
10810 // In the case of TypedefNameDecl we create the Decl first and only then we
10811 // import and set its DeclContext. So, the DC is still not set when we reach
10812 // here from GetImportedOrCreateDecl.
10813 if (To->getDeclContext())
10814 AddToLookupTable(To);
10815 return To;
10816}
10817
10818std::optional<ASTImportError>
10820 auto Pos = ImportDeclErrors.find(FromD);
10821 if (Pos != ImportDeclErrors.end())
10822 return Pos->second;
10823 else
10824 return std::nullopt;
10825}
10826
10828 auto InsertRes = ImportDeclErrors.insert({From, Error});
10829 (void)InsertRes;
10830 // Either we set the error for the first time, or we already had set one and
10831 // now we want to set the same error.
10832 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10833}
10834
10836 bool Complain) {
10837 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10838 ImportedTypes.find(From.getTypePtr());
10839 if (Pos != ImportedTypes.end()) {
10840 if (ExpectedType ToFromOrErr = Import(From)) {
10841 if (ToContext.hasSameType(*ToFromOrErr, To))
10842 return true;
10843 } else {
10844 llvm::consumeError(ToFromOrErr.takeError());
10845 }
10846 }
10847
10849 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10850 getStructuralEquivalenceKind(*this), false, Complain);
10851 return Ctx.IsEquivalent(From, To);
10852}
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:220
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
Definition ASTContext.h:930
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:4315
SourceLocation getQuestionLoc() const
Definition Expr.h:4314
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:4484
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4499
SourceLocation getLabelLoc() const
Definition Expr.h:4501
LabelDecl * getLabel() const
Definition Expr.h:4507
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:5955
Represents a loop initializing the elements of an array.
Definition Expr.h:5902
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5917
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5922
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
SourceLocation getRBracketLoc() const
Definition Expr.h:2769
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2750
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:2996
uint64_t getValue() const
Definition ExprCXX.h:3044
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3034
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3036
Expr * getDimensionExpression() const
Definition ExprCXX.h:3046
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3042
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3033
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3722
bool isVolatile() const
Definition Stmt.h:3251
outputs_range outputs()
Definition Stmt.h:3348
SourceLocation getAsmLoc() const
Definition Stmt.h:3245
inputs_range inputs()
Definition Stmt.h:3319
unsigned getNumClobbers() const
Definition Stmt.h:3296
unsigned getNumOutputs() const
Definition Stmt.h:3264
unsigned getNumInputs() const
Definition Stmt.h:3286
bool isSimple() const
Definition Stmt.h:3248
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:6814
Expr ** getSubExprs()
Definition Expr.h:6889
SourceLocation getRParenLoc() const
Definition Expr.h:6943
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5152
AtomicOp getOp() const
Definition Expr.h:6877
SourceLocation getBuiltinLoc() const
Definition Expr.h:6942
Attr - This represents one attribute.
Definition Attr.h:45
attr::Kind getKind() const
Definition Attr.h:91
void setPackExpansion(bool PE)
Definition Attr.h:107
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition Attr.h:105
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition Stmt.h:2182
Stmt * getSubStmt()
Definition Stmt.h:2218
SourceLocation getAttrLoc() const
Definition Stmt.h:2213
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2214
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition Stmt.cpp:436
Represents a C++ declaration that introduces decls from somewhere else.
Definition DeclCXX.h:3496
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3403
shadow_range shadows() const
Definition DeclCXX.h:3562
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4387
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4441
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4425
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4429
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4434
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4422
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
Expr * getLHS() const
Definition Expr.h:4022
SourceLocation getOperatorLoc() const
Definition Expr.h:4014
Expr * getRHS() const
Definition Expr.h:4024
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:4978
Opcode getOpcode() const
Definition Expr.h:4017
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4192
A binding in a decomposition declaration.
Definition DeclCXX.h:4185
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4218
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4211
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:4223
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4229
BreakStmt - This represents a break.
Definition Stmt.h:3114
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5476
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:3164
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:2100
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:1493
CXXTemporary * getTemporary()
Definition ExprCXX.h:1511
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition ExprCXX.cpp:1118
const Expr * getSubExpr() const
Definition ExprCXX.h:1515
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:723
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition ExprCXX.h:735
bool getValue() const
Definition ExprCXX.h:740
SourceLocation getLocation() const
Definition ExprCXX.h:746
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:1548
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1729
void setIsImmediateEscalating(bool Set)
Definition ExprCXX.h:1710
bool isElidable() const
Whether this construction is elidable.
Definition ExprCXX.h:1617
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition ExprCXX.h:1622
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:1672
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1641
bool isImmediateEscalating() const
Definition ExprCXX.h:1706
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition ExprCXX.h:1650
SourceLocation getLocation() const
Definition ExprCXX.h:1613
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1611
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1630
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1688
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1659
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2943
Represents a C++ base or member initializer.
Definition DeclCXX.h:2369
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2509
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2469
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2571
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2568
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2479
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2567
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2474
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2503
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2447
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2441
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2453
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2529
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2523
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2495
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1979
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2063
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1270
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition ExprCXX.h:1344
const ParmVarDecl * getParam() const
Definition ExprCXX.h:1312
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1340
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1039
bool hasRewrittenInit() const
Definition ExprCXX.h:1315
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1377
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:1434
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition ExprCXX.h:1422
bool hasRewrittenInit() const
Definition ExprCXX.h:1406
FieldDecl * getField()
Get the field whose initializer will be used.
Definition ExprCXX.h:1411
SourceLocation getBeginLoc() const
Definition ExprCXX.h:1441
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2626
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2665
bool isArrayForm() const
Definition ExprCXX.h:2652
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2676
bool isGlobalDelete() const
Definition ExprCXX.h:2651
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2661
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2653
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3870
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:3969
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:3972
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:4024
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4016
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4003
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4043
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4012
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4032
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4008
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:3996
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:3960
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:3983
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:3952
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4071
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3112
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:5032
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5054
Expr * getRHS() const
Definition ExprCXX.h:5058
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5074
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5076
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5079
Expr * getLHS() const
Definition ExprCXX.h:5057
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5075
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5077
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:1751
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1792
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1788
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1804
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1802
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
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:2129
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2755
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2778
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2225
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:375
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:406
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:413
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:409
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2355
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:2609
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2572
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:2469
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2527
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2562
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2461
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2494
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2438
SourceRange getSourceRange() const
Definition ExprCXX.h:2610
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2516
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2556
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2459
bool isGlobalNew() const
Definition ExprCXX.h:2521
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2533
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4309
bool getValue() const
Definition ExprCXX.h:4332
SourceLocation getEndLoc() const
Definition ExprCXX.h:4329
Expr * getOperand() const
Definition ExprCXX.h:4326
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4328
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:768
SourceLocation getLocation() const
Definition ExprCXX.h:782
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:5141
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Definition ExprCXX.cpp:1987
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5197
SourceLocation getInitLoc() const LLVM_READONLY
Definition ExprCXX.h:5199
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5181
ArrayRef< Expr * > getUserSpecifiedInitExprs()
Definition ExprCXX.h:5187
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5195
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2745
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2839
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2809
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2823
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2830
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2798
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2854
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2827
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2812
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:2846
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:2020
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:2050
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2033
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2046
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition DeclCXX.cpp:1834
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition DeclCXX.cpp:2027
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2061
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:286
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:304
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition ExprCXX.h:322
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2196
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2215
SourceLocation getRParenLoc() const
Definition ExprCXX.h:2219
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:800
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1899
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:1928
Represents a C++ temporary.
Definition ExprCXX.h:1459
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition ExprCXX.cpp:1113
Represents the this expression in C++.
Definition ExprCXX.h:1154
bool isImplicit() const
Definition ExprCXX.h:1177
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition ExprCXX.cpp:1585
SourceLocation getLocation() const
Definition ExprCXX.h:1171
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1208
const Expr * getSubExpr() const
Definition ExprCXX.h:1228
SourceLocation getThrowLoc() const
Definition ExprCXX.h:1231
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition ExprCXX.h:1238
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:848
bool isTypeOperand() const
Definition ExprCXX.h:884
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition ExprCXX.h:891
Expr * getExprOperand() const
Definition ExprCXX.h:895
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:902
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3744
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3788
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3799
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:3782
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3793
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3802
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2877
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:1513
ADLCallKind getADLCallKind() const
Definition Expr.h:3028
Expr * getCallee()
Definition Expr.h:3024
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3176
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3068
arg_range arguments()
Definition Expr.h:3129
SourceLocation getRParenLoc() const
Definition Expr.h:3208
CaseStmt - Represent a case statement.
Definition Stmt.h:1899
Stmt * getSubStmt()
Definition Stmt.h:2012
Expr * getLHS()
Definition Stmt.h:1982
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:1968
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition Stmt.cpp:1268
SourceLocation getCaseLoc() const
Definition Stmt.h:1964
Expr * getRHS()
Definition Stmt.h:1994
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3610
path_iterator path_begin()
Definition Expr.h:3680
CastKind getCastKind() const
Definition Expr.h:3654
path_iterator path_end()
Definition Expr.h:3681
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3730
Expr * getSubExpr()
Definition Expr.h:3660
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1621
unsigned getValue() const
Definition Expr.h:1629
CharacterLiteralKind getKind() const
Definition Expr.h:1622
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:4782
SourceLocation getBuiltinLoc() const
Definition Expr.h:4829
Expr * getLHS() const
Definition Expr.h:4824
bool isConditionDependent() const
Definition Expr.h:4812
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4805
Expr * getRHS() const
Definition Expr.h:4826
SourceLocation getRParenLoc() const
Definition Expr.h:4832
Expr * getCond() const
Definition Expr.h:4822
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.
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4234
QualType getComputationLHSType() const
Definition Expr.h:4268
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:5000
QualType getComputationResultType() const
Definition Expr.h:4271
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3539
SourceLocation getLParenLoc() const
Definition Expr.h:3574
bool isFileScope() const
Definition Expr.h:3571
const Expr * getInitializer() const
Definition Expr.h:3567
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3577
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1719
unsigned size() const
Definition Stmt.h:1764
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1769
body_range body()
Definition Stmt.h:1782
SourceLocation getLBracLoc() const
Definition Stmt.h:1836
bool hasStoredFPFeatures() const
Definition Stmt.h:1766
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition Stmt.cpp:394
SourceLocation getRBracLoc() const
Definition Stmt.h:1837
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:4325
Expr * getLHS() const
Definition Expr.h:4359
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4348
Expr * getRHS() const
Definition Expr.h:4360
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1082
APValue getAPValueResult() const
Definition Expr.cpp:409
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:346
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:3677
ContinueStmt - This represents a continue.
Definition Stmt.h:3098
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4653
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4721
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4757
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:5555
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4754
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4746
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4743
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:1270
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1381
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1425
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1474
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1397
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:484
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1405
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1363
ValueDecl * getDecl()
Definition Expr.h:1338
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1451
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1468
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1457
SourceLocation getLocation() const
Definition Expr.h:1346
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1413
bool isImmediateEscalating() const
Definition Expr.h:1478
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1610
SourceLocation getEndLoc() const
Definition Stmt.h:1633
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1628
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1636
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:2007
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:4249
SourceLocation getDefaultLoc() const
Definition Stmt.h:2064
Stmt * getSubStmt()
Definition Stmt.h:2060
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3510
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:3584
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3558
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3576
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3618
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3594
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3568
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3549
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3546
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?
Represents a single C99 designator.
Definition Expr.h:5528
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5655
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5609
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5645
SourceLocation getFieldLoc() const
Definition Expr.h:5636
SourceLocation getRBracketLoc() const
Definition Expr.h:5684
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4670
SourceLocation getEllipsisLoc() const
Definition Expr.h:5678
SourceLocation getDotLoc() const
Definition Expr.h:5631
SourceLocation getLBracketLoc() const
Definition Expr.h:5672
Represents a C99 designated initializer expression.
Definition Expr.h:5485
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5767
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5749
MutableArrayRef< Designator > designators()
Definition Expr.h:5718
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5753
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5715
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5740
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5765
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4711
A little helper class used to produce diagnostics.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2811
Stmt * getBody()
Definition Stmt.h:2836
Expr * getCond()
Definition Stmt.h:2829
SourceLocation getWhileLoc() const
Definition Stmt.h:2842
SourceLocation getDoLoc() const
Definition Stmt.h:2840
SourceLocation getRParenLoc() const
Definition Stmt.h:2844
Symbolic representation of a dynamic allocation.
Definition APValue.h:65
Represents an empty-declaration.
Definition Decl.h:5175
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:4007
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4279
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4225
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4217
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4228
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4189
EnumDecl * getMostRecentDecl()
Definition Decl.h:4112
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4234
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5028
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4180
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5088
EnumDecl * getDefinition() const
Definition Decl.h:4119
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4206
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4172
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3862
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3884
Store information needed for an explicit specifier.
Definition DeclCXX.h:1924
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1932
const Expr * getExpr() const
Definition DeclCXX.h:1933
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3661
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3696
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3685
unsigned getNumObjects() const
Definition ExprCXX.h:3689
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3667
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:444
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:451
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:3069
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3101
Expr * getQueriedExpression() const
Definition ExprCXX.h:3108
ExpressionTrait getTrait() const
Definition ExprCXX.h:3104
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3102
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:4721
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:4731
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:4831
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:1581
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1575
SourceLocation getLocation() const
Definition Expr.h:1707
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1072
llvm::APFloat getValue() const
Definition Expr.h:1666
bool isExact() const
Definition Expr.h:1699
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2867
Stmt * getInit()
Definition Stmt.h:2882
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1082
SourceLocation getRParenLoc() const
Definition Stmt.h:2927
Stmt * getBody()
Definition Stmt.h:2911
Expr * getInc()
Definition Stmt.h:2910
SourceLocation getForLoc() const
Definition Stmt.h:2923
Expr * getCond()
Definition Stmt.h:2909
SourceLocation getLParenLoc() const
Definition Stmt.h:2925
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:1062
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3136
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:3275
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2476
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4194
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4189
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3294
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3156
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2701
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3547
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:4168
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4319
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:4385
@ 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:4140
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4207
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:4374
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:3551
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:3555
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3559
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:4213
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4413
void setDefaulted(bool D=true)
Definition Decl.h:2386
void setBody(Stmt *B)
Definition Decl.cpp:3287
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:3165
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:4161
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2211
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3195
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:5254
QualType desugar() const
Definition TypeBase.h:5835
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5543
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5708
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5694
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:4806
QualType getReturnType() const
Definition TypeBase.h:4790
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3374
unsigned getNumLabels() const
Definition Stmt.h:3524
labels_range labels()
Definition Stmt.h:3547
SourceLocation getRParenLoc() const
Definition Stmt.h:3396
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3489
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3476
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3502
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3465
const Expr * getAsmStringExpr() const
Definition Stmt.h:3401
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3581
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4857
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4874
Represents a C11 generic selection.
Definition Expr.h:6112
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6387
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6407
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6368
SourceLocation getGenericLoc() const
Definition Expr.h:6465
SourceLocation getRParenLoc() const
Definition Expr.h:6469
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6357
SourceLocation getDefaultLoc() const
Definition Expr.h:6468
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:4600
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6364
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6375
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6412
GotoStmt - This represents a direct goto.
Definition Stmt.h:2948
SourceLocation getLabelLoc() const
Definition Stmt.h:2966
SourceLocation getGotoLoc() const
Definition Stmt.h:2964
LabelDecl * getLabel() const
Definition Stmt.h:2961
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:2238
Stmt * getThen()
Definition Stmt.h:2327
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:1006
SourceLocation getIfLoc() const
Definition Stmt.h:2404
IfStatementKind getStatementKind() const
Definition Stmt.h:2439
SourceLocation getElseLoc() const
Definition Stmt.h:2407
Stmt * getInit()
Definition Stmt.h:2388
SourceLocation getLParenLoc() const
Definition Stmt.h:2456
Expr * getCond()
Definition Stmt.h:2315
Stmt * getElse()
Definition Stmt.h:2336
SourceLocation getRParenLoc() const
Definition Stmt.h:2458
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1030
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1731
const Expr * getSubExpr() const
Definition Expr.h:1743
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3787
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2069
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:5991
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5049
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:2987
SourceLocation getGotoLoc() const
Definition Stmt.h:3003
SourceLocation getStarLoc() const
Definition Stmt.h:3005
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2575
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2588
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2587
Describes an C or C++ initializer list.
Definition Expr.h:5233
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5345
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5410
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5359
unsigned getNumInits() const
Definition Expr.h:5263
SourceLocation getLBraceLoc() const
Definition Expr.h:5394
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2434
InitListExpr * getSyntacticForm() const
Definition Expr.h:5406
bool hadArrayRangeDesignator() const
Definition Expr.h:5417
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5335
SourceLocation getRBraceLoc() const
Definition Expr.h:5396
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5365
ArrayRef< Expr * > inits()
Definition Expr.h:5283
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5420
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:971
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1536
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:2125
LabelDecl * getDecl() const
Definition Stmt.h:2143
Stmt * getSubStmt()
Definition Stmt.h:2147
SourceLocation getIdentLoc() const
Definition Stmt.h:2140
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:1968
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:2186
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition ExprCXX.h:2171
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition ExprCXX.h:2119
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2049
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:2174
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition ExprCXX.h:2026
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2083
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition ExprCXX.h:2021
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:3308
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3354
Represents a linkage specification.
Definition DeclCXX.h:3015
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3057
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3038
SourceLocation getExternLoc() const
Definition DeclCXX.h:3054
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3055
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3049
Represents the results of name lookup.
Definition Lookup.h:147
iterator end() const
Definition Lookup.h:359
iterator begin() const
Definition Lookup.h:358
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4920
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4937
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:4989
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:4960
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3298
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3470
SourceLocation getOperatorLoc() const
Definition Expr.h:3480
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3415
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3400
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3381
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3442
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3522
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:1746
Expr * getBase() const
Definition Expr.h:3375
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3431
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3423
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3475
bool isArrow() const
Definition Expr.h:3482
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3385
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:3201
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3262
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3284
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3287
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3290
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3271
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:1682
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1696
SourceLocation getSemiLoc() const
Definition Stmt.h:1693
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
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
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:2527
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2586
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2560
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2574
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1649
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2567
unsigned getNumExpressions() const
Definition Expr.h:2598
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2564
unsigned getNumComponents() const
Definition Expr.h:2582
Helper class for OffsetOfExpr.
Definition Expr.h:2421
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2479
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2485
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1684
@ Array
An index into an array.
Definition Expr.h:2426
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2430
@ Field
A field.
Definition Expr.h:2428
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2433
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2507
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2475
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2508
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2495
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1178
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1228
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1200
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3280
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3262
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3235
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3241
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3254
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3250
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3227
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition ExprCXX.h:3342
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3238
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3270
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3337
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:4363
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4392
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4403
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4399
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2182
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2207
const Expr * getSubExpr() const
Definition Expr.h:2199
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2211
ArrayRef< Expr * > exprs()
Definition Expr.h:6057
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4850
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6044
SourceLocation getLParenLoc() const
Definition Expr.h:6059
SourceLocation getRParenLoc() const
Definition Expr.h:6060
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:3018
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:3043
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:3006
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3048
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3054
unsigned getFunctionScopeDepth() const
Definition Decl.h:1840
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1939
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2005
SourceLocation getBeginLoc() const
Definition Expr.h:2070
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:629
bool isTransparent() const
Definition Expr.h:2044
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2040
StringLiteral * getFunctionName()
Definition Expr.h:2049
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2694
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6690
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6732
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5072
ArrayRef< Expr * > semantics()
Definition Expr.h:6762
unsigned getNumSemanticExprs() const
Definition Expr.h:6747
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6727
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:8278
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8310
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:4321
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5180
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4377
field_range fields() const
Definition Decl.h:4524
RecordDecl * getMostRecentDecl()
Definition Decl.h:4347
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5225
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4505
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4373
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:5326
Represents the body of a requires-expression.
Definition DeclCXX.h:2098
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:3139
SourceLocation getReturnLoc() const
Definition Stmt.h:3188
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3175
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition Stmt.cpp:1252
Expr * getRetValue()
Definition Stmt.h:3166
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:4577
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4613
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4610
SourceLocation getRParenLoc() const
Definition Expr.h:4597
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4600
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4441
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4503
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4526
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:4531
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4500
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4506
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4509
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4515
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:4951
SourceLocation getBeginLoc() const
Definition Expr.h:4996
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:4992
SourceLocation getEndLoc() const
Definition Expr.h:4997
SourceLocIdentKind getIdentKind() const
Definition Expr.h:4971
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:4136
bool isFailed() const
Definition DeclCXX.h:4165
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4167
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4529
CompoundStmt * getSubStmt()
Definition Expr.h:4546
unsigned getTemplateDepth() const
Definition Expr.h:4558
SourceLocation getRParenLoc() const
Definition Expr.h:4555
SourceLocation getLParenLoc() const
Definition Expr.h:4553
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:85
child_iterator child_begin()
Definition Stmt.h:1570
StmtClass getStmtClass() const
Definition Stmt.h:1472
child_iterator child_end()
Definition Stmt.h:1571
const char * getStmtClassName() const
Definition Stmt.cpp:87
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:350
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1799
bool isPascal() const
Definition Expr.h:1922
tokloc_iterator tokloc_begin() const
Definition Expr.h:1965
tokloc_iterator tokloc_end() const
Definition Expr.h:1969
StringLiteralKind getKind() const
Definition Expr.h:1912
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:1184
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1875
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1940
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4664
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4709
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4715
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4713
SourceLocation getNameLoc() const
Definition ExprCXX.h:4699
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4754
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:4802
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4788
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4792
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:1874
SourceLocation getColonLoc() const
Definition Stmt.h:1878
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1872
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2488
SourceLocation getSwitchLoc() const
Definition Stmt.h:2623
SourceLocation getLParenLoc() const
Definition Stmt.h:2625
SourceLocation getRParenLoc() const
Definition Stmt.h:2627
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition Stmt.cpp:1129
Expr * getCond()
Definition Stmt.h:2551
Stmt * getBody()
Definition Stmt.h:2563
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1148
Stmt * getInit()
Definition Stmt.h:2568
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2619
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
SourceRange getBraceRange() const
Definition Decl.h:3788
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3832
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4925
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3807
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3812
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:3965
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3948
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4902
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4897
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4939
TagKind getTagKind() const
Definition Decl.h:3911
void setBraceRange(SourceRange R)
Definition Decl.h:3789
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3815
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
A container of type source information.
Definition TypeBase.h:8249
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:8260
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2896
bool getBoolValue() const
Definition ExprCXX.h:2947
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2967
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:2972
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2958
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2939
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2971
const APValue & getAPValue() const
Definition ExprCXX.h:2952
bool isStoredAsBoolean() const
Definition ExprCXX.h:2943
An operation on a type.
Definition TypeVisitor.h:64
The base class of the type hierarchy.
Definition TypeBase.h:1833
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isArrayType() const
Definition TypeBase.h:8614
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:752
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2782
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9044
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2435
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition TypeBase.h:2411
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9091
bool isRecordType() const
Definition TypeBase.h:8642
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
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2625
SourceLocation getRParenLoc() const
Definition Expr.h:2701
SourceLocation getOperatorLoc() const
Definition Expr.h:2698
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2671
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2657
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2289
Expr * getSubExpr() const
Definition Expr.h:2285
Opcode getOpcode() const
Definition Expr.h:2280
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2381
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2384
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5014
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2298
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3390
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3464
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3459
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:4126
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4218
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4221
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4212
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4199
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.
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4037
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4067
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4071
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4064
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4088
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3940
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3971
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3981
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3988
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:3998
Represents a C++ using-declaration.
Definition DeclCXX.h:3591
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3640
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3625
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3632
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3618
Represents C++ using-directive.
Definition DeclCXX.h:3096
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3167
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3244
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3163
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3171
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3174
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3141
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3792
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3816
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3828
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3812
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3873
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3902
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3906
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3399
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3463
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3374
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4891
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:4915
SourceLocation getBuiltinLoc() const
Definition Expr.h:4918
SourceLocation getRParenLoc() const
Definition Expr.h:4921
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4912
const Expr * getSubExpr() const
Definition Expr.h:4907
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:2817
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:2942
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:2267
bool isInlineSpecified() const
Definition Decl.h:1554
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2373
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2578
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2564
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:2779
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:2484
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2822
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:2905
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()
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2676
Expr * getCond()
Definition Stmt.h:2728
SourceLocation getWhileLoc() const
Definition Stmt.h:2781
SourceLocation getRParenLoc() const
Definition Stmt.h:2786
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1209
SourceLocation getLParenLoc() const
Definition Stmt.h:2784
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:1191
Stmt * getBody()
Definition Stmt.h:2740
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
const FunctionProtoType * T
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:583
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:149
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:1796
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:5323
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5327
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5313
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5316
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5319
Extra information about a function prototype.
Definition TypeBase.h:5339
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