clang 23.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 if (auto *VD = dyn_cast<VarDecl>(D))
125 if (auto *TD = dyn_cast<TagDecl>(D))
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 // Use this to import pointers of specific type.
189 template <typename ImportT>
190 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
191 auto ToOrErr = Importer.Import(From);
192 if (ToOrErr)
193 To = cast_or_null<ImportT>(*ToOrErr);
194 return ToOrErr.takeError();
195 }
196
197 // Call the import function of ASTImporter for a baseclass of type `T` and
198 // cast the return value to `T`.
199 template <typename T>
200 auto import(T *From)
201 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203 auto ToOrErr = Importer.Import(From);
204 if (!ToOrErr)
205 return ToOrErr.takeError();
206 return cast_or_null<T>(*ToOrErr);
207 }
208
209 template <typename T>
210 auto import(const T *From) {
211 return import(const_cast<T *>(From));
212 }
213
214 // Call the import function of ASTImporter for type `T`.
215 template <typename T>
216 Expected<T> import(const T &From) {
217 return Importer.Import(From);
218 }
219
220 // Import an std::optional<T> by importing the contained T, if any.
221 template <typename T>
222 Expected<std::optional<T>> import(std::optional<T> From) {
223 if (!From)
224 return std::nullopt;
225 return import(*From);
226 }
227
228 ExplicitSpecifier importExplicitSpecifier(Error &Err,
229 ExplicitSpecifier ESpec);
230
231 // Wrapper for an overload set.
232 template <typename ToDeclT> struct CallOverloadedCreateFun {
233 template <typename... Args> decltype(auto) operator()(Args &&... args) {
234 return ToDeclT::Create(std::forward<Args>(args)...);
235 }
236 };
237
238 // Always use these functions to create a Decl during import. There are
239 // certain tasks which must be done after the Decl was created, e.g. we
240 // must immediately register that as an imported Decl. The parameter `ToD`
241 // will be set to the newly created Decl or if had been imported before
242 // then to the already imported Decl. Returns a bool value set to true if
243 // the `FromD` had been imported before.
244 template <typename ToDeclT, typename FromDeclT, typename... Args>
245 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
246 Args &&...args) {
247 // There may be several overloads of ToDeclT::Create. We must make sure
248 // to call the one which would be chosen by the arguments, thus we use a
249 // wrapper for the overload set.
250 CallOverloadedCreateFun<ToDeclT> OC;
251 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
252 std::forward<Args>(args)...);
253 }
254 // Use this overload if a special Type is needed to be created. E.g if we
255 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
256 // then:
257 // TypedefNameDecl *ToTypedef;
258 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
259 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
260 typename... Args>
261 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
262 Args &&...args) {
263 CallOverloadedCreateFun<NewDeclT> OC;
264 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
265 std::forward<Args>(args)...);
266 }
267 // Use this version if a special create function must be
268 // used, e.g. CXXRecordDecl::CreateLambda .
269 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
270 typename... Args>
271 [[nodiscard]] bool
272 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
273 FromDeclT *FromD, Args &&...args) {
274 if (Importer.getImportDeclErrorIfAny(FromD)) {
275 ToD = nullptr;
276 return true; // Already imported but with error.
277 }
278 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
279 if (ToD)
280 return true; // Already imported.
281 ToD = CreateFun(std::forward<Args>(args)...);
282 // Keep track of imported Decls.
283 Importer.RegisterImportedDecl(FromD, ToD);
284 Importer.SharedState->markAsNewDecl(ToD);
285 InitializeImportedDecl(FromD, ToD);
286 return false; // A new Decl is created.
287 }
288
289 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
290 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
291 if (FromD->isUsed())
292 ToD->setIsUsed();
293 if (FromD->isImplicit())
294 ToD->setImplicit();
295 }
296
297 // Check if we have found an existing definition. Returns with that
298 // definition if yes, otherwise returns null.
299 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
300 const FunctionDecl *Definition = nullptr;
302 FoundFunction->hasBody(Definition))
303 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
304 return nullptr;
305 }
306
307 void addDeclToContexts(Decl *FromD, Decl *ToD) {
308 if (Importer.isMinimalImport()) {
309 // In minimal import case the decl must be added even if it is not
310 // contained in original context, for LLDB compatibility.
311 // FIXME: Check if a better solution is possible.
312 if (!FromD->getDescribedTemplate() &&
313 FromD->getFriendObjectKind() == Decl::FOK_None)
315 return;
316 }
317
318 DeclContext *FromDC = FromD->getDeclContext();
319 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
320 DeclContext *ToDC = ToD->getDeclContext();
321 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
322
323 bool Visible = false;
324 if (FromDC->containsDeclAndLoad(FromD)) {
325 ToDC->addDeclInternal(ToD);
326 Visible = true;
327 }
328 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
329 ToLexicalDC->addDeclInternal(ToD);
330 Visible = true;
331 }
332
333 // If the Decl was added to any context, it was made already visible.
334 // Otherwise it is still possible that it should be visible.
335 if (!Visible) {
336 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
337 auto *ToNamed = cast<NamedDecl>(ToD);
338 DeclContextLookupResult FromLookup =
339 FromDC->lookup(FromNamed->getDeclName());
340 if (llvm::is_contained(FromLookup, FromNamed))
341 ToDC->makeDeclVisibleInContext(ToNamed);
342 }
343 }
344 }
345
346 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
347 DeclContext *OldDC) {
348 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
349 if (!LT)
350 return;
351
352 for (NamedDecl *TP : Params)
353 LT->update(TP, OldDC);
354 }
355
356 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
357 updateLookupTableForTemplateParameters(
358 Params, Importer.getToContext().getTranslationUnitDecl());
359 }
360
361 template <typename TemplateParmDeclT>
362 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
363 TemplateParmDeclT *ToD) {
364 if (D->hasDefaultArgument()) {
365 if (D->defaultArgumentWasInherited()) {
366 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
367 import(D->getDefaultArgStorage().getInheritedFrom());
368 if (!ToInheritedFromOrErr)
369 return ToInheritedFromOrErr.takeError();
370 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
371 if (!ToInheritedFrom->hasDefaultArgument()) {
372 // Resolve possible circular dependency between default value of the
373 // template argument and the template declaration.
374 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
375 import(D->getDefaultArgStorage()
376 .getInheritedFrom()
377 ->getDefaultArgument());
378 if (!ToInheritedDefaultArgOrErr)
379 return ToInheritedDefaultArgOrErr.takeError();
380 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
381 *ToInheritedDefaultArgOrErr);
382 }
383 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
384 ToInheritedFrom);
385 } else {
386 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
387 import(D->getDefaultArgument());
388 if (!ToDefaultArgOrErr)
389 return ToDefaultArgOrErr.takeError();
390 // Default argument could have been set in the
391 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
392 if (!ToD->hasDefaultArgument())
393 ToD->setDefaultArgument(Importer.getToContext(),
394 *ToDefaultArgOrErr);
395 }
396 }
397 return Error::success();
398 }
399
400 public:
401 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
402
406
407 // Importing types
409#define TYPE(Class, Base) \
410 ExpectedType Visit##Class##Type(const Class##Type *T);
411#include "clang/AST/TypeNodes.inc"
412
413 // Importing declarations
415 SourceLocation &Loc);
417 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
418 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
419 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
422 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
424 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
426
427 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
429 Expected<APValue> ImportAPValue(const APValue &FromValue);
430
432
433 /// What we should import from the definition.
435 /// Import the default subset of the definition, which might be
436 /// nothing (if minimal import is set) or might be everything (if minimal
437 /// import is not set).
439 /// Import everything.
441 /// Import only the bare bones needed to establish a valid
442 /// DeclContext.
444 };
445
447 return IDK == IDK_Everything ||
448 (IDK == IDK_Default && !Importer.isMinimalImport());
449 }
450
453 RecordDecl *From, RecordDecl *To,
456 EnumDecl *From, EnumDecl *To,
468
469 template <typename InContainerTy>
471 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
472
473 template<typename InContainerTy>
475 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
476 const InContainerTy &Container, TemplateArgumentListInfo &Result);
477
480 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
483 FunctionDecl *FromFD);
484
485 template <typename DeclTy>
486 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
487
489
491
493 ParmVarDecl *ToParam);
494
497
498 // Use for allocating string for newly imported object.
499 StringRef ImportASTStringRef(StringRef FromStr);
508
509 template <typename T>
511
512 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
513 bool IgnoreTemplateParmDepth = false);
560
563
581
582 // Importing statements
602 // FIXME: MSAsmStmt
603 // FIXME: SEHExceptStmt
604 // FIXME: SEHFinallyStmt
605 // FIXME: SEHTryStmt
606 // FIXME: SEHLeaveStmt
607 // FIXME: CapturedStmt
611 // FIXME: MSDependentExistsStmt
619
620 // Importing expressions
703
704 // Helper for chaining together multiple imports. If an error is detected,
705 // subsequent imports will return default constructed nodes, so that failure
706 // can be detected with a single conditional branch after a sequence of
707 // imports.
708 template <typename T> T importChecked(Error &Err, const T &From) {
709 // Don't attempt to import nodes if we hit an error earlier.
710 if (Err)
711 return T{};
712 Expected<T> MaybeVal = import(From);
713 if (!MaybeVal) {
714 Err = MaybeVal.takeError();
715 return T{};
716 }
717 return *MaybeVal;
718 }
719
720 template<typename IIter, typename OIter>
721 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
722 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
723 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
724 Expected<ItemT> ToOrErr = import(*Ibegin);
725 if (!ToOrErr)
726 return ToOrErr.takeError();
727 *Obegin = *ToOrErr;
728 }
729 return Error::success();
730 }
731
732 // Import every item from a container structure into an output container.
733 // If error occurs, stops at first error and returns the error.
734 // The output container should have space for all needed elements (it is not
735 // expanded, new items are put into from the beginning).
736 template<typename InContainerTy, typename OutContainerTy>
738 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
739 return ImportArrayChecked(
740 InContainer.begin(), InContainer.end(), OutContainer.begin());
741 }
742
743 template<typename InContainerTy, typename OIter>
744 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
745 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
746 }
747
749 CXXMethodDecl *FromMethod);
750
752 FunctionDecl *FromFD);
753
754 // Returns true if the given function has a placeholder return type and
755 // that type is declared inside the body of the function.
756 // E.g. auto f() { struct X{}; return X(); }
758 };
759
760template <typename InContainerTy>
762 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
763 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
764 auto ToLAngleLocOrErr = import(FromLAngleLoc);
765 if (!ToLAngleLocOrErr)
766 return ToLAngleLocOrErr.takeError();
767 auto ToRAngleLocOrErr = import(FromRAngleLoc);
768 if (!ToRAngleLocOrErr)
769 return ToRAngleLocOrErr.takeError();
770
771 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
772 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
773 return Err;
774 Result = ToTAInfo;
775 return Error::success();
776}
777
778template <>
784
785template <>
793
796 FunctionDecl *FromFD) {
797 assert(FromFD->getTemplatedKind() ==
799
801
802 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
803 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
804 return std::move(Err);
805
806 // Import template arguments.
807 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
808 std::get<1>(Result)))
809 return std::move(Err);
810
811 return Result;
812}
813
814template <>
816ASTNodeImporter::import(TemplateParameterList *From) {
818 if (Error Err = ImportContainerChecked(*From, To))
819 return std::move(Err);
820
821 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
822 if (!ToRequiresClause)
823 return ToRequiresClause.takeError();
824
825 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
826 if (!ToTemplateLocOrErr)
827 return ToTemplateLocOrErr.takeError();
828 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
829 if (!ToLAngleLocOrErr)
830 return ToLAngleLocOrErr.takeError();
831 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
832 if (!ToRAngleLocOrErr)
833 return ToRAngleLocOrErr.takeError();
834
836 Importer.getToContext(),
837 *ToTemplateLocOrErr,
838 *ToLAngleLocOrErr,
839 To,
840 *ToRAngleLocOrErr,
841 *ToRequiresClause);
842}
843
844template <>
846ASTNodeImporter::import(const TemplateArgument &From) {
847 switch (From.getKind()) {
849 return TemplateArgument();
850
852 ExpectedType ToTypeOrErr = import(From.getAsType());
853 if (!ToTypeOrErr)
854 return ToTypeOrErr.takeError();
855 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
856 From.getIsDefaulted());
857 }
858
860 ExpectedType ToTypeOrErr = import(From.getIntegralType());
861 if (!ToTypeOrErr)
862 return ToTypeOrErr.takeError();
863 return TemplateArgument(From, *ToTypeOrErr);
864 }
865
867 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
868 if (!ToOrErr)
869 return ToOrErr.takeError();
870 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
871 if (!ToTypeOrErr)
872 return ToTypeOrErr.takeError();
873 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
874 *ToTypeOrErr, From.getIsDefaulted());
875 }
876
878 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
879 if (!ToTypeOrErr)
880 return ToTypeOrErr.takeError();
881 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
882 From.getIsDefaulted());
883 }
884
886 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
887 if (!ToTypeOrErr)
888 return ToTypeOrErr.takeError();
889 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
890 if (!ToValueOrErr)
891 return ToValueOrErr.takeError();
892 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
893 *ToValueOrErr);
894 }
895
897 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
898 if (!ToTemplateOrErr)
899 return ToTemplateOrErr.takeError();
900
901 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
902 }
903
905 Expected<TemplateName> ToTemplateOrErr =
906 import(From.getAsTemplateOrTemplatePattern());
907 if (!ToTemplateOrErr)
908 return ToTemplateOrErr.takeError();
909
910 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
911 From.getIsDefaulted());
912 }
913
915 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
916 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
917 From.getIsDefaulted());
918 else
919 return ToExpr.takeError();
920
923 ToPack.reserve(From.pack_size());
924 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
925 return std::move(Err);
926
927 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
928 }
929 }
930
931 llvm_unreachable("Invalid template argument kind");
932}
933
934template <>
936ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
937 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
938 if (!ArgOrErr)
939 return ArgOrErr.takeError();
940 TemplateArgument Arg = *ArgOrErr;
941
942 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
943
946 ExpectedExpr E = import(FromInfo.getAsExpr());
947 if (!E)
948 return E.takeError();
949 ToInfo = TemplateArgumentLocInfo(*E);
950 } else if (Arg.getKind() == TemplateArgument::Type) {
951 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
952 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
953 else
954 return TSIOrErr.takeError();
955 } else {
956 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
957 if (!ToTemplateKWLocOrErr)
958 return ToTemplateKWLocOrErr.takeError();
959 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
960 if (!ToTemplateQualifierLocOrErr)
961 return ToTemplateQualifierLocOrErr.takeError();
962 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
963 if (!ToTemplateNameLocOrErr)
964 return ToTemplateNameLocOrErr.takeError();
965 auto ToTemplateEllipsisLocOrErr =
966 import(FromInfo.getTemplateEllipsisLoc());
967 if (!ToTemplateEllipsisLocOrErr)
968 return ToTemplateEllipsisLocOrErr.takeError();
970 Importer.getToContext(), *ToTemplateKWLocOrErr,
971 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
972 *ToTemplateEllipsisLocOrErr);
973 }
974
975 return TemplateArgumentLoc(Arg, ToInfo);
976}
977
978template <>
979Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
980 if (DG.isNull())
981 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
982 size_t NumDecls = DG.end() - DG.begin();
984 ToDecls.reserve(NumDecls);
985 for (Decl *FromD : DG) {
986 if (auto ToDOrErr = import(FromD))
987 ToDecls.push_back(*ToDOrErr);
988 else
989 return ToDOrErr.takeError();
990 }
991 return DeclGroupRef::Create(Importer.getToContext(),
992 ToDecls.begin(),
993 NumDecls);
994}
995
996template <>
998ASTNodeImporter::import(const Designator &D) {
999 if (D.isFieldDesignator()) {
1000 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
1001
1002 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
1003 if (!ToDotLocOrErr)
1004 return ToDotLocOrErr.takeError();
1005
1006 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1007 if (!ToFieldLocOrErr)
1008 return ToFieldLocOrErr.takeError();
1009
1011 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1012 }
1013
1014 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1015 if (!ToLBracketLocOrErr)
1016 return ToLBracketLocOrErr.takeError();
1017
1018 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1019 if (!ToRBracketLocOrErr)
1020 return ToRBracketLocOrErr.takeError();
1021
1022 if (D.isArrayDesignator())
1024 *ToLBracketLocOrErr,
1025 *ToRBracketLocOrErr);
1026
1027 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1028 if (!ToEllipsisLocOrErr)
1029 return ToEllipsisLocOrErr.takeError();
1030
1031 assert(D.isArrayRangeDesignator());
1033 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1034 *ToRBracketLocOrErr);
1035}
1036
1037template <>
1038Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1039 Error Err = Error::success();
1040 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1041 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1042 auto ToConceptNameLoc =
1043 importChecked(Err, From->getConceptNameInfo().getLoc());
1044 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1045 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1046 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1047 if (Err)
1048 return std::move(Err);
1049 TemplateArgumentListInfo ToTAInfo;
1050 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1051 if (ASTTemplateArgs)
1052 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1053 return std::move(Err);
1054 auto *ConceptRef = ConceptReference::Create(
1055 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1056 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1057 ToNamedConcept,
1058 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1059 Importer.getToContext(), ToTAInfo)
1060 : nullptr);
1061 return ConceptRef;
1062}
1063
1064StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1065 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1066 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1067 return StringRef(ToStore, FromStr.size());
1068}
1069
1071 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1072 ToSat.IsSatisfied = FromSat.IsSatisfied;
1073 ToSat.ContainsErrors = FromSat.ContainsErrors;
1074 if (!ToSat.IsSatisfied) {
1075 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1076 if (const Expr *E = Record->dyn_cast<const Expr *>()) {
1077 ExpectedExpr ToSecondExpr = import(E);
1078 if (!ToSecondExpr)
1079 return ToSecondExpr.takeError();
1080 ToSat.Details.emplace_back(ToSecondExpr.get());
1081 } else {
1082 auto Pair =
1083 Record->dyn_cast<const ConstraintSubstitutionDiagnostic *>();
1084
1085 ExpectedSLoc ToPairFirst = import(Pair->first);
1086 if (!ToPairFirst)
1087 return ToPairFirst.takeError();
1088 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1089 ToSat.Details.emplace_back(new (Importer.getToContext())
1091 ToPairFirst.get(), ToPairSecond});
1092 }
1093 }
1094 }
1095 return Error::success();
1096}
1097
1098template <>
1100ASTNodeImporter::import(
1102 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1103 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1104 if (!ToLoc)
1105 return ToLoc.takeError();
1106 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1107 return new (Importer.getToContext())
1109 ToDiagMessage};
1110}
1111
1114 using namespace concepts;
1115
1116 if (From->isSubstitutionFailure()) {
1117 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1118 if (!DiagOrErr)
1119 return DiagOrErr.takeError();
1120 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1121 } else {
1122 Expected<TypeSourceInfo *> ToType = import(From->getType());
1123 if (!ToType)
1124 return ToType.takeError();
1125 return new (Importer.getToContext()) TypeRequirement(*ToType);
1126 }
1127}
1128
1131 using namespace concepts;
1132
1133 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1134 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1135
1136 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1137 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1138
1139 if (IsRKSimple) {
1140 Req.emplace();
1141 } else {
1142 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1144
1145 if (FromTypeRequirement.isTypeConstraint()) {
1146 const bool IsDependent = FromTypeRequirement.isDependent();
1147 auto ParamsOrErr =
1148 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1149 if (!ParamsOrErr)
1150 return ParamsOrErr.takeError();
1151 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1152 auto SubstConstraintExprOrErr =
1154 if (!SubstConstraintExprOrErr)
1155 return SubstConstraintExprOrErr.takeError();
1156 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1157 }
1158 Req.emplace(ParamsOrErr.get(), IsDependent);
1159 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1160 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1161 if (!DiagOrErr)
1162 return DiagOrErr.takeError();
1163 Req.emplace(DiagOrErr.get());
1164 } else {
1165 Req.emplace();
1166 }
1167 }
1168
1169 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1170 if (!NoexceptLocOrErr)
1171 return NoexceptLocOrErr.takeError();
1172
1173 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1174 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1175 if (!DiagOrErr)
1176 return DiagOrErr.takeError();
1177 return new (Importer.getToContext()) ExprRequirement(
1178 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1179 } else {
1180 Expected<Expr *> ExprOrErr = import(From->getExpr());
1181 if (!ExprOrErr)
1182 return ExprOrErr.takeError();
1183 return new (Importer.getToContext()) concepts::ExprRequirement(
1184 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1185 SubstitutedConstraintExpr);
1186 }
1187}
1188
1191 using namespace concepts;
1192
1193 const ASTConstraintSatisfaction &FromSatisfaction =
1195 if (From->hasInvalidConstraint()) {
1196 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1197 ASTConstraintSatisfaction *ToSatisfaction =
1198 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1199 FromSatisfaction);
1200 return new (Importer.getToContext())
1201 NestedRequirement(ToEntity, ToSatisfaction);
1202 } else {
1203 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1204 if (!ToExpr)
1205 return ToExpr.takeError();
1206 if (ToExpr.get()->isInstantiationDependent()) {
1207 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1208 } else {
1209 ConstraintSatisfaction Satisfaction;
1210 if (Error Err =
1211 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1212 return std::move(Err);
1213 return new (Importer.getToContext()) NestedRequirement(
1214 Importer.getToContext(), ToExpr.get(), Satisfaction);
1215 }
1216 }
1217}
1218
1219template <>
1221ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1222 switch (FromRequire->getKind()) {
1231 }
1232 llvm_unreachable("Unhandled requirement kind");
1233}
1234
1235template <>
1236Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1237 ValueDecl *Var = nullptr;
1238 if (From.capturesVariable()) {
1239 if (auto VarOrErr = import(From.getCapturedVar()))
1240 Var = *VarOrErr;
1241 else
1242 return VarOrErr.takeError();
1243 }
1244
1245 auto LocationOrErr = import(From.getLocation());
1246 if (!LocationOrErr)
1247 return LocationOrErr.takeError();
1248
1249 SourceLocation EllipsisLoc;
1250 if (From.isPackExpansion())
1251 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1252 return std::move(Err);
1253
1254 return LambdaCapture(
1255 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1256 EllipsisLoc);
1257}
1258
1259template <typename T>
1261 if (Found->getLinkageInternal() != From->getLinkageInternal())
1262 return false;
1263
1264 if (From->hasExternalFormalLinkage())
1265 return Found->hasExternalFormalLinkage();
1266 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1267 return false;
1268 if (From->isInAnonymousNamespace())
1269 return Found->isInAnonymousNamespace();
1270 else
1271 return !Found->isInAnonymousNamespace() &&
1272 !Found->hasExternalFormalLinkage();
1273}
1274
1275template <>
1277 TypedefNameDecl *From) {
1278 if (Found->getLinkageInternal() != From->getLinkageInternal())
1279 return false;
1280
1281 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1282 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1283 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1284}
1285
1286} // namespace clang
1287
1288//----------------------------------------------------------------------------
1289// Import Types
1290//----------------------------------------------------------------------------
1291
1292using namespace clang;
1293
1295 const FunctionDecl *D) {
1296 const FunctionDecl *LambdaD = nullptr;
1297 if (!isCycle(D) && D) {
1298 FunctionDeclsWithImportInProgress.insert(D);
1299 LambdaD = D;
1300 }
1301 return llvm::scope_exit([this, LambdaD]() {
1302 if (LambdaD) {
1303 FunctionDeclsWithImportInProgress.erase(LambdaD);
1304 }
1305 });
1306}
1307
1309 const FunctionDecl *D) const {
1310 return FunctionDeclsWithImportInProgress.find(D) !=
1311 FunctionDeclsWithImportInProgress.end();
1312}
1313
1315 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1316 << T->getTypeClassName();
1317 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1318}
1319
1320ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1321 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1322 if (!UnderlyingTypeOrErr)
1323 return UnderlyingTypeOrErr.takeError();
1324
1325 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1326}
1327
1328ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1329 switch (T->getKind()) {
1330#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1331 case BuiltinType::Id: \
1332 return Importer.getToContext().SingletonId;
1333#include "clang/Basic/OpenCLImageTypes.def"
1334#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1335 case BuiltinType::Id: \
1336 return Importer.getToContext().Id##Ty;
1337#include "clang/Basic/OpenCLExtensionTypes.def"
1338#define SVE_TYPE(Name, Id, SingletonId) \
1339 case BuiltinType::Id: \
1340 return Importer.getToContext().SingletonId;
1341#include "clang/Basic/AArch64ACLETypes.def"
1342#define PPC_VECTOR_TYPE(Name, Id, Size) \
1343 case BuiltinType::Id: \
1344 return Importer.getToContext().Id##Ty;
1345#include "clang/Basic/PPCTypes.def"
1346#define RVV_TYPE(Name, Id, SingletonId) \
1347 case BuiltinType::Id: \
1348 return Importer.getToContext().SingletonId;
1349#include "clang/Basic/RISCVVTypes.def"
1350#define WASM_TYPE(Name, Id, SingletonId) \
1351 case BuiltinType::Id: \
1352 return Importer.getToContext().SingletonId;
1353#include "clang/Basic/WebAssemblyReferenceTypes.def"
1354#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1355 case BuiltinType::Id: \
1356 return Importer.getToContext().SingletonId;
1357#include "clang/Basic/AMDGPUTypes.def"
1358#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1359 case BuiltinType::Id: \
1360 return Importer.getToContext().SingletonId;
1361#include "clang/Basic/HLSLIntangibleTypes.def"
1362#define SHARED_SINGLETON_TYPE(Expansion)
1363#define BUILTIN_TYPE(Id, SingletonId) \
1364 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1365#include "clang/AST/BuiltinTypes.def"
1366
1367 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1368 // context supports C++.
1369
1370 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1371 // context supports ObjC.
1372
1373 case BuiltinType::Char_U:
1374 // The context we're importing from has an unsigned 'char'. If we're
1375 // importing into a context with a signed 'char', translate to
1376 // 'unsigned char' instead.
1377 if (Importer.getToContext().getLangOpts().CharIsSigned)
1378 return Importer.getToContext().UnsignedCharTy;
1379
1380 return Importer.getToContext().CharTy;
1381
1382 case BuiltinType::Char_S:
1383 // The context we're importing from has an unsigned 'char'. If we're
1384 // importing into a context with a signed 'char', translate to
1385 // 'unsigned char' instead.
1386 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1387 return Importer.getToContext().SignedCharTy;
1388
1389 return Importer.getToContext().CharTy;
1390
1391 case BuiltinType::WChar_S:
1392 case BuiltinType::WChar_U:
1393 // FIXME: If not in C++, shall we translate to the C equivalent of
1394 // wchar_t?
1395 return Importer.getToContext().WCharTy;
1396 }
1397
1398 llvm_unreachable("Invalid BuiltinType Kind!");
1399}
1400
1401ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1402 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1403 if (!ToOriginalTypeOrErr)
1404 return ToOriginalTypeOrErr.takeError();
1405
1406 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1407}
1408
1409ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1410 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1411 if (!ToElementTypeOrErr)
1412 return ToElementTypeOrErr.takeError();
1413
1414 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1415}
1416
1417ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1418 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1419 if (!ToPointeeTypeOrErr)
1420 return ToPointeeTypeOrErr.takeError();
1421
1422 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1423}
1424
1425ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1426 // FIXME: Check for blocks support in "to" context.
1427 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1428 if (!ToPointeeTypeOrErr)
1429 return ToPointeeTypeOrErr.takeError();
1430
1431 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1432}
1433
1435ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1436 // FIXME: Check for C++ support in "to" context.
1437 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1438 if (!ToPointeeTypeOrErr)
1439 return ToPointeeTypeOrErr.takeError();
1440
1441 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1442}
1443
1445ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1446 // FIXME: Check for C++0x support in "to" context.
1447 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1448 if (!ToPointeeTypeOrErr)
1449 return ToPointeeTypeOrErr.takeError();
1450
1451 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1452}
1453
1455ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1456 // FIXME: Check for C++ support in "to" context.
1457 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1458 if (!ToPointeeTypeOrErr)
1459 return ToPointeeTypeOrErr.takeError();
1460
1461 auto QualifierOrErr = import(T->getQualifier());
1462 if (!QualifierOrErr)
1463 return QualifierOrErr.takeError();
1464
1465 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1466 if (!ClsOrErr)
1467 return ClsOrErr.takeError();
1468
1469 return Importer.getToContext().getMemberPointerType(
1470 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1471}
1472
1474ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1475 Error Err = Error::success();
1476 auto ToElementType = importChecked(Err, T->getElementType());
1477 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1478 if (Err)
1479 return std::move(Err);
1480
1481 return Importer.getToContext().getConstantArrayType(
1482 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
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 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2551
2552 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2553 return Err;
2554
2555 // Add base classes.
2556 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2557 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2558 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2559
2560 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2561 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2562
2563 #define FIELD(Name, Width, Merge) \
2564 ToData.Name = FromData.Name;
2565 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2566
2567 // Copy over the data stored in RecordDeclBits
2568 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2569
2571 for (const auto &Base1 : FromCXX->bases()) {
2572 ExpectedType TyOrErr = import(Base1.getType());
2573 if (!TyOrErr)
2574 return TyOrErr.takeError();
2575
2576 SourceLocation EllipsisLoc;
2577 if (Base1.isPackExpansion()) {
2578 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2579 EllipsisLoc = *LocOrErr;
2580 else
2581 return LocOrErr.takeError();
2582 }
2583
2584 // Ensure that we have a definition for the base.
2585 if (Error Err =
2586 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2587 return Err;
2588
2589 auto RangeOrErr = import(Base1.getSourceRange());
2590 if (!RangeOrErr)
2591 return RangeOrErr.takeError();
2592
2593 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2594 if (!TSIOrErr)
2595 return TSIOrErr.takeError();
2596
2597 Bases.push_back(
2598 new (Importer.getToContext()) CXXBaseSpecifier(
2599 *RangeOrErr,
2600 Base1.isVirtual(),
2601 Base1.isBaseOfClass(),
2602 Base1.getAccessSpecifierAsWritten(),
2603 *TSIOrErr,
2604 EllipsisLoc));
2605 }
2606 if (!Bases.empty())
2607 ToCXX->setBases(Bases.data(), Bases.size());
2608 }
2609
2610 if (shouldForceImportDeclContext(Kind)) {
2611 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2612 return Err;
2613 }
2614
2615 return Error::success();
2616}
2617
2619 if (To->getAnyInitializer())
2620 return Error::success();
2621
2622 Expr *FromInit = From->getInit();
2623 if (!FromInit)
2624 return Error::success();
2625
2626 ExpectedExpr ToInitOrErr = import(FromInit);
2627 if (!ToInitOrErr)
2628 return ToInitOrErr.takeError();
2629
2630 To->setInit(*ToInitOrErr);
2631 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2632 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2633 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2634 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2635 // FIXME: Also import the initializer value.
2636 }
2637
2638 // FIXME: Other bits to merge?
2639 return Error::success();
2640}
2641
2643 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2644 if (To->getDefinition() || To->isBeingDefined()) {
2645 if (Kind == IDK_Everything)
2646 return ImportDeclContext(From, /*ForceImport=*/true);
2647 return Error::success();
2648 }
2649
2650 To->startDefinition();
2651
2652 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2653 return Err;
2654
2655 ExpectedType ToTypeOrErr =
2656 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2657 if (!ToTypeOrErr)
2658 return ToTypeOrErr.takeError();
2659
2660 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2661 if (!ToPromotionTypeOrErr)
2662 return ToPromotionTypeOrErr.takeError();
2663
2665 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2666 return Err;
2667
2668 // FIXME: we might need to merge the number of positive or negative bits
2669 // if the enumerator lists don't match.
2670 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2671 From->getNumPositiveBits(),
2672 From->getNumNegativeBits());
2673 return Error::success();
2674}
2675
2679 for (const auto &Arg : FromArgs) {
2680 if (auto ToOrErr = import(Arg))
2681 ToArgs.push_back(*ToOrErr);
2682 else
2683 return ToOrErr.takeError();
2684 }
2685
2686 return Error::success();
2687}
2688
2689// FIXME: Do not forget to remove this and use only 'import'.
2692 return import(From);
2693}
2694
2695template <typename InContainerTy>
2697 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2698 for (const auto &FromLoc : Container) {
2699 if (auto ToLocOrErr = import(FromLoc))
2700 ToTAInfo.addArgument(*ToLocOrErr);
2701 else
2702 return ToLocOrErr.takeError();
2703 }
2704 return Error::success();
2705}
2706
2712
2713bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2714 bool IgnoreTemplateParmDepth) {
2715 // Eliminate a potential failure point where we attempt to re-import
2716 // something we're trying to import while completing ToRecord.
2717 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2718 if (ToOrigin) {
2719 To = ToOrigin;
2720 }
2721
2723 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2724 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2726 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2727 IgnoreTemplateParmDepth);
2728 return Ctx.IsEquivalent(From, To);
2729}
2730
2732 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2733 << D->getDeclKindName();
2734 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2735}
2736
2738 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2739 << D->getDeclKindName();
2740 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2741}
2742
2744 // Import the context of this declaration.
2745 DeclContext *DC, *LexicalDC;
2746 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2747 return std::move(Err);
2748
2749 // Import the location of this declaration.
2750 ExpectedSLoc LocOrErr = import(D->getLocation());
2751 if (!LocOrErr)
2752 return LocOrErr.takeError();
2753
2754 EmptyDecl *ToD;
2755 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2756 return ToD;
2757
2758 ToD->setLexicalDeclContext(LexicalDC);
2759 LexicalDC->addDeclInternal(ToD);
2760 return ToD;
2761}
2762
2764 TranslationUnitDecl *ToD =
2765 Importer.getToContext().getTranslationUnitDecl();
2766
2767 Importer.MapImported(D, ToD);
2768
2769 return ToD;
2770}
2771
2773 DeclContext *DC, *LexicalDC;
2774 DeclarationName Name;
2775 SourceLocation Loc;
2776 NamedDecl *ToND;
2777 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2778 return std::move(Err);
2779 if (ToND)
2780 return ToND;
2781
2782 BindingDecl *ToD;
2783 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2784 Name.getAsIdentifierInfo(), D->getType()))
2785 return ToD;
2786
2787 Error Err = Error::success();
2788 QualType ToType = importChecked(Err, D->getType());
2789 Expr *ToBinding = importChecked(Err, D->getBinding());
2790 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2791 if (Err)
2792 return std::move(Err);
2793
2794 ToD->setBinding(ToType, ToBinding);
2795 ToD->setDecomposedDecl(ToDecomposedDecl);
2796 addDeclToContexts(D, ToD);
2797
2798 return ToD;
2799}
2800
2802 ExpectedSLoc LocOrErr = import(D->getLocation());
2803 if (!LocOrErr)
2804 return LocOrErr.takeError();
2805 auto ColonLocOrErr = import(D->getColonLoc());
2806 if (!ColonLocOrErr)
2807 return ColonLocOrErr.takeError();
2808
2809 // Import the context of this declaration.
2810 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2811 if (!DCOrErr)
2812 return DCOrErr.takeError();
2813 DeclContext *DC = *DCOrErr;
2814
2815 AccessSpecDecl *ToD;
2816 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2817 DC, *LocOrErr, *ColonLocOrErr))
2818 return ToD;
2819
2820 // Lexical DeclContext and Semantic DeclContext
2821 // is always the same for the accessSpec.
2822 ToD->setLexicalDeclContext(DC);
2823 DC->addDeclInternal(ToD);
2824
2825 return ToD;
2826}
2827
2829 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2830 if (!DCOrErr)
2831 return DCOrErr.takeError();
2832 DeclContext *DC = *DCOrErr;
2833 DeclContext *LexicalDC = DC;
2834
2835 Error Err = Error::success();
2836 auto ToLocation = importChecked(Err, D->getLocation());
2837 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2838 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2839 auto ToMessage = importChecked(Err, D->getMessage());
2840 if (Err)
2841 return std::move(Err);
2842
2843 StaticAssertDecl *ToD;
2844 if (GetImportedOrCreateDecl(
2845 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2846 ToRParenLoc, D->isFailed()))
2847 return ToD;
2848
2849 ToD->setLexicalDeclContext(LexicalDC);
2850 LexicalDC->addDeclInternal(ToD);
2851 return ToD;
2852}
2853
2855 // Import the major distinguishing characteristics of this namespace.
2856 DeclContext *DC, *LexicalDC;
2857 DeclarationName Name;
2858 SourceLocation Loc;
2859 NamedDecl *ToD;
2860 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2861 return std::move(Err);
2862 if (ToD)
2863 return ToD;
2864
2865 NamespaceDecl *MergeWithNamespace = nullptr;
2866 if (!Name) {
2867 // This is an anonymous namespace. Adopt an existing anonymous
2868 // namespace if we can.
2869 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2870 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2871 MergeWithNamespace = TU->getAnonymousNamespace();
2872 else
2873 MergeWithNamespace =
2874 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2875 } else {
2876 SmallVector<NamedDecl *, 4> ConflictingDecls;
2877 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2878 for (auto *FoundDecl : FoundDecls) {
2879 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2880 continue;
2881
2882 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2883 MergeWithNamespace = FoundNS;
2884 ConflictingDecls.clear();
2885 break;
2886 }
2887
2888 ConflictingDecls.push_back(FoundDecl);
2889 }
2890
2891 if (!ConflictingDecls.empty()) {
2892 ExpectedName NameOrErr = Importer.HandleNameConflict(
2893 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2894 ConflictingDecls.size());
2895 if (NameOrErr)
2896 Name = NameOrErr.get();
2897 else
2898 return NameOrErr.takeError();
2899 }
2900 }
2901
2902 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2903 if (!BeginLocOrErr)
2904 return BeginLocOrErr.takeError();
2905 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2906 if (!RBraceLocOrErr)
2907 return RBraceLocOrErr.takeError();
2908
2909 // Create the "to" namespace, if needed.
2910 NamespaceDecl *ToNamespace = MergeWithNamespace;
2911 if (!ToNamespace) {
2912 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2913 D->isInline(), *BeginLocOrErr, Loc,
2914 Name.getAsIdentifierInfo(),
2915 /*PrevDecl=*/nullptr, D->isNested()))
2916 return ToNamespace;
2917 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2918 ToNamespace->setLexicalDeclContext(LexicalDC);
2919 LexicalDC->addDeclInternal(ToNamespace);
2920
2921 // If this is an anonymous namespace, register it as the anonymous
2922 // namespace within its context.
2923 if (!Name) {
2924 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2925 TU->setAnonymousNamespace(ToNamespace);
2926 else
2927 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2928 }
2929 }
2930 Importer.MapImported(D, ToNamespace);
2931
2932 if (Error Err = ImportDeclContext(D))
2933 return std::move(Err);
2934
2935 return ToNamespace;
2936}
2937
2939 // Import the major distinguishing characteristics of this namespace.
2940 DeclContext *DC, *LexicalDC;
2941 DeclarationName Name;
2942 SourceLocation Loc;
2943 NamedDecl *LookupD;
2944 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2945 return std::move(Err);
2946 if (LookupD)
2947 return LookupD;
2948
2949 // NOTE: No conflict resolution is done for namespace aliases now.
2950
2951 Error Err = Error::success();
2952 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2953 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2954 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2955 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2956 auto ToNamespace = importChecked(Err, D->getNamespace());
2957 if (Err)
2958 return std::move(Err);
2959
2960 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2961
2962 NamespaceAliasDecl *ToD;
2963 if (GetImportedOrCreateDecl(
2964 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2965 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2966 return ToD;
2967
2968 ToD->setLexicalDeclContext(LexicalDC);
2969 LexicalDC->addDeclInternal(ToD);
2970
2971 return ToD;
2972}
2973
2976 // Import the major distinguishing characteristics of this typedef.
2977 DeclarationName Name;
2978 SourceLocation Loc;
2979 NamedDecl *ToD;
2980 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2981 // is created.
2982 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2983 return std::move(Err);
2984 if (ToD)
2985 return ToD;
2986
2987 DeclContext *DC = cast_or_null<DeclContext>(
2988 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2989 DeclContext *LexicalDC =
2990 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2992
2993 // If this typedef is not in block scope, determine whether we've
2994 // seen a typedef with the same name (that we can merge with) or any
2995 // other entity by that name (which name lookup could conflict with).
2996 // Note: Repeated typedefs are not valid in C99:
2997 // 'typedef int T; typedef int T;' is invalid
2998 // We do not care about this now.
2999 if (DC && !DC->isFunctionOrMethod()) {
3000 SmallVector<NamedDecl *, 4> ConflictingDecls;
3001 unsigned IDNS = Decl::IDNS_Ordinary;
3002 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3003 for (auto *FoundDecl : FoundDecls) {
3004 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3005 continue;
3006 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3007 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3008 continue;
3009
3010 QualType FromUT = D->getUnderlyingType();
3011 QualType FoundUT = FoundTypedef->getUnderlyingType();
3012 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3013 // If the underlying declarations are unnamed records these can be
3014 // imported as different types. We should create a distinct typedef
3015 // node in this case.
3016 // If we found an existing underlying type with a record in a
3017 // different context (than the imported), this is already reason for
3018 // having distinct typedef nodes for these.
3019 // Again this can create situation like
3020 // 'typedef int T; typedef int T;' but this is hard to avoid without
3021 // a rename strategy at import.
3022 if (!FromUT.isNull() && !FoundUT.isNull()) {
3023 RecordDecl *FromR = FromUT->getAsRecordDecl();
3024 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3025 if (FromR && FoundR &&
3026 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3027 continue;
3028 }
3029 // If the "From" context has a complete underlying type but we
3030 // already have a complete underlying type then return with that.
3031 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3032 return Importer.MapImported(D, FoundTypedef);
3033 // FIXME Handle redecl chain. When you do that make consistent changes
3034 // in ASTImporterLookupTable too.
3035 } else {
3036 ConflictingDecls.push_back(FoundDecl);
3037 }
3038 }
3039 }
3040
3041 if (!ConflictingDecls.empty()) {
3042 ExpectedName NameOrErr = Importer.HandleNameConflict(
3043 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3044 if (NameOrErr)
3045 Name = NameOrErr.get();
3046 else
3047 return NameOrErr.takeError();
3048 }
3049 }
3050
3051 Error Err = Error::success();
3053 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3054 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3055 if (Err)
3056 return std::move(Err);
3057
3058 // Create the new typedef node.
3059 // FIXME: ToUnderlyingType is not used.
3060 (void)ToUnderlyingType;
3061 TypedefNameDecl *ToTypedef;
3062 if (IsAlias) {
3063 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3064 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3065 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3066 return ToTypedef;
3067 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3068 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3069 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3070 return ToTypedef;
3071
3072 // Import the DeclContext and set it to the Typedef.
3073 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3074 return std::move(Err);
3075 ToTypedef->setDeclContext(DC);
3076 ToTypedef->setLexicalDeclContext(LexicalDC);
3077 // Add to the lookupTable because we could not do that in MapImported.
3078 Importer.AddToLookupTable(ToTypedef);
3079
3080 ToTypedef->setAccess(D->getAccess());
3081
3082 // Templated declarations should not appear in DeclContext.
3083 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3084 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3085 LexicalDC->addDeclInternal(ToTypedef);
3086
3087 return ToTypedef;
3088}
3089
3093
3097
3100 // Import the major distinguishing characteristics of this typedef.
3101 DeclContext *DC, *LexicalDC;
3102 DeclarationName Name;
3103 SourceLocation Loc;
3104 NamedDecl *FoundD;
3105 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3106 return std::move(Err);
3107 if (FoundD)
3108 return FoundD;
3109
3110 // If this typedef is not in block scope, determine whether we've
3111 // seen a typedef with the same name (that we can merge with) or any
3112 // other entity by that name (which name lookup could conflict with).
3113 if (!DC->isFunctionOrMethod()) {
3114 SmallVector<NamedDecl *, 4> ConflictingDecls;
3115 unsigned IDNS = Decl::IDNS_Ordinary;
3116 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3117 for (auto *FoundDecl : FoundDecls) {
3118 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3119 continue;
3120 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3121 if (IsStructuralMatch(D, FoundAlias))
3122 return Importer.MapImported(D, FoundAlias);
3123 ConflictingDecls.push_back(FoundDecl);
3124 }
3125 }
3126
3127 if (!ConflictingDecls.empty()) {
3128 ExpectedName NameOrErr = Importer.HandleNameConflict(
3129 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3130 if (NameOrErr)
3131 Name = NameOrErr.get();
3132 else
3133 return NameOrErr.takeError();
3134 }
3135 }
3136
3137 Error Err = Error::success();
3138 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3139 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3140 if (Err)
3141 return std::move(Err);
3142
3143 TypeAliasTemplateDecl *ToAlias;
3144 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3145 Name, ToTemplateParameters, ToTemplatedDecl))
3146 return ToAlias;
3147
3148 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3149
3150 ToAlias->setAccess(D->getAccess());
3151 ToAlias->setLexicalDeclContext(LexicalDC);
3152 LexicalDC->addDeclInternal(ToAlias);
3153 if (DC != Importer.getToContext().getTranslationUnitDecl())
3154 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3155 return ToAlias;
3156}
3157
3159 // Import the major distinguishing characteristics of this label.
3160 DeclContext *DC, *LexicalDC;
3161 DeclarationName Name;
3162 SourceLocation Loc;
3163 NamedDecl *ToD;
3164 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3165 return std::move(Err);
3166 if (ToD)
3167 return ToD;
3168
3169 assert(LexicalDC->isFunctionOrMethod());
3170
3171 LabelDecl *ToLabel;
3172 if (D->isGnuLocal()) {
3173 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3174 if (!BeginLocOrErr)
3175 return BeginLocOrErr.takeError();
3176 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3177 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3178 return ToLabel;
3179
3180 } else {
3181 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3182 Name.getAsIdentifierInfo()))
3183 return ToLabel;
3184
3185 }
3186
3187 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3188 if (!ToStmtOrErr)
3189 return ToStmtOrErr.takeError();
3190
3191 ToLabel->setStmt(*ToStmtOrErr);
3192 ToLabel->setLexicalDeclContext(LexicalDC);
3193 LexicalDC->addDeclInternal(ToLabel);
3194 return ToLabel;
3195}
3196
3198 // Import the major distinguishing characteristics of this enum.
3199 DeclContext *DC, *LexicalDC;
3200 DeclarationName Name;
3201 SourceLocation Loc;
3202 NamedDecl *ToD;
3203 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3204 return std::move(Err);
3205 if (ToD)
3206 return ToD;
3207
3208 // Figure out what enum name we're looking for.
3209 unsigned IDNS = Decl::IDNS_Tag;
3210 DeclarationName SearchName = Name;
3211 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3212 if (Error Err = importInto(
3213 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3214 return std::move(Err);
3215 IDNS = Decl::IDNS_Ordinary;
3216 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3217 IDNS |= Decl::IDNS_Ordinary;
3218
3219 // We may already have an enum of the same name; try to find and match it.
3220 EnumDecl *PrevDecl = nullptr;
3221 if (!DC->isFunctionOrMethod()) {
3222 SmallVector<NamedDecl *, 4> ConflictingDecls;
3223 auto FoundDecls =
3224 Importer.findDeclsInToCtx(DC, SearchName);
3225 for (auto *FoundDecl : FoundDecls) {
3226 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3227 continue;
3228
3229 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3230 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3231 FoundDecl = Tag->getDecl();
3232 }
3233
3234 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3235 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3236 continue;
3237 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3238 EnumDecl *FoundDef = FoundEnum->getDefinition();
3239 if (D->isThisDeclarationADefinition() && FoundDef)
3240 return Importer.MapImported(D, FoundDef);
3241 PrevDecl = FoundEnum->getMostRecentDecl();
3242 break;
3243 }
3244 ConflictingDecls.push_back(FoundDecl);
3245 }
3246 }
3247
3248 // In case of unnamed enums, we try to find an existing similar one, if none
3249 // was found, perform the import always.
3250 // Structural in-equivalence is not detected in this way here, but it may
3251 // be found when the parent decl is imported (if the enum is part of a
3252 // class). To make this totally exact a more difficult solution is needed.
3253 if (SearchName && !ConflictingDecls.empty()) {
3254 ExpectedName NameOrErr = Importer.HandleNameConflict(
3255 SearchName, DC, IDNS, ConflictingDecls.data(),
3256 ConflictingDecls.size());
3257 if (NameOrErr)
3258 Name = NameOrErr.get();
3259 else
3260 return NameOrErr.takeError();
3261 }
3262 }
3263
3264 Error Err = Error::success();
3265 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3266 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3267 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3268 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3269 if (Err)
3270 return std::move(Err);
3271
3272 // Create the enum declaration.
3273 EnumDecl *D2;
3274 if (GetImportedOrCreateDecl(
3275 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3276 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3277 D->isScopedUsingClassTag(), D->isFixed()))
3278 return D2;
3279
3280 D2->setQualifierInfo(ToQualifierLoc);
3281 D2->setIntegerType(ToIntegerType);
3282 D2->setBraceRange(ToBraceRange);
3283 D2->setAccess(D->getAccess());
3284 D2->setLexicalDeclContext(LexicalDC);
3285 addDeclToContexts(D, D2);
3286
3288 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3289 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3290 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3291 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3292 else
3293 return ToInstOrErr.takeError();
3294 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3296 else
3297 return POIOrErr.takeError();
3298 }
3299
3300 // Import the definition
3301 if (D->isCompleteDefinition())
3302 if (Error Err = ImportDefinition(D, D2))
3303 return std::move(Err);
3304
3305 return D2;
3306}
3307
3309 bool IsFriendTemplate = false;
3310 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3311 IsFriendTemplate =
3312 DCXX->getDescribedClassTemplate() &&
3313 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3315 }
3316
3317 // Import the major distinguishing characteristics of this record.
3318 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3319 DeclarationName Name;
3320 SourceLocation Loc;
3321 NamedDecl *ToD = nullptr;
3322 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3323 return std::move(Err);
3324 if (ToD)
3325 return ToD;
3326
3327 // Figure out what structure name we're looking for.
3328 unsigned IDNS = Decl::IDNS_Tag;
3329 DeclarationName SearchName = Name;
3330 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3331 if (Error Err = importInto(
3332 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3333 return std::move(Err);
3334 IDNS = Decl::IDNS_Ordinary;
3335 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3337
3338 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3339 : DC->isDependentContext();
3340 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3341
3342 // We may already have a record of the same name; try to find and match it.
3343 RecordDecl *PrevDecl = nullptr;
3344 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3345 SmallVector<NamedDecl *, 4> ConflictingDecls;
3346 auto FoundDecls =
3347 Importer.findDeclsInToCtx(DC, SearchName);
3348 if (!FoundDecls.empty()) {
3349 // We're going to have to compare D against potentially conflicting Decls,
3350 // so complete it.
3353 }
3354
3355 for (auto *FoundDecl : FoundDecls) {
3356 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3357 continue;
3358
3359 Decl *Found = FoundDecl;
3360 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3361 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3362 Found = Tag->getDecl();
3363 }
3364
3365 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3366 // Do not emit false positive diagnostic in case of unnamed
3367 // struct/union and in case of anonymous structs. Would be false
3368 // because there may be several anonymous/unnamed structs in a class.
3369 // E.g. these are both valid:
3370 // struct A { // unnamed structs
3371 // struct { struct A *next; } entry0;
3372 // struct { struct A *next; } entry1;
3373 // };
3374 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3375 if (!SearchName)
3376 if (!IsStructuralMatch(D, FoundRecord, false))
3377 continue;
3378
3379 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3380 continue;
3381
3382 if (IsStructuralMatch(D, FoundRecord)) {
3383 RecordDecl *FoundDef = FoundRecord->getDefinition();
3384 if (D->isThisDeclarationADefinition() && FoundDef) {
3385 // FIXME: Structural equivalence check should check for same
3386 // user-defined methods.
3387 Importer.MapImported(D, FoundDef);
3388 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3389 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3390 assert(FoundCXX && "Record type mismatch");
3391
3392 if (!Importer.isMinimalImport())
3393 // FoundDef may not have every implicit method that D has
3394 // because implicit methods are created only if they are used.
3395 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3396 return std::move(Err);
3397 }
3398 // FIXME: We can return FoundDef here.
3399 }
3400 PrevDecl = FoundRecord->getMostRecentDecl();
3401 break;
3402 }
3403 ConflictingDecls.push_back(FoundDecl);
3404 } // kind is RecordDecl
3405 } // for
3406
3407 if (!ConflictingDecls.empty() && SearchName) {
3408 ExpectedName NameOrErr = Importer.HandleNameConflict(
3409 SearchName, DC, IDNS, ConflictingDecls.data(),
3410 ConflictingDecls.size());
3411 if (NameOrErr)
3412 Name = NameOrErr.get();
3413 else
3414 return NameOrErr.takeError();
3415 }
3416 }
3417
3418 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3419 if (!BeginLocOrErr)
3420 return BeginLocOrErr.takeError();
3421
3422 // Create the record declaration.
3423 RecordDecl *D2 = nullptr;
3424 CXXRecordDecl *D2CXX = nullptr;
3425 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3426 if (DCXX->isLambda()) {
3427 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3428 if (!TInfoOrErr)
3429 return TInfoOrErr.takeError();
3430 if (GetImportedOrCreateSpecialDecl(
3431 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3432 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3433 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3434 return D2CXX;
3435 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3436 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3437 if (!CDeclOrErr)
3438 return CDeclOrErr.takeError();
3439 Numbering.ContextDecl = *CDeclOrErr;
3440 D2CXX->setLambdaNumbering(Numbering);
3441 } else {
3442 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3443 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3444 Name.getAsIdentifierInfo(),
3445 cast_or_null<CXXRecordDecl>(PrevDecl)))
3446 return D2CXX;
3447 }
3448
3449 D2 = D2CXX;
3450 D2->setAccess(D->getAccess());
3451 D2->setLexicalDeclContext(LexicalDC);
3452 addDeclToContexts(D, D2);
3453
3454 if (ClassTemplateDecl *FromDescribed =
3455 DCXX->getDescribedClassTemplate()) {
3456 ClassTemplateDecl *ToDescribed;
3457 if (Error Err = importInto(ToDescribed, FromDescribed))
3458 return std::move(Err);
3459 D2CXX->setDescribedClassTemplate(ToDescribed);
3460 } else if (MemberSpecializationInfo *MemberInfo =
3461 DCXX->getMemberSpecializationInfo()) {
3463 MemberInfo->getTemplateSpecializationKind();
3465
3466 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3467 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3468 else
3469 return ToInstOrErr.takeError();
3470
3471 if (ExpectedSLoc POIOrErr =
3472 import(MemberInfo->getPointOfInstantiation()))
3474 *POIOrErr);
3475 else
3476 return POIOrErr.takeError();
3477 }
3478
3479 } else {
3480 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3481 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3482 Name.getAsIdentifierInfo(), PrevDecl))
3483 return D2;
3484 D2->setLexicalDeclContext(LexicalDC);
3485 addDeclToContexts(D, D2);
3486 }
3487
3488 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3489 D2->setBraceRange(*BraceRangeOrErr);
3490 else
3491 return BraceRangeOrErr.takeError();
3492 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3493 D2->setQualifierInfo(*QualifierLocOrErr);
3494 else
3495 return QualifierLocOrErr.takeError();
3496
3497 if (D->isAnonymousStructOrUnion())
3498 D2->setAnonymousStructOrUnion(true);
3499
3500 if (D->isCompleteDefinition())
3501 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3502 return std::move(Err);
3503
3504 return D2;
3505}
3506
3508 // Import the major distinguishing characteristics of this enumerator.
3509 DeclContext *DC, *LexicalDC;
3510 DeclarationName Name;
3511 SourceLocation Loc;
3512 NamedDecl *ToD;
3513 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3514 return std::move(Err);
3515 if (ToD)
3516 return ToD;
3517
3518 // Determine whether there are any other declarations with the same name and
3519 // in the same context.
3520 if (!LexicalDC->isFunctionOrMethod()) {
3521 SmallVector<NamedDecl *, 4> ConflictingDecls;
3522 unsigned IDNS = Decl::IDNS_Ordinary;
3523 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3524 for (auto *FoundDecl : FoundDecls) {
3525 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3526 continue;
3527
3528 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3529 if (IsStructuralMatch(D, FoundEnumConstant))
3530 return Importer.MapImported(D, FoundEnumConstant);
3531 ConflictingDecls.push_back(FoundDecl);
3532 }
3533 }
3534
3535 if (!ConflictingDecls.empty()) {
3536 ExpectedName NameOrErr = Importer.HandleNameConflict(
3537 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3538 if (NameOrErr)
3539 Name = NameOrErr.get();
3540 else
3541 return NameOrErr.takeError();
3542 }
3543 }
3544
3545 ExpectedType TypeOrErr = import(D->getType());
3546 if (!TypeOrErr)
3547 return TypeOrErr.takeError();
3548
3549 ExpectedExpr InitOrErr = import(D->getInitExpr());
3550 if (!InitOrErr)
3551 return InitOrErr.takeError();
3552
3553 EnumConstantDecl *ToEnumerator;
3554 if (GetImportedOrCreateDecl(
3555 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3556 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3557 return ToEnumerator;
3558
3559 ToEnumerator->setAccess(D->getAccess());
3560 ToEnumerator->setLexicalDeclContext(LexicalDC);
3561 LexicalDC->addDeclInternal(ToEnumerator);
3562 return ToEnumerator;
3563}
3564
3565template <typename DeclTy>
3567 DeclTy *ToD) {
3568 unsigned int Num = FromD->getNumTemplateParameterLists();
3569 if (Num == 0)
3570 return Error::success();
3572 for (unsigned int I = 0; I < Num; ++I)
3573 if (Expected<TemplateParameterList *> ToTPListOrErr =
3574 import(FromD->getTemplateParameterList(I)))
3575 ToTPLists[I] = *ToTPListOrErr;
3576 else
3577 return ToTPListOrErr.takeError();
3578 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3579 return Error::success();
3580}
3581
3583 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3584 switch (FromFD->getTemplatedKind()) {
3587 return Error::success();
3588
3590 if (Expected<FunctionDecl *> InstFDOrErr =
3591 import(FromFD->getInstantiatedFromDecl()))
3592 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3593 return Error::success();
3596
3597 if (Expected<FunctionDecl *> InstFDOrErr =
3598 import(FromFD->getInstantiatedFromMemberFunction()))
3599 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3600 else
3601 return InstFDOrErr.takeError();
3602
3603 if (ExpectedSLoc POIOrErr = import(
3606 else
3607 return POIOrErr.takeError();
3608
3609 return Error::success();
3610 }
3611
3613 auto FunctionAndArgsOrErr =
3615 if (!FunctionAndArgsOrErr)
3616 return FunctionAndArgsOrErr.takeError();
3617
3619 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3620
3621 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3622 TemplateArgumentListInfo ToTAInfo;
3623 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3624 if (FromTAArgsAsWritten)
3626 *FromTAArgsAsWritten, ToTAInfo))
3627 return Err;
3628
3629 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3630 if (!POIOrErr)
3631 return POIOrErr.takeError();
3632
3633 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3634 return Err;
3635
3636 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3637 ToFD->setFunctionTemplateSpecialization(
3638 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3639 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3640 return Error::success();
3641 }
3642
3644 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3645 UnresolvedSet<8> Candidates;
3646 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3647 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3648 Candidates.addDecl(*ToFTDOrErr);
3649 else
3650 return ToFTDOrErr.takeError();
3651 }
3652
3653 // Import TemplateArgumentListInfo.
3654 TemplateArgumentListInfo ToTAInfo;
3655 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3656 if (FromTAArgsAsWritten)
3657 if (Error Err =
3658 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3659 return Err;
3660
3662 Importer.getToContext(), Candidates,
3663 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3664 return Error::success();
3665 }
3666 }
3667 llvm_unreachable("All cases should be covered!");
3668}
3669
3672 auto FunctionAndArgsOrErr =
3674 if (!FunctionAndArgsOrErr)
3675 return FunctionAndArgsOrErr.takeError();
3676
3678 TemplateArgsTy ToTemplArgs;
3679 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3680 void *InsertPos = nullptr;
3681 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3682 return FoundSpec;
3683}
3684
3686 FunctionDecl *ToFD) {
3687 if (Stmt *FromBody = FromFD->getBody()) {
3688 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3689 ToFD->setBody(*ToBodyOrErr);
3690 else
3691 return ToBodyOrErr.takeError();
3692 }
3693 return Error::success();
3694}
3695
3696// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3697// which is equal to the given DC, or D is equal to DC.
3698static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3699 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3700 if (!DCi)
3701 DCi = D->getDeclContext();
3702 assert(DCi && "Declaration should have a context");
3703 while (DCi != D->getTranslationUnitDecl()) {
3704 if (DCi == DC)
3705 return true;
3706 DCi = DCi->getParent();
3707 }
3708 return false;
3709}
3710
3711// Check if there is a declaration that has 'DC' as parent context and is
3712// referenced from statement 'S' or one of its children. The search is done in
3713// BFS order through children of 'S'.
3714static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3715 SmallVector<const Stmt *> ToProcess;
3716 ToProcess.push_back(S);
3717 while (!ToProcess.empty()) {
3718 const Stmt *CurrentS = ToProcess.pop_back_val();
3719 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3720 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3721 if (const Decl *D = DeclRef->getDecl())
3722 if (isAncestorDeclContextOf(DC, D))
3723 return true;
3724 } else if (const auto *E =
3725 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3726 if (const Decl *D = E->getAssociatedDecl())
3727 if (isAncestorDeclContextOf(DC, D))
3728 return true;
3729 }
3730 }
3731 return false;
3732}
3733
3734namespace {
3735/// Check if a type has any reference to a declaration that is inside the body
3736/// of a function.
3737/// The \c CheckType(QualType) function should be used to determine
3738/// this property.
3739///
3740/// The type visitor visits one type object only (not recursive).
3741/// To find all referenced declarations we must discover all type objects until
3742/// the canonical type is reached (walk over typedef and similar objects). This
3743/// is done by loop over all "sugar" type objects. For every such type we must
3744/// check all declarations that are referenced from it. For this check the
3745/// visitor is used. In the visit functions all referenced declarations except
3746/// the one that follows in the sugar chain (if any) must be checked. For this
3747/// check the same visitor is re-used (it has no state-dependent data).
3748///
3749/// The visit functions have 3 possible return values:
3750/// - True, found a declaration inside \c ParentDC.
3751/// - False, found declarations only outside \c ParentDC and it is not possible
3752/// to find more declarations (the "sugar" chain does not continue).
3753/// - Empty optional value, found no declarations or only outside \c ParentDC,
3754/// but it is possible to find more declarations in the type "sugar" chain.
3755/// The loop over the "sugar" types can be implemented by using type visit
3756/// functions only (call \c CheckType with the desugared type). With the current
3757/// solution no visit function is needed if the type has only a desugared type
3758/// as data.
3759class IsTypeDeclaredInsideVisitor
3760 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3761public:
3762 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3763 : ParentDC(ParentDC) {}
3764
3765 bool CheckType(QualType T) {
3766 // Check the chain of "sugar" types.
3767 // The "sugar" types are typedef or similar types that have the same
3768 // canonical type.
3769 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3770 return *Res;
3771 QualType DsT =
3772 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3773 while (DsT != T) {
3774 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3775 return *Res;
3776 T = DsT;
3777 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3778 }
3779 return false;
3780 }
3781
3782 std::optional<bool> VisitTagType(const TagType *T) {
3783 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3784 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3785 if (checkTemplateArgument(Arg))
3786 return true;
3787 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3788 }
3789
3790 std::optional<bool> VisitPointerType(const PointerType *T) {
3791 return CheckType(T->getPointeeType());
3792 }
3793
3794 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3795 return CheckType(T->getPointeeTypeAsWritten());
3796 }
3797
3798 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3799 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3800 }
3801
3802 std::optional<bool> VisitUsingType(const UsingType *T) {
3803 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3804 }
3805
3806 std::optional<bool>
3807 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3808 for (const auto &Arg : T->template_arguments())
3809 if (checkTemplateArgument(Arg))
3810 return true;
3811 // This type is a "sugar" to a record type, it can have a desugared type.
3812 return {};
3813 }
3814
3815 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3816 return CheckType(T->getBaseType());
3817 }
3818
3819 std::optional<bool>
3820 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3821 // The "associated declaration" can be the same as ParentDC.
3822 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3823 return true;
3824 return {};
3825 }
3826
3827 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3828 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3829 return true;
3830
3831 return CheckType(T->getElementType());
3832 }
3833
3834 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3835 llvm_unreachable(
3836 "Variable array should not occur in deduced return type of a function");
3837 }
3838
3839 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3840 llvm_unreachable("Incomplete array should not occur in deduced return type "
3841 "of a function");
3842 }
3843
3844 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3845 llvm_unreachable("Dependent array should not occur in deduced return type "
3846 "of a function");
3847 }
3848
3849private:
3850 const DeclContext *const ParentDC;
3851
3852 bool checkTemplateArgument(const TemplateArgument &Arg) {
3853 switch (Arg.getKind()) {
3855 return false;
3857 return CheckType(Arg.getIntegralType());
3859 return CheckType(Arg.getAsType());
3861 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3863 // FIXME: The declaration in this case is not allowed to be in a function?
3864 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3866 // FIXME: The type is not allowed to be in the function?
3867 return CheckType(Arg.getNullPtrType());
3869 return CheckType(Arg.getStructuralValueType());
3871 for (const auto &PackArg : Arg.getPackAsArray())
3872 if (checkTemplateArgument(PackArg))
3873 return true;
3874 return false;
3876 // Templates can not be defined locally in functions.
3877 // A template passed as argument can be not in ParentDC.
3878 return false;
3880 // Templates can not be defined locally in functions.
3881 // A template passed as argument can be not in ParentDC.
3882 return false;
3883 }
3884 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3885 };
3886};
3887} // namespace
3888
3889/// This function checks if the given function has a return type that contains
3890/// a reference (in any way) to a declaration inside the same function.
3892 QualType FromTy = D->getType();
3893 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3894 assert(FromFPT && "Must be called on FunctionProtoType");
3895
3896 auto IsCXX11Lambda = [&]() {
3897 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3898 return false;
3899
3900 return isLambdaMethod(D);
3901 };
3902
3903 QualType RetT = FromFPT->getReturnType();
3904 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3905 FunctionDecl *Def = D->getDefinition();
3906 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3907 return Visitor.CheckType(RetT);
3908 }
3909
3910 return false;
3911}
3912
3914ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3915 Expr *ExplicitExpr = ESpec.getExpr();
3916 if (ExplicitExpr)
3917 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3918 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3919}
3920
3922
3924 auto RedeclIt = Redecls.begin();
3925 // Import the first part of the decl chain. I.e. import all previous
3926 // declarations starting from the canonical decl.
3927 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3928 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3929 if (!ToRedeclOrErr)
3930 return ToRedeclOrErr.takeError();
3931 }
3932 assert(*RedeclIt == D);
3933
3934 // Import the major distinguishing characteristics of this function.
3935 DeclContext *DC, *LexicalDC;
3936 DeclarationName Name;
3937 SourceLocation Loc;
3938 NamedDecl *ToD;
3939 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3940 return std::move(Err);
3941 if (ToD)
3942 return ToD;
3943
3944 FunctionDecl *FoundByLookup = nullptr;
3946
3947 // If this is a function template specialization, then try to find the same
3948 // existing specialization in the "to" context. The lookup below will not
3949 // find any specialization, but would find the primary template; thus, we
3950 // have to skip normal lookup in case of specializations.
3951 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3952 if (D->getTemplatedKind() ==
3954 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3955 if (!FoundFunctionOrErr)
3956 return FoundFunctionOrErr.takeError();
3957 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3958 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3959 return Def;
3960 FoundByLookup = FoundFunction;
3961 }
3962 }
3963 // Try to find a function in our own ("to") context with the same name, same
3964 // type, and in the same context as the function we're importing.
3965 else if (!LexicalDC->isFunctionOrMethod()) {
3966 SmallVector<NamedDecl *, 4> ConflictingDecls;
3968 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3969 for (auto *FoundDecl : FoundDecls) {
3970 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3971 continue;
3972
3973 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3974 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3975 continue;
3976
3977 if (IsStructuralMatch(D, FoundFunction)) {
3978 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3979 return Def;
3980 FoundByLookup = FoundFunction;
3981 break;
3982 }
3983 // FIXME: Check for overloading more carefully, e.g., by boosting
3984 // Sema::IsOverload out to the AST library.
3985
3986 // Function overloading is okay in C++.
3987 if (Importer.getToContext().getLangOpts().CPlusPlus)
3988 continue;
3989
3990 // Complain about inconsistent function types.
3991 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3992 << Name << D->getType() << FoundFunction->getType();
3993 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3994 << FoundFunction->getType();
3995 ConflictingDecls.push_back(FoundDecl);
3996 }
3997 }
3998
3999 if (!ConflictingDecls.empty()) {
4000 ExpectedName NameOrErr = Importer.HandleNameConflict(
4001 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4002 if (NameOrErr)
4003 Name = NameOrErr.get();
4004 else
4005 return NameOrErr.takeError();
4006 }
4007 }
4008
4009 // We do not allow more than one in-class declaration of a function. This is
4010 // because AST clients like VTableBuilder asserts on this. VTableBuilder
4011 // assumes there is only one in-class declaration. Building a redecl
4012 // chain would result in more than one in-class declaration for
4013 // overrides (even if they are part of the same redecl chain inside the
4014 // derived class.)
4015 if (FoundByLookup) {
4016 if (isa<CXXMethodDecl>(FoundByLookup)) {
4017 if (D->getLexicalDeclContext() == D->getDeclContext()) {
4018 if (!D->doesThisDeclarationHaveABody()) {
4019 if (FunctionTemplateDecl *DescribedD =
4021 // Handle a "templated" function together with its described
4022 // template. This avoids need for a similar check at import of the
4023 // described template.
4024 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4025 "Templated function mapped to non-templated?");
4026 Importer.MapImported(DescribedD,
4027 FoundByLookup->getDescribedFunctionTemplate());
4028 }
4029 return Importer.MapImported(D, FoundByLookup);
4030 } else {
4031 // Let's continue and build up the redecl chain in this case.
4032 // FIXME Merge the functions into one decl.
4033 }
4034 }
4035 }
4036 }
4037
4038 DeclarationNameInfo NameInfo(Name, Loc);
4039 // Import additional name location/type info.
4040 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4041 return std::move(Err);
4042
4043 QualType FromTy = D->getType();
4044 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4045 // Set to true if we do not import the type of the function as is. There are
4046 // cases when the original type would result in an infinite recursion during
4047 // the import. To avoid an infinite recursion when importing, we create the
4048 // FunctionDecl with a simplified function type and update it only after the
4049 // relevant AST nodes are already imported.
4050 // The type is related to TypeSourceInfo (it references the type), so we must
4051 // do the same with TypeSourceInfo.
4052 bool UsedDifferentProtoType = false;
4053 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4054 QualType FromReturnTy = FromFPT->getReturnType();
4055 // Functions with auto return type may define a struct inside their body
4056 // and the return type could refer to that struct.
4057 // E.g.: auto foo() { struct X{}; return X(); }
4058 // To avoid an infinite recursion when importing, create the FunctionDecl
4059 // with a simplified return type.
4060 // Reuse this approach for auto return types declared as typenames from
4061 // template params, tracked in FindFunctionDeclImportCycle.
4063 Importer.FindFunctionDeclImportCycle.isCycle(D)) {
4064 FromReturnTy = Importer.getFromContext().VoidTy;
4065 UsedDifferentProtoType = true;
4066 }
4067 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4068 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4069 // FunctionDecl that we are importing the FunctionProtoType for.
4070 // To avoid an infinite recursion when importing, create the FunctionDecl
4071 // with a simplified function type.
4072 if (FromEPI.ExceptionSpec.SourceDecl ||
4073 FromEPI.ExceptionSpec.SourceTemplate ||
4074 FromEPI.ExceptionSpec.NoexceptExpr) {
4076 FromEPI = DefaultEPI;
4077 UsedDifferentProtoType = true;
4078 }
4079 FromTy = Importer.getFromContext().getFunctionType(
4080 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4081 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4082 FromTy, D->getBeginLoc());
4083 }
4084
4085 Error Err = Error::success();
4086 auto ScopedReturnTypeDeclCycleDetector =
4087 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
4088 auto T = importChecked(Err, FromTy);
4089 auto TInfo = importChecked(Err, FromTSI);
4090 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4091 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4092 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4093 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4094 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4095 TrailingRequiresClause.ConstraintExpr =
4096 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4097 if (Err)
4098 return std::move(Err);
4099
4100 // Import the function parameters.
4102 for (auto *P : D->parameters()) {
4103 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4104 Parameters.push_back(*ToPOrErr);
4105 else
4106 return ToPOrErr.takeError();
4107 }
4108
4109 // Create the imported function.
4110 FunctionDecl *ToFunction = nullptr;
4111 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4112 ExplicitSpecifier ESpec =
4113 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4114 if (Err)
4115 return std::move(Err);
4116 auto ToInheritedConstructor = InheritedConstructor();
4117 if (FromConstructor->isInheritingConstructor()) {
4118 Expected<InheritedConstructor> ImportedInheritedCtor =
4119 import(FromConstructor->getInheritedConstructor());
4120 if (!ImportedInheritedCtor)
4121 return ImportedInheritedCtor.takeError();
4122 ToInheritedConstructor = *ImportedInheritedCtor;
4123 }
4124 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4125 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4126 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4128 ToInheritedConstructor, TrailingRequiresClause))
4129 return ToFunction;
4130 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4131
4132 Error Err = Error::success();
4133 auto ToOperatorDelete = importChecked(
4134 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4135 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4136 if (Err)
4137 return std::move(Err);
4138
4139 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4140 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4141 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4143 TrailingRequiresClause))
4144 return ToFunction;
4145
4146 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4147
4148 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4149 } else if (CXXConversionDecl *FromConversion =
4150 dyn_cast<CXXConversionDecl>(D)) {
4151 ExplicitSpecifier ESpec =
4152 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4153 if (Err)
4154 return std::move(Err);
4155 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4156 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4157 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4158 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4159 SourceLocation(), TrailingRequiresClause))
4160 return ToFunction;
4161 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4162 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4163 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4164 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4165 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4166 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4167 return ToFunction;
4168 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4169 ExplicitSpecifier ESpec =
4170 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4171 CXXConstructorDecl *Ctor =
4172 importChecked(Err, Guide->getCorrespondingConstructor());
4173 const CXXDeductionGuideDecl *SourceDG =
4174 importChecked(Err, Guide->getSourceDeductionGuide());
4175 if (Err)
4176 return std::move(Err);
4177 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4178 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4179 NameInfo, T, TInfo, ToEndLoc, Ctor,
4180 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4181 SourceDG, Guide->getSourceDeductionGuideKind()))
4182 return ToFunction;
4183 } else {
4184 if (GetImportedOrCreateDecl(
4185 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4186 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4188 D->getConstexprKind(), TrailingRequiresClause))
4189 return ToFunction;
4190 }
4191
4192 // Connect the redecl chain.
4193 if (FoundByLookup) {
4194 auto *Recent = const_cast<FunctionDecl *>(
4195 FoundByLookup->getMostRecentDecl());
4196 ToFunction->setPreviousDecl(Recent);
4197 // FIXME Probably we should merge exception specifications. E.g. In the
4198 // "To" context the existing function may have exception specification with
4199 // noexcept-unevaluated, while the newly imported function may have an
4200 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4201 // decl and its redeclarations may be required.
4202 }
4203
4204 StringLiteral *Msg = D->getDeletedMessage();
4205 if (Msg) {
4206 auto Imported = import(Msg);
4207 if (!Imported)
4208 return Imported.takeError();
4209 Msg = *Imported;
4210 }
4211
4212 ToFunction->setQualifierInfo(ToQualifierLoc);
4213 ToFunction->setAccess(D->getAccess());
4214 ToFunction->setLexicalDeclContext(LexicalDC);
4215 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4216 ToFunction->setTrivial(D->isTrivial());
4217 ToFunction->setIsPureVirtual(D->isPureVirtual());
4218 ToFunction->setDefaulted(D->isDefaulted());
4220 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4226 ToFunction->setRangeEnd(ToEndLoc);
4227 ToFunction->setDefaultLoc(ToDefaultLoc);
4228
4229 if (Msg)
4230 ToFunction->setDefaultedOrDeletedInfo(
4232 Importer.getToContext(), {}, Msg));
4233
4234 // Set the parameters.
4235 for (auto *Param : Parameters) {
4236 Param->setOwningFunction(ToFunction);
4237 ToFunction->addDeclInternal(Param);
4238 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4239 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4240 }
4241 ToFunction->setParams(Parameters);
4242
4243 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4244 // params it refers to.
4245 if (TInfo) {
4246 if (auto ProtoLoc =
4247 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4248 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4249 ProtoLoc.setParam(I, Parameters[I]);
4250 }
4251 }
4252
4253 // Import the describing template function, if any.
4254 if (FromFT) {
4255 auto ToFTOrErr = import(FromFT);
4256 if (!ToFTOrErr)
4257 return ToFTOrErr.takeError();
4258 }
4259
4260 // Import Ctor initializers.
4261 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4262 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4263 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4264 // Import first, then allocate memory and copy if there was no error.
4265 if (Error Err = ImportContainerChecked(
4266 FromConstructor->inits(), CtorInitializers))
4267 return std::move(Err);
4268 auto **Memory =
4269 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4270 llvm::copy(CtorInitializers, Memory);
4271 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4272 ToCtor->setCtorInitializers(Memory);
4273 ToCtor->setNumCtorInitializers(NumInitializers);
4274 }
4275 }
4276
4277 // If it is a template, import all related things.
4278 if (Error Err = ImportTemplateInformation(D, ToFunction))
4279 return std::move(Err);
4280
4281 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4283 FromCXXMethod))
4284 return std::move(Err);
4285
4287 Error Err = ImportFunctionDeclBody(D, ToFunction);
4288
4289 if (Err)
4290 return std::move(Err);
4291 }
4292
4293 // Import and set the original type in case we used another type.
4294 if (UsedDifferentProtoType) {
4295 if (ExpectedType TyOrErr = import(D->getType()))
4296 ToFunction->setType(*TyOrErr);
4297 else
4298 return TyOrErr.takeError();
4299 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4300 ToFunction->setTypeSourceInfo(*TSIOrErr);
4301 else
4302 return TSIOrErr.takeError();
4303 }
4304
4305 // FIXME: Other bits to merge?
4306
4307 addDeclToContexts(D, ToFunction);
4308
4309 // Import the rest of the chain. I.e. import all subsequent declarations.
4310 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4311 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4312 if (!ToRedeclOrErr)
4313 return ToRedeclOrErr.takeError();
4314 }
4315
4316 return ToFunction;
4317}
4318
4322
4326
4330
4334
4339
4341 // Import the major distinguishing characteristics of a variable.
4342 DeclContext *DC, *LexicalDC;
4343 DeclarationName Name;
4344 SourceLocation Loc;
4345 NamedDecl *ToD;
4346 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4347 return std::move(Err);
4348 if (ToD)
4349 return ToD;
4350
4351 // Determine whether we've already imported this field.
4352 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4353 for (auto *FoundDecl : FoundDecls) {
4354 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4355 // For anonymous fields, match up by index.
4356 if (!Name &&
4358 ASTImporter::getFieldIndex(FoundField))
4359 continue;
4360
4361 if (Importer.IsStructurallyEquivalent(D->getType(),
4362 FoundField->getType())) {
4363 Importer.MapImported(D, FoundField);
4364 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4365 // initializer of a FieldDecl might not had been instantiated in the
4366 // "To" context. However, the "From" context might instantiated that,
4367 // thus we have to merge that.
4368 // Note: `hasInClassInitializer()` is not the same as non-null
4369 // `getInClassInitializer()` value.
4370 if (Expr *FromInitializer = D->getInClassInitializer()) {
4371 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4372 // Import of the FromInitializer may result in the setting of
4373 // InClassInitializer. If not, set it here.
4374 assert(FoundField->hasInClassInitializer() &&
4375 "Field should have an in-class initializer if it has an "
4376 "expression for it.");
4377 if (!FoundField->getInClassInitializer())
4378 FoundField->setInClassInitializer(*ToInitializerOrErr);
4379 } else {
4380 return ToInitializerOrErr.takeError();
4381 }
4382 }
4383 return FoundField;
4384 }
4385
4386 // FIXME: Why is this case not handled with calling HandleNameConflict?
4387 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4388 << Name << D->getType() << FoundField->getType();
4389 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4390 << FoundField->getType();
4391
4392 return make_error<ASTImportError>(ASTImportError::NameConflict);
4393 }
4394 }
4395
4396 Error Err = Error::success();
4397 auto ToType = importChecked(Err, D->getType());
4398 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4399 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4400 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4401 if (Err)
4402 return std::move(Err);
4403 const Type *ToCapturedVLAType = nullptr;
4404 if (Error Err = Importer.importInto(
4405 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4406 return std::move(Err);
4407
4408 FieldDecl *ToField;
4409 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4410 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4411 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4412 D->getInClassInitStyle()))
4413 return ToField;
4414
4415 ToField->setAccess(D->getAccess());
4416 ToField->setLexicalDeclContext(LexicalDC);
4417 ToField->setImplicit(D->isImplicit());
4418 if (ToCapturedVLAType)
4419 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4420 LexicalDC->addDeclInternal(ToField);
4421 // Import initializer only after the field was created, it may have recursive
4422 // reference to the field.
4423 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4424 if (Err)
4425 return std::move(Err);
4426 if (ToInitializer) {
4427 auto *AlreadyImported = ToField->getInClassInitializer();
4428 if (AlreadyImported)
4429 assert(ToInitializer == AlreadyImported &&
4430 "Duplicate import of in-class initializer.");
4431 else
4432 ToField->setInClassInitializer(ToInitializer);
4433 }
4434
4435 return ToField;
4436}
4437
4439 // Import the major distinguishing characteristics of a variable.
4440 DeclContext *DC, *LexicalDC;
4441 DeclarationName Name;
4442 SourceLocation Loc;
4443 NamedDecl *ToD;
4444 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4445 return std::move(Err);
4446 if (ToD)
4447 return ToD;
4448
4449 // Determine whether we've already imported this field.
4450 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4451 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4452 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4453 // For anonymous indirect fields, match up by index.
4454 if (!Name &&
4456 ASTImporter::getFieldIndex(FoundField))
4457 continue;
4458
4459 if (Importer.IsStructurallyEquivalent(D->getType(),
4460 FoundField->getType(),
4461 !Name.isEmpty())) {
4462 Importer.MapImported(D, FoundField);
4463 return FoundField;
4464 }
4465
4466 // If there are more anonymous fields to check, continue.
4467 if (!Name && I < N-1)
4468 continue;
4469
4470 // FIXME: Why is this case not handled with calling HandleNameConflict?
4471 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4472 << Name << D->getType() << FoundField->getType();
4473 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4474 << FoundField->getType();
4475
4476 return make_error<ASTImportError>(ASTImportError::NameConflict);
4477 }
4478 }
4479
4480 // Import the type.
4481 auto TypeOrErr = import(D->getType());
4482 if (!TypeOrErr)
4483 return TypeOrErr.takeError();
4484
4485 auto **NamedChain =
4486 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4487
4488 unsigned i = 0;
4489 for (auto *PI : D->chain())
4490 if (Expected<NamedDecl *> ToD = import(PI))
4491 NamedChain[i++] = *ToD;
4492 else
4493 return ToD.takeError();
4494
4495 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4496 IndirectFieldDecl *ToIndirectField;
4497 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4498 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4499 // FIXME here we leak `NamedChain` which is allocated before
4500 return ToIndirectField;
4501
4502 ToIndirectField->setAccess(D->getAccess());
4503 ToIndirectField->setLexicalDeclContext(LexicalDC);
4504 LexicalDC->addDeclInternal(ToIndirectField);
4505 return ToIndirectField;
4506}
4507
4508/// Used as return type of getFriendCountAndPosition.
4510 /// Number of similar looking friends.
4511 unsigned int TotalCount;
4512 /// Index of the specific FriendDecl.
4513 unsigned int IndexOfDecl;
4514};
4515
4516static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4517 FriendDecl *FD2) {
4518 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4519 return false;
4520
4521 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4522 return Importer.IsStructurallyEquivalent(
4523 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4524
4525 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4527 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4528 FD2->getASTContext(), NonEquivalentDecls,
4530 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4531 return Ctx.IsEquivalent(FD1, FD2);
4532}
4533
4535 FriendDecl *FD) {
4536 unsigned int FriendCount = 0;
4537 UnsignedOrNone FriendPosition = std::nullopt;
4538 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4539
4540 for (FriendDecl *FoundFriend : RD->friends()) {
4541 if (FoundFriend == FD) {
4542 FriendPosition = FriendCount;
4543 ++FriendCount;
4544 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4545 ++FriendCount;
4546 }
4547 }
4548
4549 assert(FriendPosition && "Friend decl not found in own parent.");
4550
4551 return {FriendCount, *FriendPosition};
4552}
4553
4555 // Import the major distinguishing characteristics of a declaration.
4556 DeclContext *DC, *LexicalDC;
4557 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4558 return std::move(Err);
4559
4560 // Determine whether we've already imported this decl.
4561 // FriendDecl is not a NamedDecl so we cannot use lookup.
4562 // We try to maintain order and count of redundant friend declarations.
4563 const auto *RD = cast<CXXRecordDecl>(DC);
4564 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4565 for (FriendDecl *ImportedFriend : RD->friends())
4566 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4567 ImportedEquivalentFriends.push_back(ImportedFriend);
4568
4569 FriendCountAndPosition CountAndPosition =
4570 getFriendCountAndPosition(Importer, D);
4571
4572 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4573 "Class with non-matching friends is imported, ODR check wrong?");
4574 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4575 return Importer.MapImported(
4576 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4577
4578 // Not found. Create it.
4579 // The declarations will be put into order later by ImportDeclContext.
4581 if (NamedDecl *FriendD = D->getFriendDecl()) {
4582 NamedDecl *ToFriendD;
4583 if (Error Err = importInto(ToFriendD, FriendD))
4584 return std::move(Err);
4585
4586 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4587 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4588 ToFriendD->setObjectOfFriendDecl(false);
4589
4590 ToFU = ToFriendD;
4591 } else { // The friend is a type, not a decl.
4592 if (auto TSIOrErr = import(D->getFriendType()))
4593 ToFU = *TSIOrErr;
4594 else
4595 return TSIOrErr.takeError();
4596 }
4597
4598 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4599 auto **FromTPLists = D->getTrailingObjects();
4600 for (unsigned I = 0; I < D->NumTPLists; I++) {
4601 if (auto ListOrErr = import(FromTPLists[I]))
4602 ToTPLists[I] = *ListOrErr;
4603 else
4604 return ListOrErr.takeError();
4605 }
4606
4607 auto LocationOrErr = import(D->getLocation());
4608 if (!LocationOrErr)
4609 return LocationOrErr.takeError();
4610 auto FriendLocOrErr = import(D->getFriendLoc());
4611 if (!FriendLocOrErr)
4612 return FriendLocOrErr.takeError();
4613 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4614 if (!EllipsisLocOrErr)
4615 return EllipsisLocOrErr.takeError();
4616
4617 FriendDecl *FrD;
4618 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4619 *LocationOrErr, ToFU, *FriendLocOrErr,
4620 *EllipsisLocOrErr, ToTPLists))
4621 return FrD;
4622
4623 FrD->setAccess(D->getAccess());
4624 FrD->setLexicalDeclContext(LexicalDC);
4625 LexicalDC->addDeclInternal(FrD);
4626 return FrD;
4627}
4628
4630 // Import the major distinguishing characteristics of an ivar.
4631 DeclContext *DC, *LexicalDC;
4632 DeclarationName Name;
4633 SourceLocation Loc;
4634 NamedDecl *ToD;
4635 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4636 return std::move(Err);
4637 if (ToD)
4638 return ToD;
4639
4640 // Determine whether we've already imported this ivar
4641 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4642 for (auto *FoundDecl : FoundDecls) {
4643 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4644 if (Importer.IsStructurallyEquivalent(D->getType(),
4645 FoundIvar->getType())) {
4646 Importer.MapImported(D, FoundIvar);
4647 return FoundIvar;
4648 }
4649
4650 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4651 << Name << D->getType() << FoundIvar->getType();
4652 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4653 << FoundIvar->getType();
4654
4655 return make_error<ASTImportError>(ASTImportError::NameConflict);
4656 }
4657 }
4658
4659 Error Err = Error::success();
4660 auto ToType = importChecked(Err, D->getType());
4661 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4662 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4663 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4664 if (Err)
4665 return std::move(Err);
4666
4667 ObjCIvarDecl *ToIvar;
4668 if (GetImportedOrCreateDecl(
4669 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4670 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4671 ToType, ToTypeSourceInfo,
4672 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4673 return ToIvar;
4674
4675 ToIvar->setLexicalDeclContext(LexicalDC);
4676 LexicalDC->addDeclInternal(ToIvar);
4677 return ToIvar;
4678}
4679
4681
4683 auto RedeclIt = Redecls.begin();
4684 // Import the first part of the decl chain. I.e. import all previous
4685 // declarations starting from the canonical decl.
4686 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4687 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4688 if (!RedeclOrErr)
4689 return RedeclOrErr.takeError();
4690 }
4691 assert(*RedeclIt == D);
4692
4693 // Import the major distinguishing characteristics of a variable.
4694 DeclContext *DC, *LexicalDC;
4695 DeclarationName Name;
4696 SourceLocation Loc;
4697 NamedDecl *ToD;
4698 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4699 return std::move(Err);
4700 if (ToD)
4701 return ToD;
4702
4703 // Try to find a variable in our own ("to") context with the same name and
4704 // in the same context as the variable we're importing.
4705 VarDecl *FoundByLookup = nullptr;
4706 if (D->isFileVarDecl()) {
4707 SmallVector<NamedDecl *, 4> ConflictingDecls;
4708 unsigned IDNS = Decl::IDNS_Ordinary;
4709 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4710 for (auto *FoundDecl : FoundDecls) {
4711 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4712 continue;
4713
4714 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4715 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4716 continue;
4717 if (Importer.IsStructurallyEquivalent(D->getType(),
4718 FoundVar->getType())) {
4719
4720 // The VarDecl in the "From" context has a definition, but in the
4721 // "To" context we already have a definition.
4722 VarDecl *FoundDef = FoundVar->getDefinition();
4723 if (D->isThisDeclarationADefinition() && FoundDef)
4724 // FIXME Check for ODR error if the two definitions have
4725 // different initializers?
4726 return Importer.MapImported(D, FoundDef);
4727
4728 // The VarDecl in the "From" context has an initializer, but in the
4729 // "To" context we already have an initializer.
4730 const VarDecl *FoundDInit = nullptr;
4731 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4732 // FIXME Diagnose ODR error if the two initializers are different?
4733 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4734
4735 FoundByLookup = FoundVar;
4736 break;
4737 }
4738
4739 const ArrayType *FoundArray
4740 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4741 const ArrayType *TArray
4742 = Importer.getToContext().getAsArrayType(D->getType());
4743 if (FoundArray && TArray) {
4744 if (isa<IncompleteArrayType>(FoundArray) &&
4745 isa<ConstantArrayType>(TArray)) {
4746 // Import the type.
4747 if (auto TyOrErr = import(D->getType()))
4748 FoundVar->setType(*TyOrErr);
4749 else
4750 return TyOrErr.takeError();
4751
4752 FoundByLookup = FoundVar;
4753 break;
4754 } else if (isa<IncompleteArrayType>(TArray) &&
4755 isa<ConstantArrayType>(FoundArray)) {
4756 FoundByLookup = FoundVar;
4757 break;
4758 }
4759 }
4760
4761 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4762 << Name << D->getType() << FoundVar->getType();
4763 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4764 << FoundVar->getType();
4765 ConflictingDecls.push_back(FoundDecl);
4766 }
4767 }
4768
4769 if (!ConflictingDecls.empty()) {
4770 ExpectedName NameOrErr = Importer.HandleNameConflict(
4771 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4772 if (NameOrErr)
4773 Name = NameOrErr.get();
4774 else
4775 return NameOrErr.takeError();
4776 }
4777 }
4778
4779 Error Err = Error::success();
4780 auto ToType = importChecked(Err, D->getType());
4781 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4782 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4783 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4784 if (Err)
4785 return std::move(Err);
4786
4787 VarDecl *ToVar;
4788 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4789 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4790 if (Error Err =
4791 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4792 return std::move(Err);
4793 DecompositionDecl *ToDecomp;
4794 if (GetImportedOrCreateDecl(
4795 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4796 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4797 return ToDecomp;
4798 ToVar = ToDecomp;
4799 } else {
4800 // Create the imported variable.
4801 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4802 ToInnerLocStart, Loc,
4803 Name.getAsIdentifierInfo(), ToType,
4804 ToTypeSourceInfo, D->getStorageClass()))
4805 return ToVar;
4806 }
4807
4808 ToVar->setTSCSpec(D->getTSCSpec());
4809 ToVar->setQualifierInfo(ToQualifierLoc);
4810 ToVar->setAccess(D->getAccess());
4811 ToVar->setLexicalDeclContext(LexicalDC);
4812 if (D->isInlineSpecified())
4813 ToVar->setInlineSpecified();
4814 if (D->isInline())
4815 ToVar->setImplicitlyInline();
4816
4817 if (FoundByLookup) {
4818 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4819 ToVar->setPreviousDecl(Recent);
4820 }
4821
4822 // Import the described template, if any.
4823 if (D->getDescribedVarTemplate()) {
4824 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4825 if (!ToVTOrErr)
4826 return ToVTOrErr.takeError();
4828 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4830 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4831 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4832 else
4833 return ToInstOrErr.takeError();
4834 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4836 else
4837 return POIOrErr.takeError();
4838 }
4839
4840 if (Error Err = ImportInitializer(D, ToVar))
4841 return std::move(Err);
4842
4843 if (D->isConstexpr())
4844 ToVar->setConstexpr(true);
4845
4846 addDeclToContexts(D, ToVar);
4847
4848 // Import the rest of the chain. I.e. import all subsequent declarations.
4849 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4850 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4851 if (!RedeclOrErr)
4852 return RedeclOrErr.takeError();
4853 }
4854
4855 return ToVar;
4856}
4857
4859 // Parameters are created in the translation unit's context, then moved
4860 // into the function declaration's context afterward.
4861 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4862
4863 Error Err = Error::success();
4864 auto ToDeclName = importChecked(Err, D->getDeclName());
4865 auto ToLocation = importChecked(Err, D->getLocation());
4866 auto ToType = importChecked(Err, D->getType());
4867 if (Err)
4868 return std::move(Err);
4869
4870 // Create the imported parameter.
4871 ImplicitParamDecl *ToParm = nullptr;
4872 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4873 ToLocation, ToDeclName.getAsIdentifierInfo(),
4874 ToType, D->getParameterKind()))
4875 return ToParm;
4876 return ToParm;
4877}
4878
4880 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4881
4882 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4883 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4884 else
4885 return LocOrErr.takeError();
4886
4888 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4889
4890 if (FromParam->hasUninstantiatedDefaultArg()) {
4891 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4892 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4893 else
4894 return ToDefArgOrErr.takeError();
4895 } else if (FromParam->hasUnparsedDefaultArg()) {
4896 ToParam->setUnparsedDefaultArg();
4897 } else if (FromParam->hasDefaultArg()) {
4898 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4899 ToParam->setDefaultArg(*ToDefArgOrErr);
4900 else
4901 return ToDefArgOrErr.takeError();
4902 }
4903
4904 return Error::success();
4905}
4906
4909 Error Err = Error::success();
4910 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4911 ConstructorUsingShadowDecl *ToShadow =
4912 importChecked(Err, From.getShadowDecl());
4913 if (Err)
4914 return std::move(Err);
4915 return InheritedConstructor(ToShadow, ToBaseCtor);
4916}
4917
4919 // Parameters are created in the translation unit's context, then moved
4920 // into the function declaration's context afterward.
4921 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4922
4923 Error Err = Error::success();
4924 auto ToDeclName = importChecked(Err, D->getDeclName());
4925 auto ToLocation = importChecked(Err, D->getLocation());
4926 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4927 auto ToType = importChecked(Err, D->getType());
4928 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4929 if (Err)
4930 return std::move(Err);
4931
4932 ParmVarDecl *ToParm;
4933 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4934 ToInnerLocStart, ToLocation,
4935 ToDeclName.getAsIdentifierInfo(), ToType,
4936 ToTypeSourceInfo, D->getStorageClass(),
4937 /*DefaultArg*/ nullptr))
4938 return ToParm;
4939
4940 // Set the default argument. It should be no problem if it was already done.
4941 // Do not import the default expression before GetImportedOrCreateDecl call
4942 // to avoid possible infinite import loop because circular dependency.
4943 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4944 return std::move(Err);
4945
4946 if (D->isObjCMethodParameter()) {
4949 } else {
4952 }
4953
4954 return ToParm;
4955}
4956
4958 // Import the major distinguishing characteristics of a method.
4959 DeclContext *DC, *LexicalDC;
4960 DeclarationName Name;
4961 SourceLocation Loc;
4962 NamedDecl *ToD;
4963 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4964 return std::move(Err);
4965 if (ToD)
4966 return ToD;
4967
4968 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4969 for (auto *FoundDecl : FoundDecls) {
4970 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4971 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4972 continue;
4973
4974 // Check return types.
4975 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4976 FoundMethod->getReturnType())) {
4977 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4978 << D->isInstanceMethod() << Name << D->getReturnType()
4979 << FoundMethod->getReturnType();
4980 Importer.ToDiag(FoundMethod->getLocation(),
4981 diag::note_odr_objc_method_here)
4982 << D->isInstanceMethod() << Name;
4983
4984 return make_error<ASTImportError>(ASTImportError::NameConflict);
4985 }
4986
4987 // Check the number of parameters.
4988 if (D->param_size() != FoundMethod->param_size()) {
4989 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4990 << D->isInstanceMethod() << Name
4991 << D->param_size() << FoundMethod->param_size();
4992 Importer.ToDiag(FoundMethod->getLocation(),
4993 diag::note_odr_objc_method_here)
4994 << D->isInstanceMethod() << Name;
4995
4996 return make_error<ASTImportError>(ASTImportError::NameConflict);
4997 }
4998
4999 // Check parameter types.
5001 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
5002 P != PEnd; ++P, ++FoundP) {
5003 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
5004 (*FoundP)->getType())) {
5005 Importer.FromDiag((*P)->getLocation(),
5006 diag::warn_odr_objc_method_param_type_inconsistent)
5007 << D->isInstanceMethod() << Name
5008 << (*P)->getType() << (*FoundP)->getType();
5009 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
5010 << (*FoundP)->getType();
5011
5012 return make_error<ASTImportError>(ASTImportError::NameConflict);
5013 }
5014 }
5015
5016 // Check variadic/non-variadic.
5017 // Check the number of parameters.
5018 if (D->isVariadic() != FoundMethod->isVariadic()) {
5019 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
5020 << D->isInstanceMethod() << Name;
5021 Importer.ToDiag(FoundMethod->getLocation(),
5022 diag::note_odr_objc_method_here)
5023 << D->isInstanceMethod() << Name;
5024
5025 return make_error<ASTImportError>(ASTImportError::NameConflict);
5026 }
5027
5028 // FIXME: Any other bits we need to merge?
5029 return Importer.MapImported(D, FoundMethod);
5030 }
5031 }
5032
5033 Error Err = Error::success();
5034 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5035 auto ToReturnType = importChecked(Err, D->getReturnType());
5036 auto ToReturnTypeSourceInfo =
5038 if (Err)
5039 return std::move(Err);
5040
5041 ObjCMethodDecl *ToMethod;
5042 if (GetImportedOrCreateDecl(
5043 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5044 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5048 return ToMethod;
5049
5050 // FIXME: When we decide to merge method definitions, we'll need to
5051 // deal with implicit parameters.
5052
5053 // Import the parameters
5055 for (auto *FromP : D->parameters()) {
5056 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5057 ToParams.push_back(*ToPOrErr);
5058 else
5059 return ToPOrErr.takeError();
5060 }
5061
5062 // Set the parameters.
5063 for (auto *ToParam : ToParams) {
5064 ToParam->setOwningFunction(ToMethod);
5065 ToMethod->addDeclInternal(ToParam);
5066 }
5067
5069 D->getSelectorLocs(FromSelLocs);
5070 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5071 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5072 return std::move(Err);
5073
5074 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5075
5076 ToMethod->setLexicalDeclContext(LexicalDC);
5077 LexicalDC->addDeclInternal(ToMethod);
5078
5079 // Implicit params are declared when Sema encounters the definition but this
5080 // never happens when the method is imported. Manually declare the implicit
5081 // params now that the MethodDecl knows its class interface.
5082 if (D->getSelfDecl())
5083 ToMethod->createImplicitParams(Importer.getToContext(),
5084 ToMethod->getClassInterface());
5085
5086 return ToMethod;
5087}
5088
5090 // Import the major distinguishing characteristics of a category.
5091 DeclContext *DC, *LexicalDC;
5092 DeclarationName Name;
5093 SourceLocation Loc;
5094 NamedDecl *ToD;
5095 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5096 return std::move(Err);
5097 if (ToD)
5098 return ToD;
5099
5100 Error Err = Error::success();
5101 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5102 auto ToLocation = importChecked(Err, D->getLocation());
5103 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5104 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5105 if (Err)
5106 return std::move(Err);
5107
5109 if (GetImportedOrCreateDecl(
5110 Result, D, Importer.getToContext(), DC, D->getVariance(),
5111 ToVarianceLoc, D->getIndex(),
5112 ToLocation, Name.getAsIdentifierInfo(),
5113 ToColonLoc, ToTypeSourceInfo))
5114 return Result;
5115
5116 // Only import 'ObjCTypeParamType' after the decl is created.
5117 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5118 if (Err)
5119 return std::move(Err);
5120 Result->setTypeForDecl(ToTypeForDecl);
5121 Result->setLexicalDeclContext(LexicalDC);
5122 return Result;
5123}
5124
5126 // Import the major distinguishing characteristics of a category.
5127 DeclContext *DC, *LexicalDC;
5128 DeclarationName Name;
5129 SourceLocation Loc;
5130 NamedDecl *ToD;
5131 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5132 return std::move(Err);
5133 if (ToD)
5134 return ToD;
5135
5136 ObjCInterfaceDecl *ToInterface;
5137 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5138 return std::move(Err);
5139
5140 // Determine if we've already encountered this category.
5141 ObjCCategoryDecl *MergeWithCategory
5142 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5143 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5144 if (!ToCategory) {
5145
5146 Error Err = Error::success();
5147 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5148 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5149 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5150 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5151 if (Err)
5152 return std::move(Err);
5153
5154 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5155 ToAtStartLoc, Loc,
5156 ToCategoryNameLoc,
5157 Name.getAsIdentifierInfo(), ToInterface,
5158 /*TypeParamList=*/nullptr,
5159 ToIvarLBraceLoc,
5160 ToIvarRBraceLoc))
5161 return ToCategory;
5162
5163 ToCategory->setLexicalDeclContext(LexicalDC);
5164 LexicalDC->addDeclInternal(ToCategory);
5165 // Import the type parameter list after MapImported, to avoid
5166 // loops when bringing in their DeclContext.
5167 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5168 ToCategory->setTypeParamList(*PListOrErr);
5169 else
5170 return PListOrErr.takeError();
5171
5172 // Import protocols
5174 SmallVector<SourceLocation, 4> ProtocolLocs;
5176 = D->protocol_loc_begin();
5178 FromProtoEnd = D->protocol_end();
5179 FromProto != FromProtoEnd;
5180 ++FromProto, ++FromProtoLoc) {
5181 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5182 Protocols.push_back(*ToProtoOrErr);
5183 else
5184 return ToProtoOrErr.takeError();
5185
5186 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5187 ProtocolLocs.push_back(*ToProtoLocOrErr);
5188 else
5189 return ToProtoLocOrErr.takeError();
5190 }
5191
5192 // FIXME: If we're merging, make sure that the protocol list is the same.
5193 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5194 ProtocolLocs.data(), Importer.getToContext());
5195
5196 } else {
5197 Importer.MapImported(D, ToCategory);
5198 }
5199
5200 // Import all of the members of this category.
5201 if (Error Err = ImportDeclContext(D))
5202 return std::move(Err);
5203
5204 // If we have an implementation, import it as well.
5205 if (D->getImplementation()) {
5206 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5207 import(D->getImplementation()))
5208 ToCategory->setImplementation(*ToImplOrErr);
5209 else
5210 return ToImplOrErr.takeError();
5211 }
5212
5213 return ToCategory;
5214}
5215
5218 if (To->getDefinition()) {
5220 if (Error Err = ImportDeclContext(From))
5221 return Err;
5222 return Error::success();
5223 }
5224
5225 // Start the protocol definition
5226 To->startDefinition();
5227
5228 // Import protocols
5230 SmallVector<SourceLocation, 4> ProtocolLocs;
5232 From->protocol_loc_begin();
5233 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5234 FromProtoEnd = From->protocol_end();
5235 FromProto != FromProtoEnd;
5236 ++FromProto, ++FromProtoLoc) {
5237 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5238 Protocols.push_back(*ToProtoOrErr);
5239 else
5240 return ToProtoOrErr.takeError();
5241
5242 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5243 ProtocolLocs.push_back(*ToProtoLocOrErr);
5244 else
5245 return ToProtoLocOrErr.takeError();
5246
5247 }
5248
5249 // FIXME: If we're merging, make sure that the protocol list is the same.
5250 To->setProtocolList(Protocols.data(), Protocols.size(),
5251 ProtocolLocs.data(), Importer.getToContext());
5252
5253 if (shouldForceImportDeclContext(Kind)) {
5254 // Import all of the members of this protocol.
5255 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5256 return Err;
5257 }
5258 return Error::success();
5259}
5260
5262 // If this protocol has a definition in the translation unit we're coming
5263 // from, but this particular declaration is not that definition, import the
5264 // definition and map to that.
5266 if (Definition && Definition != D) {
5267 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5268 return Importer.MapImported(D, *ImportedDefOrErr);
5269 else
5270 return ImportedDefOrErr.takeError();
5271 }
5272
5273 // Import the major distinguishing characteristics of a protocol.
5274 DeclContext *DC, *LexicalDC;
5275 DeclarationName Name;
5276 SourceLocation Loc;
5277 NamedDecl *ToD;
5278 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5279 return std::move(Err);
5280 if (ToD)
5281 return ToD;
5282
5283 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5284 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5285 for (auto *FoundDecl : FoundDecls) {
5286 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5287 continue;
5288
5289 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5290 break;
5291 }
5292
5293 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5294 if (!ToProto) {
5295 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5296 if (!ToAtBeginLocOrErr)
5297 return ToAtBeginLocOrErr.takeError();
5298
5299 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5300 Name.getAsIdentifierInfo(), Loc,
5301 *ToAtBeginLocOrErr,
5302 /*PrevDecl=*/nullptr))
5303 return ToProto;
5304 ToProto->setLexicalDeclContext(LexicalDC);
5305 LexicalDC->addDeclInternal(ToProto);
5306 }
5307
5308 Importer.MapImported(D, ToProto);
5309
5311 if (Error Err = ImportDefinition(D, ToProto))
5312 return std::move(Err);
5313
5314 return ToProto;
5315}
5316
5318 DeclContext *DC, *LexicalDC;
5319 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5320 return std::move(Err);
5321
5322 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5323 if (!ExternLocOrErr)
5324 return ExternLocOrErr.takeError();
5325
5326 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5327 if (!LangLocOrErr)
5328 return LangLocOrErr.takeError();
5329
5330 bool HasBraces = D->hasBraces();
5331
5332 LinkageSpecDecl *ToLinkageSpec;
5333 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5334 *ExternLocOrErr, *LangLocOrErr,
5335 D->getLanguage(), HasBraces))
5336 return ToLinkageSpec;
5337
5338 if (HasBraces) {
5339 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5340 if (!RBraceLocOrErr)
5341 return RBraceLocOrErr.takeError();
5342 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5343 }
5344
5345 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5346 LexicalDC->addDeclInternal(ToLinkageSpec);
5347
5348 return ToLinkageSpec;
5349}
5350
5352 BaseUsingDecl *ToSI) {
5353 for (UsingShadowDecl *FromShadow : D->shadows()) {
5354 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5355 ToSI->addShadowDecl(*ToShadowOrErr);
5356 else
5357 // FIXME: We return error here but the definition is already created
5358 // and available with lookups. How to fix this?..
5359 return ToShadowOrErr.takeError();
5360 }
5361 return ToSI;
5362}
5363
5365 DeclContext *DC, *LexicalDC;
5366 DeclarationName Name;
5367 SourceLocation Loc;
5368 NamedDecl *ToD = nullptr;
5369 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5370 return std::move(Err);
5371 if (ToD)
5372 return ToD;
5373
5374 Error Err = Error::success();
5375 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5376 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5377 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5378 if (Err)
5379 return std::move(Err);
5380
5381 DeclarationNameInfo NameInfo(Name, ToLoc);
5382 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5383 return std::move(Err);
5384
5385 UsingDecl *ToUsing;
5386 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5387 ToUsingLoc, ToQualifierLoc, NameInfo,
5388 D->hasTypename()))
5389 return ToUsing;
5390
5391 ToUsing->setLexicalDeclContext(LexicalDC);
5392 LexicalDC->addDeclInternal(ToUsing);
5393
5394 if (NamedDecl *FromPattern =
5395 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5396 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5397 Importer.getToContext().setInstantiatedFromUsingDecl(
5398 ToUsing, *ToPatternOrErr);
5399 else
5400 return ToPatternOrErr.takeError();
5401 }
5402
5403 return ImportUsingShadowDecls(D, ToUsing);
5404}
5405
5407 DeclContext *DC, *LexicalDC;
5408 DeclarationName Name;
5409 SourceLocation Loc;
5410 NamedDecl *ToD = nullptr;
5411 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5412 return std::move(Err);
5413 if (ToD)
5414 return ToD;
5415
5416 Error Err = Error::success();
5417 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5418 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5419 auto ToNameLoc = importChecked(Err, D->getLocation());
5420 auto *ToEnumType = importChecked(Err, D->getEnumType());
5421 if (Err)
5422 return std::move(Err);
5423
5424 UsingEnumDecl *ToUsingEnum;
5425 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5426 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5427 return ToUsingEnum;
5428
5429 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5430 LexicalDC->addDeclInternal(ToUsingEnum);
5431
5432 if (UsingEnumDecl *FromPattern =
5433 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5434 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5435 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5436 *ToPatternOrErr);
5437 else
5438 return ToPatternOrErr.takeError();
5439 }
5440
5441 return ImportUsingShadowDecls(D, ToUsingEnum);
5442}
5443
5445 DeclContext *DC, *LexicalDC;
5446 DeclarationName Name;
5447 SourceLocation Loc;
5448 NamedDecl *ToD = nullptr;
5449 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5450 return std::move(Err);
5451 if (ToD)
5452 return ToD;
5453
5454 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5455 if (!ToIntroducerOrErr)
5456 return ToIntroducerOrErr.takeError();
5457
5458 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5459 if (!ToTargetOrErr)
5460 return ToTargetOrErr.takeError();
5461
5462 UsingShadowDecl *ToShadow;
5463 if (auto *FromConstructorUsingShadow =
5464 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5465 Error Err = Error::success();
5467 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5468 if (Err)
5469 return std::move(Err);
5470 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5471 // is really the "NominatedBaseClassShadowDecl" value if it exists
5472 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5473 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5474 // get the correct values.
5475 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5476 ToShadow, D, Importer.getToContext(), DC, Loc,
5477 cast<UsingDecl>(*ToIntroducerOrErr),
5478 Nominated ? Nominated : *ToTargetOrErr,
5479 FromConstructorUsingShadow->constructsVirtualBase()))
5480 return ToShadow;
5481 } else {
5482 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5483 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5484 return ToShadow;
5485 }
5486
5487 ToShadow->setLexicalDeclContext(LexicalDC);
5488 ToShadow->setAccess(D->getAccess());
5489
5490 if (UsingShadowDecl *FromPattern =
5491 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5492 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5493 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5494 ToShadow, *ToPatternOrErr);
5495 else
5496 // FIXME: We return error here but the definition is already created
5497 // and available with lookups. How to fix this?..
5498 return ToPatternOrErr.takeError();
5499 }
5500
5501 LexicalDC->addDeclInternal(ToShadow);
5502
5503 return ToShadow;
5504}
5505
5507 DeclContext *DC, *LexicalDC;
5508 DeclarationName Name;
5509 SourceLocation Loc;
5510 NamedDecl *ToD = nullptr;
5511 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5512 return std::move(Err);
5513 if (ToD)
5514 return ToD;
5515
5516 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5517 if (!ToComAncestorOrErr)
5518 return ToComAncestorOrErr.takeError();
5519
5520 Error Err = Error::success();
5521 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5522 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5523 auto ToNamespaceKeyLocation =
5525 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5526 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5527 if (Err)
5528 return std::move(Err);
5529
5530 UsingDirectiveDecl *ToUsingDir;
5531 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5532 ToUsingLoc,
5533 ToNamespaceKeyLocation,
5534 ToQualifierLoc,
5535 ToIdentLocation,
5536 ToNominatedNamespace, *ToComAncestorOrErr))
5537 return ToUsingDir;
5538
5539 ToUsingDir->setLexicalDeclContext(LexicalDC);
5540 LexicalDC->addDeclInternal(ToUsingDir);
5541
5542 return ToUsingDir;
5543}
5544
5546 DeclContext *DC, *LexicalDC;
5547 DeclarationName Name;
5548 SourceLocation Loc;
5549 NamedDecl *ToD = nullptr;
5550 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5551 return std::move(Err);
5552 if (ToD)
5553 return ToD;
5554
5555 auto ToInstantiatedFromUsingOrErr =
5556 Importer.Import(D->getInstantiatedFromUsingDecl());
5557 if (!ToInstantiatedFromUsingOrErr)
5558 return ToInstantiatedFromUsingOrErr.takeError();
5559 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5560 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5561 return std::move(Err);
5562
5563 UsingPackDecl *ToUsingPack;
5564 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5565 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5566 Expansions))
5567 return ToUsingPack;
5568
5569 addDeclToContexts(D, ToUsingPack);
5570
5571 return ToUsingPack;
5572}
5573
5576 DeclContext *DC, *LexicalDC;
5577 DeclarationName Name;
5578 SourceLocation Loc;
5579 NamedDecl *ToD = nullptr;
5580 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5581 return std::move(Err);
5582 if (ToD)
5583 return ToD;
5584
5585 Error Err = Error::success();
5586 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5587 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5588 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5589 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5590 if (Err)
5591 return std::move(Err);
5592
5593 DeclarationNameInfo NameInfo(Name, ToLoc);
5594 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5595 return std::move(Err);
5596
5597 UnresolvedUsingValueDecl *ToUsingValue;
5598 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5599 ToUsingLoc, ToQualifierLoc, NameInfo,
5600 ToEllipsisLoc))
5601 return ToUsingValue;
5602
5603 ToUsingValue->setAccess(D->getAccess());
5604 ToUsingValue->setLexicalDeclContext(LexicalDC);
5605 LexicalDC->addDeclInternal(ToUsingValue);
5606
5607 return ToUsingValue;
5608}
5609
5612 DeclContext *DC, *LexicalDC;
5613 DeclarationName Name;
5614 SourceLocation Loc;
5615 NamedDecl *ToD = nullptr;
5616 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5617 return std::move(Err);
5618 if (ToD)
5619 return ToD;
5620
5621 Error Err = Error::success();
5622 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5623 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5624 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5625 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5626 if (Err)
5627 return std::move(Err);
5628
5630 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5631 ToUsingLoc, ToTypenameLoc,
5632 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5633 return ToUsing;
5634
5635 ToUsing->setAccess(D->getAccess());
5636 ToUsing->setLexicalDeclContext(LexicalDC);
5637 LexicalDC->addDeclInternal(ToUsing);
5638
5639 return ToUsing;
5640}
5641
5643 Decl* ToD = nullptr;
5644 switch (D->getBuiltinTemplateKind()) {
5645#define BuiltinTemplate(BTName) \
5646 case BuiltinTemplateKind::BTK##BTName: \
5647 ToD = Importer.getToContext().get##BTName##Decl(); \
5648 break;
5649#include "clang/Basic/BuiltinTemplates.inc"
5650 }
5651 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5652 Importer.MapImported(D, ToD);
5653 return ToD;
5654}
5655
5658 if (To->getDefinition()) {
5659 // Check consistency of superclass.
5660 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5661 if (FromSuper) {
5662 if (auto FromSuperOrErr = import(FromSuper))
5663 FromSuper = *FromSuperOrErr;
5664 else
5665 return FromSuperOrErr.takeError();
5666 }
5667
5668 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5669 if ((bool)FromSuper != (bool)ToSuper ||
5670 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5671 Importer.ToDiag(To->getLocation(),
5672 diag::warn_odr_objc_superclass_inconsistent)
5673 << To->getDeclName();
5674 if (ToSuper)
5675 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5676 << To->getSuperClass()->getDeclName();
5677 else
5678 Importer.ToDiag(To->getLocation(),
5679 diag::note_odr_objc_missing_superclass);
5680 if (From->getSuperClass())
5681 Importer.FromDiag(From->getSuperClassLoc(),
5682 diag::note_odr_objc_superclass)
5683 << From->getSuperClass()->getDeclName();
5684 else
5685 Importer.FromDiag(From->getLocation(),
5686 diag::note_odr_objc_missing_superclass);
5687 }
5688
5690 if (Error Err = ImportDeclContext(From))
5691 return Err;
5692 return Error::success();
5693 }
5694
5695 // Start the definition.
5696 To->startDefinition();
5697
5698 // If this class has a superclass, import it.
5699 if (From->getSuperClass()) {
5700 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5701 To->setSuperClass(*SuperTInfoOrErr);
5702 else
5703 return SuperTInfoOrErr.takeError();
5704 }
5705
5706 // Import protocols
5708 SmallVector<SourceLocation, 4> ProtocolLocs;
5710 From->protocol_loc_begin();
5711
5713 FromProtoEnd = From->protocol_end();
5714 FromProto != FromProtoEnd;
5715 ++FromProto, ++FromProtoLoc) {
5716 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5717 Protocols.push_back(*ToProtoOrErr);
5718 else
5719 return ToProtoOrErr.takeError();
5720
5721 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5722 ProtocolLocs.push_back(*ToProtoLocOrErr);
5723 else
5724 return ToProtoLocOrErr.takeError();
5725
5726 }
5727
5728 // FIXME: If we're merging, make sure that the protocol list is the same.
5729 To->setProtocolList(Protocols.data(), Protocols.size(),
5730 ProtocolLocs.data(), Importer.getToContext());
5731
5732 // Import categories. When the categories themselves are imported, they'll
5733 // hook themselves into this interface.
5734 for (auto *Cat : From->known_categories()) {
5735 auto ToCatOrErr = import(Cat);
5736 if (!ToCatOrErr)
5737 return ToCatOrErr.takeError();
5738 }
5739
5740 // If we have an @implementation, import it as well.
5741 if (From->getImplementation()) {
5742 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5743 import(From->getImplementation()))
5744 To->setImplementation(*ToImplOrErr);
5745 else
5746 return ToImplOrErr.takeError();
5747 }
5748
5749 // Import all of the members of this class.
5750 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5751 return Err;
5752
5753 return Error::success();
5754}
5755
5758 if (!list)
5759 return nullptr;
5760
5762 for (auto *fromTypeParam : *list) {
5763 if (auto toTypeParamOrErr = import(fromTypeParam))
5764 toTypeParams.push_back(*toTypeParamOrErr);
5765 else
5766 return toTypeParamOrErr.takeError();
5767 }
5768
5769 auto LAngleLocOrErr = import(list->getLAngleLoc());
5770 if (!LAngleLocOrErr)
5771 return LAngleLocOrErr.takeError();
5772
5773 auto RAngleLocOrErr = import(list->getRAngleLoc());
5774 if (!RAngleLocOrErr)
5775 return RAngleLocOrErr.takeError();
5776
5777 return ObjCTypeParamList::create(Importer.getToContext(),
5778 *LAngleLocOrErr,
5779 toTypeParams,
5780 *RAngleLocOrErr);
5781}
5782
5784 // If this class has a definition in the translation unit we're coming from,
5785 // but this particular declaration is not that definition, import the
5786 // definition and map to that.
5788 if (Definition && Definition != D) {
5789 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5790 return Importer.MapImported(D, *ImportedDefOrErr);
5791 else
5792 return ImportedDefOrErr.takeError();
5793 }
5794
5795 // Import the major distinguishing characteristics of an @interface.
5796 DeclContext *DC, *LexicalDC;
5797 DeclarationName Name;
5798 SourceLocation Loc;
5799 NamedDecl *ToD;
5800 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5801 return std::move(Err);
5802 if (ToD)
5803 return ToD;
5804
5805 // Look for an existing interface with the same name.
5806 ObjCInterfaceDecl *MergeWithIface = nullptr;
5807 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5808 for (auto *FoundDecl : FoundDecls) {
5809 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5810 continue;
5811
5812 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5813 break;
5814 }
5815
5816 // Create an interface declaration, if one does not already exist.
5817 ObjCInterfaceDecl *ToIface = MergeWithIface;
5818 if (!ToIface) {
5819 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5820 if (!AtBeginLocOrErr)
5821 return AtBeginLocOrErr.takeError();
5822
5823 if (GetImportedOrCreateDecl(
5824 ToIface, D, Importer.getToContext(), DC,
5825 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5826 /*TypeParamList=*/nullptr,
5827 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5828 return ToIface;
5829 ToIface->setLexicalDeclContext(LexicalDC);
5830 LexicalDC->addDeclInternal(ToIface);
5831 }
5832 Importer.MapImported(D, ToIface);
5833 // Import the type parameter list after MapImported, to avoid
5834 // loops when bringing in their DeclContext.
5835 if (auto ToPListOrErr =
5837 ToIface->setTypeParamList(*ToPListOrErr);
5838 else
5839 return ToPListOrErr.takeError();
5840
5842 if (Error Err = ImportDefinition(D, ToIface))
5843 return std::move(Err);
5844
5845 return ToIface;
5846}
5847
5850 ObjCCategoryDecl *Category;
5851 if (Error Err = importInto(Category, D->getCategoryDecl()))
5852 return std::move(Err);
5853
5854 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5855 if (!ToImpl) {
5856 DeclContext *DC, *LexicalDC;
5857 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5858 return std::move(Err);
5859
5860 Error Err = Error::success();
5861 auto ToLocation = importChecked(Err, D->getLocation());
5862 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5863 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5864 if (Err)
5865 return std::move(Err);
5866
5867 if (GetImportedOrCreateDecl(
5868 ToImpl, D, Importer.getToContext(), DC,
5869 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5870 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5871 return ToImpl;
5872
5873 ToImpl->setLexicalDeclContext(LexicalDC);
5874 LexicalDC->addDeclInternal(ToImpl);
5875 Category->setImplementation(ToImpl);
5876 }
5877
5878 Importer.MapImported(D, ToImpl);
5879 if (Error Err = ImportDeclContext(D))
5880 return std::move(Err);
5881
5882 return ToImpl;
5883}
5884
5887 // Find the corresponding interface.
5888 ObjCInterfaceDecl *Iface;
5889 if (Error Err = importInto(Iface, D->getClassInterface()))
5890 return std::move(Err);
5891
5892 // Import the superclass, if any.
5893 ObjCInterfaceDecl *Super;
5894 if (Error Err = importInto(Super, D->getSuperClass()))
5895 return std::move(Err);
5896
5898 if (!Impl) {
5899 // We haven't imported an implementation yet. Create a new @implementation
5900 // now.
5901 DeclContext *DC, *LexicalDC;
5902 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5903 return std::move(Err);
5904
5905 Error Err = Error::success();
5906 auto ToLocation = importChecked(Err, D->getLocation());
5907 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5908 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5909 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5910 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5911 if (Err)
5912 return std::move(Err);
5913
5914 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5915 DC, Iface, Super,
5916 ToLocation,
5917 ToAtStartLoc,
5918 ToSuperClassLoc,
5919 ToIvarLBraceLoc,
5920 ToIvarRBraceLoc))
5921 return Impl;
5922
5923 Impl->setLexicalDeclContext(LexicalDC);
5924
5925 // Associate the implementation with the class it implements.
5926 Iface->setImplementation(Impl);
5927 Importer.MapImported(D, Iface->getImplementation());
5928 } else {
5929 Importer.MapImported(D, Iface->getImplementation());
5930
5931 // Verify that the existing @implementation has the same superclass.
5932 if ((Super && !Impl->getSuperClass()) ||
5933 (!Super && Impl->getSuperClass()) ||
5934 (Super && Impl->getSuperClass() &&
5936 Impl->getSuperClass()))) {
5937 Importer.ToDiag(Impl->getLocation(),
5938 diag::warn_odr_objc_superclass_inconsistent)
5939 << Iface->getDeclName();
5940 // FIXME: It would be nice to have the location of the superclass
5941 // below.
5942 if (Impl->getSuperClass())
5943 Importer.ToDiag(Impl->getLocation(),
5944 diag::note_odr_objc_superclass)
5945 << Impl->getSuperClass()->getDeclName();
5946 else
5947 Importer.ToDiag(Impl->getLocation(),
5948 diag::note_odr_objc_missing_superclass);
5949 if (D->getSuperClass())
5950 Importer.FromDiag(D->getLocation(),
5951 diag::note_odr_objc_superclass)
5952 << D->getSuperClass()->getDeclName();
5953 else
5954 Importer.FromDiag(D->getLocation(),
5955 diag::note_odr_objc_missing_superclass);
5956
5957 return make_error<ASTImportError>(ASTImportError::NameConflict);
5958 }
5959 }
5960
5961 // Import all of the members of this @implementation.
5962 if (Error Err = ImportDeclContext(D))
5963 return std::move(Err);
5964
5965 return Impl;
5966}
5967
5969 // Import the major distinguishing characteristics of an @property.
5970 DeclContext *DC, *LexicalDC;
5971 DeclarationName Name;
5972 SourceLocation Loc;
5973 NamedDecl *ToD;
5974 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5975 return std::move(Err);
5976 if (ToD)
5977 return ToD;
5978
5979 // Check whether we have already imported this property.
5980 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5981 for (auto *FoundDecl : FoundDecls) {
5982 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5983 // Instance and class properties can share the same name but are different
5984 // declarations.
5985 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5986 continue;
5987
5988 // Check property types.
5989 if (!Importer.IsStructurallyEquivalent(D->getType(),
5990 FoundProp->getType())) {
5991 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5992 << Name << D->getType() << FoundProp->getType();
5993 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5994 << FoundProp->getType();
5995
5996 return make_error<ASTImportError>(ASTImportError::NameConflict);
5997 }
5998
5999 // FIXME: Check property attributes, getters, setters, etc.?
6000
6001 // Consider these properties to be equivalent.
6002 Importer.MapImported(D, FoundProp);
6003 return FoundProp;
6004 }
6005 }
6006
6007 Error Err = Error::success();
6008 auto ToType = importChecked(Err, D->getType());
6009 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6010 auto ToAtLoc = importChecked(Err, D->getAtLoc());
6011 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
6012 if (Err)
6013 return std::move(Err);
6014
6015 // Create the new property.
6016 ObjCPropertyDecl *ToProperty;
6017 if (GetImportedOrCreateDecl(
6018 ToProperty, D, Importer.getToContext(), DC, Loc,
6019 Name.getAsIdentifierInfo(), ToAtLoc,
6020 ToLParenLoc, ToType,
6021 ToTypeSourceInfo, D->getPropertyImplementation()))
6022 return ToProperty;
6023
6024 auto ToGetterName = importChecked(Err, D->getGetterName());
6025 auto ToSetterName = importChecked(Err, D->getSetterName());
6026 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6027 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6028 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6029 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6030 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6031 if (Err)
6032 return std::move(Err);
6033
6034 ToProperty->setLexicalDeclContext(LexicalDC);
6035 LexicalDC->addDeclInternal(ToProperty);
6036
6040 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6041 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6042 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6043 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6044 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6045 return ToProperty;
6046}
6047
6051 if (Error Err = importInto(Property, D->getPropertyDecl()))
6052 return std::move(Err);
6053
6054 DeclContext *DC, *LexicalDC;
6055 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6056 return std::move(Err);
6057
6058 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6059
6060 // Import the ivar (for an @synthesize).
6061 ObjCIvarDecl *Ivar = nullptr;
6062 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6063 return std::move(Err);
6064
6065 ObjCPropertyImplDecl *ToImpl
6066 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6067 Property->getQueryKind());
6068 if (!ToImpl) {
6069
6070 Error Err = Error::success();
6071 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6072 auto ToLocation = importChecked(Err, D->getLocation());
6073 auto ToPropertyIvarDeclLoc =
6075 if (Err)
6076 return std::move(Err);
6077
6078 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6079 ToBeginLoc,
6080 ToLocation, Property,
6081 D->getPropertyImplementation(), Ivar,
6082 ToPropertyIvarDeclLoc))
6083 return ToImpl;
6084
6085 ToImpl->setLexicalDeclContext(LexicalDC);
6086 LexicalDC->addDeclInternal(ToImpl);
6087 } else {
6088 // Check that we have the same kind of property implementation (@synthesize
6089 // vs. @dynamic).
6091 Importer.ToDiag(ToImpl->getLocation(),
6092 diag::warn_odr_objc_property_impl_kind_inconsistent)
6093 << Property->getDeclName()
6094 << (ToImpl->getPropertyImplementation()
6096 Importer.FromDiag(D->getLocation(),
6097 diag::note_odr_objc_property_impl_kind)
6098 << D->getPropertyDecl()->getDeclName()
6100
6101 return make_error<ASTImportError>(ASTImportError::NameConflict);
6102 }
6103
6104 // For @synthesize, check that we have the same
6106 Ivar != ToImpl->getPropertyIvarDecl()) {
6107 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6108 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6109 << Property->getDeclName()
6110 << ToImpl->getPropertyIvarDecl()->getDeclName()
6111 << Ivar->getDeclName();
6112 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6113 diag::note_odr_objc_synthesize_ivar_here)
6115
6116 return make_error<ASTImportError>(ASTImportError::NameConflict);
6117 }
6118
6119 // Merge the existing implementation with the new implementation.
6120 Importer.MapImported(D, ToImpl);
6121 }
6122
6123 return ToImpl;
6124}
6125
6128 // For template arguments, we adopt the translation unit as our declaration
6129 // context. This context will be fixed when (during) the actual template
6130 // declaration is created.
6131
6132 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6133 if (!BeginLocOrErr)
6134 return BeginLocOrErr.takeError();
6135
6136 ExpectedSLoc LocationOrErr = import(D->getLocation());
6137 if (!LocationOrErr)
6138 return LocationOrErr.takeError();
6139
6140 TemplateTypeParmDecl *ToD = nullptr;
6141 if (GetImportedOrCreateDecl(
6142 ToD, D, Importer.getToContext(),
6143 Importer.getToContext().getTranslationUnitDecl(),
6144 *BeginLocOrErr, *LocationOrErr,
6145 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6147 D->hasTypeConstraint()))
6148 return ToD;
6149
6150 // Import the type-constraint
6151 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6152
6153 Error Err = Error::success();
6154 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6155 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6156 if (Err)
6157 return std::move(Err);
6158
6159 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6160 }
6161
6162 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6163 return Err;
6164
6165 return ToD;
6166}
6167
6170
6171 Error Err = Error::success();
6172 auto ToDeclName = importChecked(Err, D->getDeclName());
6173 auto ToLocation = importChecked(Err, D->getLocation());
6174 auto ToType = importChecked(Err, D->getType());
6175 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6176 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6177 if (Err)
6178 return std::move(Err);
6179
6180 NonTypeTemplateParmDecl *ToD = nullptr;
6181 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6182 Importer.getToContext().getTranslationUnitDecl(),
6183 ToInnerLocStart, ToLocation, D->getDepth(),
6184 D->getPosition(),
6185 ToDeclName.getAsIdentifierInfo(), ToType,
6186 D->isParameterPack(), ToTypeSourceInfo))
6187 return ToD;
6188
6189 Err = importTemplateParameterDefaultArgument(D, ToD);
6190 if (Err)
6191 return Err;
6192
6193 return ToD;
6194}
6195
6198 bool IsCanonical = false;
6199 if (auto *CanonD = Importer.getFromContext()
6200 .findCanonicalTemplateTemplateParmDeclInternal(D);
6201 CanonD == D)
6202 IsCanonical = true;
6203
6204 // Import the name of this declaration.
6205 auto NameOrErr = import(D->getDeclName());
6206 if (!NameOrErr)
6207 return NameOrErr.takeError();
6208
6209 // Import the location of this declaration.
6210 ExpectedSLoc LocationOrErr = import(D->getLocation());
6211 if (!LocationOrErr)
6212 return LocationOrErr.takeError();
6213
6214 // Import template parameters.
6215 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6216 if (!TemplateParamsOrErr)
6217 return TemplateParamsOrErr.takeError();
6218
6219 TemplateTemplateParmDecl *ToD = nullptr;
6220 if (GetImportedOrCreateDecl(
6221 ToD, D, Importer.getToContext(),
6222 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6223 D->getDepth(), D->getPosition(), D->isParameterPack(),
6224 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6225 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6226 return ToD;
6227
6228 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6229 return Err;
6230
6231 if (IsCanonical)
6232 return Importer.getToContext()
6233 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6234
6235 return ToD;
6236}
6237
6238// Returns the definition for a (forward) declaration of a TemplateDecl, if
6239// it has any definition in the redecl chain.
6240template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6241 assert(D->getTemplatedDecl() && "Should be called on templates only");
6242 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6243 if (!ToTemplatedDef)
6244 return nullptr;
6245 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6246 return cast_or_null<T>(TemplateWithDef);
6247}
6248
6250
6251 // Import the major distinguishing characteristics of this class template.
6252 DeclContext *DC, *LexicalDC;
6253 DeclarationName Name;
6254 SourceLocation Loc;
6255 NamedDecl *ToD;
6256 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6257 return std::move(Err);
6258 if (ToD)
6259 return ToD;
6260
6261 // Should check if a declaration is friend in a dependent context.
6262 // Such templates are not linked together in a declaration chain.
6263 // The ASTImporter strategy is to map existing forward declarations to
6264 // imported ones only if strictly necessary, otherwise import these as new
6265 // forward declarations. In case of the "dependent friend" declarations, new
6266 // declarations are created, but not linked in a declaration chain.
6267 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6268 return TD->getFriendObjectKind() != Decl::FOK_None &&
6269 TD->getLexicalDeclContext()->isDependentContext();
6270 };
6271 bool DependentFriend = IsDependentFriend(D);
6272
6273 ClassTemplateDecl *FoundByLookup = nullptr;
6274
6275 // We may already have a template of the same name; try to find and match it.
6276 if (!DC->isFunctionOrMethod()) {
6277 SmallVector<NamedDecl *, 4> ConflictingDecls;
6278 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6279 for (auto *FoundDecl : FoundDecls) {
6280 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6282 continue;
6283
6284 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6285 if (FoundTemplate) {
6286 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6287 continue;
6288
6289 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6290 bool IgnoreTemplateParmDepth =
6291 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6293 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6294 IgnoreTemplateParmDepth)) {
6295 if (DependentFriend || IsDependentFriend(FoundTemplate))
6296 continue;
6297
6298 ClassTemplateDecl *TemplateWithDef =
6299 getTemplateDefinition(FoundTemplate);
6300 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6301 return Importer.MapImported(D, TemplateWithDef);
6302 if (!FoundByLookup)
6303 FoundByLookup = FoundTemplate;
6304 // Search in all matches because there may be multiple decl chains,
6305 // see ASTTests test ImportExistingFriendClassTemplateDef.
6306 continue;
6307 }
6308 // When importing a friend, it is possible that multiple declarations
6309 // with same name can co-exist in specific cases (if a template contains
6310 // a friend template and has a specialization). For this case the
6311 // declarations should match, except that the "template depth" is
6312 // different. No linking of previous declaration is needed in this case.
6313 // FIXME: This condition may need refinement.
6314 if (D->getFriendObjectKind() != Decl::FOK_None &&
6315 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6316 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6317 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6318 /*IgnoreTemplateParmDepth=*/true))
6319 continue;
6320
6321 ConflictingDecls.push_back(FoundDecl);
6322 }
6323 }
6324
6325 if (!ConflictingDecls.empty()) {
6326 ExpectedName NameOrErr = Importer.HandleNameConflict(
6327 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6328 ConflictingDecls.size());
6329 if (NameOrErr)
6330 Name = NameOrErr.get();
6331 else
6332 return NameOrErr.takeError();
6333 }
6334 }
6335
6336 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6337
6338 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6339 if (!TemplateParamsOrErr)
6340 return TemplateParamsOrErr.takeError();
6341
6342 // Create the declaration that is being templated.
6343 CXXRecordDecl *ToTemplated;
6344 if (Error Err = importInto(ToTemplated, FromTemplated))
6345 return std::move(Err);
6346
6347 // Create the class template declaration itself.
6349 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6350 *TemplateParamsOrErr, ToTemplated))
6351 return D2;
6352
6353 ToTemplated->setDescribedClassTemplate(D2);
6354
6355 D2->setAccess(D->getAccess());
6356 D2->setLexicalDeclContext(LexicalDC);
6357
6358 addDeclToContexts(D, D2);
6359 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6360
6361 if (FoundByLookup) {
6362 auto *Recent =
6363 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6364
6365 // It is possible that during the import of the class template definition
6366 // we start the import of a fwd friend decl of the very same class template
6367 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6368 // had been created earlier and by that time the lookup could not find
6369 // anything existing, so it has no previous decl. Later, (still during the
6370 // import of the fwd friend decl) we start to import the definition again
6371 // and this time the lookup finds the previous fwd friend class template.
6372 // In this case we must set up the previous decl for the templated decl.
6373 if (!ToTemplated->getPreviousDecl()) {
6374 assert(FoundByLookup->getTemplatedDecl() &&
6375 "Found decl must have its templated decl set");
6376 CXXRecordDecl *PrevTemplated =
6377 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6378 if (ToTemplated != PrevTemplated)
6379 ToTemplated->setPreviousDecl(PrevTemplated);
6380 }
6381
6382 D2->setPreviousDecl(Recent);
6383 }
6384
6385 return D2;
6386}
6387
6390 ClassTemplateDecl *ClassTemplate;
6391 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6392 return std::move(Err);
6393
6394 // Import the context of this declaration.
6395 DeclContext *DC, *LexicalDC;
6396 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6397 return std::move(Err);
6398
6399 // Import template arguments.
6401 if (Error Err =
6402 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6403 return std::move(Err);
6404 // Try to find an existing specialization with these template arguments and
6405 // template parameter list.
6406 void *InsertPos = nullptr;
6407 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6409 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6410
6411 // Import template parameters.
6412 TemplateParameterList *ToTPList = nullptr;
6413
6414 if (PartialSpec) {
6415 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6416 if (!ToTPListOrErr)
6417 return ToTPListOrErr.takeError();
6418 ToTPList = *ToTPListOrErr;
6419 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6420 *ToTPListOrErr,
6421 InsertPos);
6422 } else
6423 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6424
6425 if (PrevDecl) {
6426 if (IsStructuralMatch(D, PrevDecl)) {
6427 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6428 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6429 Importer.MapImported(D, PrevDefinition);
6430 // Import those default field initializers which have been
6431 // instantiated in the "From" context, but not in the "To" context.
6432 for (auto *FromField : D->fields()) {
6433 auto ToOrErr = import(FromField);
6434 if (!ToOrErr)
6435 return ToOrErr.takeError();
6436 }
6437
6438 // Import those methods which have been instantiated in the
6439 // "From" context, but not in the "To" context.
6440 for (CXXMethodDecl *FromM : D->methods()) {
6441 auto ToOrErr = import(FromM);
6442 if (!ToOrErr)
6443 return ToOrErr.takeError();
6444 }
6445
6446 // TODO Import instantiated default arguments.
6447 // TODO Import instantiated exception specifications.
6448 //
6449 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6450 // what else could be fused during an AST merge.
6451 return PrevDefinition;
6452 }
6453 } else { // ODR violation.
6454 // FIXME HandleNameConflict
6455 return make_error<ASTImportError>(ASTImportError::NameConflict);
6456 }
6457 }
6458
6459 // Import the location of this declaration.
6460 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6461 if (!BeginLocOrErr)
6462 return BeginLocOrErr.takeError();
6463 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6464 if (!IdLocOrErr)
6465 return IdLocOrErr.takeError();
6466
6467 // Import TemplateArgumentListInfo.
6468 TemplateArgumentListInfo ToTAInfo;
6469 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6470 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6471 return std::move(Err);
6472 }
6473
6474 // Create the specialization.
6475 ClassTemplateSpecializationDecl *D2 = nullptr;
6476 if (PartialSpec) {
6477 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6478 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6479 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6480 /*CanonInjectedTST=*/CanQualType(),
6481 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6482 return D2;
6483
6484 // Update InsertPos, because preceding import calls may have invalidated
6485 // it by adding new specializations.
6487 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6488 InsertPos))
6489 // Add this partial specialization to the class template.
6490 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6492 import(PartialSpec->getInstantiatedFromMember()))
6493 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6494 else
6495 return ToInstOrErr.takeError();
6496
6497 updateLookupTableForTemplateParameters(*ToTPList);
6498 } else { // Not a partial specialization.
6499 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6500 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6501 TemplateArgs, D->hasStrictPackMatch(),
6502 PrevDecl))
6503 return D2;
6504
6505 // Update InsertPos, because preceding import calls may have invalidated
6506 // it by adding new specializations.
6507 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6508 // Add this specialization to the class template.
6509 ClassTemplate->AddSpecialization(D2, InsertPos);
6510 }
6511
6513
6514 // Set the context of this specialization/instantiation.
6515 D2->setLexicalDeclContext(LexicalDC);
6516
6517 // Add to the DC only if it was an explicit specialization/instantiation.
6519 LexicalDC->addDeclInternal(D2);
6520 }
6521
6522 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6523 D2->setBraceRange(*BraceRangeOrErr);
6524 else
6525 return BraceRangeOrErr.takeError();
6526
6527 if (Error Err = ImportTemplateParameterLists(D, D2))
6528 return std::move(Err);
6529
6530 // Import the qualifier, if any.
6531 if (auto LocOrErr = import(D->getQualifierLoc()))
6532 D2->setQualifierInfo(*LocOrErr);
6533 else
6534 return LocOrErr.takeError();
6535
6536 if (D->getTemplateArgsAsWritten())
6537 D2->setTemplateArgsAsWritten(ToTAInfo);
6538
6539 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6540 D2->setTemplateKeywordLoc(*LocOrErr);
6541 else
6542 return LocOrErr.takeError();
6543
6544 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6545 D2->setExternKeywordLoc(*LocOrErr);
6546 else
6547 return LocOrErr.takeError();
6548
6549 if (D->getPointOfInstantiation().isValid()) {
6550 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6551 D2->setPointOfInstantiation(*POIOrErr);
6552 else
6553 return POIOrErr.takeError();
6554 }
6555
6557
6558 if (auto P = D->getInstantiatedFrom()) {
6559 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6560 if (auto CTDorErr = import(CTD))
6561 D2->setInstantiationOf(*CTDorErr);
6562 } else {
6564 auto CTPSDOrErr = import(CTPSD);
6565 if (!CTPSDOrErr)
6566 return CTPSDOrErr.takeError();
6568 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6569 for (unsigned I = 0; I < DArgs.size(); ++I) {
6570 const TemplateArgument &DArg = DArgs[I];
6571 if (auto ArgOrErr = import(DArg))
6572 D2ArgsVec[I] = *ArgOrErr;
6573 else
6574 return ArgOrErr.takeError();
6575 }
6577 *CTPSDOrErr,
6578 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6579 }
6580 }
6581
6582 if (D->isCompleteDefinition())
6583 if (Error Err = ImportDefinition(D, D2))
6584 return std::move(Err);
6585
6586 return D2;
6587}
6588
6590 // Import the major distinguishing characteristics of this variable template.
6591 DeclContext *DC, *LexicalDC;
6592 DeclarationName Name;
6593 SourceLocation Loc;
6594 NamedDecl *ToD;
6595 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6596 return std::move(Err);
6597 if (ToD)
6598 return ToD;
6599
6600 // We may already have a template of the same name; try to find and match it.
6601 assert(!DC->isFunctionOrMethod() &&
6602 "Variable templates cannot be declared at function scope");
6603
6604 SmallVector<NamedDecl *, 4> ConflictingDecls;
6605 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6606 VarTemplateDecl *FoundByLookup = nullptr;
6607 for (auto *FoundDecl : FoundDecls) {
6608 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6609 continue;
6610
6611 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6612 // Use the templated decl, some linkage flags are set only there.
6613 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6614 D->getTemplatedDecl()))
6615 continue;
6616 if (IsStructuralMatch(D, FoundTemplate)) {
6617 // FIXME Check for ODR error if the two definitions have
6618 // different initializers?
6619 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6620 if (D->getDeclContext()->isRecord()) {
6621 assert(FoundTemplate->getDeclContext()->isRecord() &&
6622 "Member variable template imported as non-member, "
6623 "inconsistent imported AST?");
6624 if (FoundDef)
6625 return Importer.MapImported(D, FoundDef);
6627 return Importer.MapImported(D, FoundTemplate);
6628 } else {
6629 if (FoundDef && D->isThisDeclarationADefinition())
6630 return Importer.MapImported(D, FoundDef);
6631 }
6632 FoundByLookup = FoundTemplate;
6633 break;
6634 }
6635 ConflictingDecls.push_back(FoundDecl);
6636 }
6637 }
6638
6639 if (!ConflictingDecls.empty()) {
6640 ExpectedName NameOrErr = Importer.HandleNameConflict(
6641 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6642 ConflictingDecls.size());
6643 if (NameOrErr)
6644 Name = NameOrErr.get();
6645 else
6646 return NameOrErr.takeError();
6647 }
6648
6649 VarDecl *DTemplated = D->getTemplatedDecl();
6650
6651 // Import the type.
6652 // FIXME: Value not used?
6653 ExpectedType TypeOrErr = import(DTemplated->getType());
6654 if (!TypeOrErr)
6655 return TypeOrErr.takeError();
6656
6657 // Create the declaration that is being templated.
6658 VarDecl *ToTemplated;
6659 if (Error Err = importInto(ToTemplated, DTemplated))
6660 return std::move(Err);
6661
6662 // Create the variable template declaration itself.
6663 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6664 if (!TemplateParamsOrErr)
6665 return TemplateParamsOrErr.takeError();
6666
6667 VarTemplateDecl *ToVarTD;
6668 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6669 Name, *TemplateParamsOrErr, ToTemplated))
6670 return ToVarTD;
6671
6672 ToTemplated->setDescribedVarTemplate(ToVarTD);
6673
6674 ToVarTD->setAccess(D->getAccess());
6675 ToVarTD->setLexicalDeclContext(LexicalDC);
6676 LexicalDC->addDeclInternal(ToVarTD);
6677 if (DC != Importer.getToContext().getTranslationUnitDecl())
6678 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6679
6680 if (FoundByLookup) {
6681 auto *Recent =
6682 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6683 if (!ToTemplated->getPreviousDecl()) {
6684 auto *PrevTemplated =
6685 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6686 if (ToTemplated != PrevTemplated)
6687 ToTemplated->setPreviousDecl(PrevTemplated);
6688 }
6689 ToVarTD->setPreviousDecl(Recent);
6690 }
6691
6692 return ToVarTD;
6693}
6694
6697 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6698 // in an analog way (but specialized for this case).
6699
6701 auto RedeclIt = Redecls.begin();
6702 // Import the first part of the decl chain. I.e. import all previous
6703 // declarations starting from the canonical decl.
6704 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6705 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6706 if (!RedeclOrErr)
6707 return RedeclOrErr.takeError();
6708 }
6709 assert(*RedeclIt == D);
6710
6711 VarTemplateDecl *VarTemplate = nullptr;
6713 return std::move(Err);
6714
6715 // Import the context of this declaration.
6716 DeclContext *DC, *LexicalDC;
6717 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6718 return std::move(Err);
6719
6720 // Import the location of this declaration.
6721 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6722 if (!BeginLocOrErr)
6723 return BeginLocOrErr.takeError();
6724
6725 auto IdLocOrErr = import(D->getLocation());
6726 if (!IdLocOrErr)
6727 return IdLocOrErr.takeError();
6728
6729 // Import template arguments.
6731 if (Error Err =
6732 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6733 return std::move(Err);
6734
6735 // Try to find an existing specialization with these template arguments.
6736 void *InsertPos = nullptr;
6737 VarTemplateSpecializationDecl *FoundSpecialization =
6738 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6739 if (FoundSpecialization) {
6740 if (IsStructuralMatch(D, FoundSpecialization)) {
6741 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6742 if (D->getDeclContext()->isRecord()) {
6743 // In a record, it is allowed only to have one optional declaration and
6744 // one definition of the (static or constexpr) variable template.
6745 assert(
6746 FoundSpecialization->getDeclContext()->isRecord() &&
6747 "Member variable template specialization imported as non-member, "
6748 "inconsistent imported AST?");
6749 if (FoundDef)
6750 return Importer.MapImported(D, FoundDef);
6752 return Importer.MapImported(D, FoundSpecialization);
6753 } else {
6754 // If definition is imported and there is already one, map to it.
6755 // Otherwise create a new variable and link it to the existing.
6756 if (FoundDef && D->isThisDeclarationADefinition())
6757 return Importer.MapImported(D, FoundDef);
6758 }
6759 } else {
6760 return make_error<ASTImportError>(ASTImportError::NameConflict);
6761 }
6762 }
6763
6764 VarTemplateSpecializationDecl *D2 = nullptr;
6765
6766 TemplateArgumentListInfo ToTAInfo;
6767 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6768 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6769 return std::move(Err);
6770 }
6771
6772 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6773 // Create a new specialization.
6774 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6775 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6776 if (!ToTPListOrErr)
6777 return ToTPListOrErr.takeError();
6778
6779 PartVarSpecDecl *ToPartial;
6780 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6781 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6782 VarTemplate, QualType(), nullptr,
6783 D->getStorageClass(), TemplateArgs))
6784 return ToPartial;
6785
6786 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6787 import(FromPartial->getInstantiatedFromMember()))
6788 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6789 else
6790 return ToInstOrErr.takeError();
6791
6792 if (FromPartial->isMemberSpecialization())
6793 ToPartial->setMemberSpecialization();
6794
6795 D2 = ToPartial;
6796
6797 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6798 // to adopt template parameters.
6799 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6800 } else { // Full specialization
6801 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6802 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6803 QualType(), nullptr, D->getStorageClass(),
6804 TemplateArgs))
6805 return D2;
6806 }
6807
6808 // Update InsertPos, because preceding import calls may have invalidated
6809 // it by adding new specializations.
6810 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6811 VarTemplate->AddSpecialization(D2, InsertPos);
6812
6813 QualType T;
6814 if (Error Err = importInto(T, D->getType()))
6815 return std::move(Err);
6816 D2->setType(T);
6817
6818 auto TInfoOrErr = import(D->getTypeSourceInfo());
6819 if (!TInfoOrErr)
6820 return TInfoOrErr.takeError();
6821 D2->setTypeSourceInfo(*TInfoOrErr);
6822
6823 if (D->getPointOfInstantiation().isValid()) {
6824 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6825 D2->setPointOfInstantiation(*POIOrErr);
6826 else
6827 return POIOrErr.takeError();
6828 }
6829
6831
6832 if (D->getTemplateArgsAsWritten())
6833 D2->setTemplateArgsAsWritten(ToTAInfo);
6834
6835 if (auto LocOrErr = import(D->getQualifierLoc()))
6836 D2->setQualifierInfo(*LocOrErr);
6837 else
6838 return LocOrErr.takeError();
6839
6840 if (D->isConstexpr())
6841 D2->setConstexpr(true);
6842
6843 D2->setAccess(D->getAccess());
6844
6845 if (Error Err = ImportInitializer(D, D2))
6846 return std::move(Err);
6847
6848 if (FoundSpecialization)
6849 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6850
6851 addDeclToContexts(D, D2);
6852
6853 // Import the rest of the chain. I.e. import all subsequent declarations.
6854 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6855 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6856 if (!RedeclOrErr)
6857 return RedeclOrErr.takeError();
6858 }
6859
6860 return D2;
6861}
6862
6865 DeclContext *DC, *LexicalDC;
6866 DeclarationName Name;
6867 SourceLocation Loc;
6868 NamedDecl *ToD;
6869
6870 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6871 return std::move(Err);
6872
6873 if (ToD)
6874 return ToD;
6875
6876 const FunctionTemplateDecl *FoundByLookup = nullptr;
6877
6878 // Try to find a function in our own ("to") context with the same name, same
6879 // type, and in the same context as the function we're importing.
6880 // FIXME Split this into a separate function.
6881 if (!LexicalDC->isFunctionOrMethod()) {
6883 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6884 for (auto *FoundDecl : FoundDecls) {
6885 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6886 continue;
6887
6888 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6889 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6890 continue;
6891 if (IsStructuralMatch(D, FoundTemplate)) {
6892 FunctionTemplateDecl *TemplateWithDef =
6893 getTemplateDefinition(FoundTemplate);
6894 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6895 return Importer.MapImported(D, TemplateWithDef);
6896
6897 FoundByLookup = FoundTemplate;
6898 break;
6899 // TODO: handle conflicting names
6900 }
6901 }
6902 }
6903 }
6904
6905 auto ParamsOrErr = import(D->getTemplateParameters());
6906 if (!ParamsOrErr)
6907 return ParamsOrErr.takeError();
6908 TemplateParameterList *Params = *ParamsOrErr;
6909
6910 FunctionDecl *TemplatedFD;
6911 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6912 return std::move(Err);
6913
6914 // At creation of the template the template parameters are "adopted"
6915 // (DeclContext is changed). After this possible change the lookup table
6916 // must be updated.
6917 // At deduction guides the DeclContext of the template parameters may be
6918 // different from what we would expect, it may be the class template, or a
6919 // probably different CXXDeductionGuideDecl. This may come from the fact that
6920 // the template parameter objects may be shared between deduction guides or
6921 // the class template, and at creation of multiple FunctionTemplateDecl
6922 // objects (for deduction guides) the same parameters are re-used. The
6923 // "adoption" happens multiple times with different parent, even recursively
6924 // for TemplateTemplateParmDecl. The same happens at import when the
6925 // FunctionTemplateDecl objects are created, but in different order.
6926 // In this way the DeclContext of these template parameters is not necessarily
6927 // the same as in the "from" context.
6929 OldParamDC.reserve(Params->size());
6930 llvm::transform(*Params, std::back_inserter(OldParamDC),
6931 [](NamedDecl *ND) { return ND->getDeclContext(); });
6932
6933 FunctionTemplateDecl *ToFunc;
6934 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6935 Params, TemplatedFD))
6936 return ToFunc;
6937
6938 // Fail if TemplatedFD is already part of a template.
6939 // The template should have been found by structural equivalence check before,
6940 // or ToFunc should be already imported.
6941 // If not, there is AST incompatibility that can be caused by previous import
6942 // errors. (NameConflict is not exact here.)
6943 if (TemplatedFD->getDescribedTemplate())
6944 return make_error<ASTImportError>(ASTImportError::NameConflict);
6945
6946 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6947
6948 ToFunc->setAccess(D->getAccess());
6949 ToFunc->setLexicalDeclContext(LexicalDC);
6950 addDeclToContexts(D, ToFunc);
6951
6952 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6953 if (LT && !OldParamDC.empty()) {
6954 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6955 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6956 }
6957
6958 if (FoundByLookup) {
6959 auto *Recent =
6960 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6961 if (!TemplatedFD->getPreviousDecl()) {
6962 assert(FoundByLookup->getTemplatedDecl() &&
6963 "Found decl must have its templated decl set");
6964 auto *PrevTemplated =
6965 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6966 if (TemplatedFD != PrevTemplated)
6967 TemplatedFD->setPreviousDecl(PrevTemplated);
6968 }
6969 ToFunc->setPreviousDecl(Recent);
6970 }
6971
6972 return ToFunc;
6973}
6974
6976 DeclContext *DC, *LexicalDC;
6977 Error Err = ImportDeclContext(D, DC, LexicalDC);
6978 auto LocationOrErr = importChecked(Err, D->getLocation());
6979 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6980 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6981 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6982 if (Err)
6983 return std::move(Err);
6984
6985 ConceptDecl *To;
6986 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6987 NameDeclOrErr, ToTemplateParameters,
6988 ConstraintExpr))
6989 return To;
6990 To->setLexicalDeclContext(LexicalDC);
6991 LexicalDC->addDeclInternal(To);
6992 return To;
6993}
6994
6997 DeclContext *DC, *LexicalDC;
6998 Error Err = ImportDeclContext(D, DC, LexicalDC);
6999 auto RequiresLoc = importChecked(Err, D->getLocation());
7000 if (Err)
7001 return std::move(Err);
7002
7004 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
7005 return To;
7006 To->setLexicalDeclContext(LexicalDC);
7007 LexicalDC->addDeclInternal(To);
7008 return To;
7009}
7010
7013 DeclContext *DC, *LexicalDC;
7014 Error Err = ImportDeclContext(D, DC, LexicalDC);
7015 auto ToSL = importChecked(Err, D->getLocation());
7016 if (Err)
7017 return std::move(Err);
7018
7020 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
7021 return std::move(Err);
7022
7024 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
7025 return To;
7026 To->setLexicalDeclContext(LexicalDC);
7027 LexicalDC->addDeclInternal(To);
7028 return To;
7029}
7030
7031//----------------------------------------------------------------------------
7032// Import Statements
7033//----------------------------------------------------------------------------
7034
7036 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7037 << S->getStmtClassName();
7038 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7039}
7040
7041
7043 if (Importer.returnWithErrorInTest())
7044 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7046 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7047 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7048 // ToII is nullptr when no symbolic name is given for output operand
7049 // see ParseStmtAsm::ParseAsmOperandsOpt
7050 Names.push_back(ToII);
7051 }
7052
7053 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7054 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7055 // ToII is nullptr when no symbolic name is given for input operand
7056 // see ParseStmtAsm::ParseAsmOperandsOpt
7057 Names.push_back(ToII);
7058 }
7059
7060 SmallVector<Expr *, 4> Clobbers;
7061 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7062 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7063 Clobbers.push_back(*ClobberOrErr);
7064 else
7065 return ClobberOrErr.takeError();
7066
7067 }
7068
7069 SmallVector<Expr *, 4> Constraints;
7070 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7071 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7072 Constraints.push_back(*OutputOrErr);
7073 else
7074 return OutputOrErr.takeError();
7075 }
7076
7077 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7078 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7079 Constraints.push_back(*InputOrErr);
7080 else
7081 return InputOrErr.takeError();
7082 }
7083
7085 S->getNumLabels());
7086 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7087 return std::move(Err);
7088
7089 if (Error Err =
7090 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7091 return std::move(Err);
7092
7093 if (Error Err = ImportArrayChecked(
7094 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7095 return std::move(Err);
7096
7097 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7098 if (!AsmLocOrErr)
7099 return AsmLocOrErr.takeError();
7100 auto AsmStrOrErr = import(S->getAsmStringExpr());
7101 if (!AsmStrOrErr)
7102 return AsmStrOrErr.takeError();
7103 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7104 if (!RParenLocOrErr)
7105 return RParenLocOrErr.takeError();
7106
7107 return new (Importer.getToContext()) GCCAsmStmt(
7108 Importer.getToContext(),
7109 *AsmLocOrErr,
7110 S->isSimple(),
7111 S->isVolatile(),
7112 S->getNumOutputs(),
7113 S->getNumInputs(),
7114 Names.data(),
7115 Constraints.data(),
7116 Exprs.data(),
7117 *AsmStrOrErr,
7118 S->getNumClobbers(),
7119 Clobbers.data(),
7120 S->getNumLabels(),
7121 *RParenLocOrErr);
7122}
7123
7125
7126 Error Err = Error::success();
7127 auto ToDG = importChecked(Err, S->getDeclGroup());
7128 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7129 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7130 if (Err)
7131 return std::move(Err);
7132 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7133}
7134
7136 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7137 if (!ToSemiLocOrErr)
7138 return ToSemiLocOrErr.takeError();
7139 return new (Importer.getToContext()) NullStmt(
7140 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7141}
7142
7144 SmallVector<Stmt *, 8> ToStmts(S->size());
7145
7146 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7147 return std::move(Err);
7148
7149 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7150 if (!ToLBracLocOrErr)
7151 return ToLBracLocOrErr.takeError();
7152
7153 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7154 if (!ToRBracLocOrErr)
7155 return ToRBracLocOrErr.takeError();
7156
7157 FPOptionsOverride FPO =
7159 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7160 *ToLBracLocOrErr, *ToRBracLocOrErr);
7161}
7162
7164
7165 Error Err = Error::success();
7166 auto ToLHS = importChecked(Err, S->getLHS());
7167 auto ToRHS = importChecked(Err, S->getRHS());
7168 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7169 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7170 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7171 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7172 if (Err)
7173 return std::move(Err);
7174
7175 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7176 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7177 ToStmt->setSubStmt(ToSubStmt);
7178
7179 return ToStmt;
7180}
7181
7183
7184 Error Err = Error::success();
7185 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7186 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7187 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7188 if (Err)
7189 return std::move(Err);
7190
7191 return new (Importer.getToContext()) DefaultStmt(
7192 ToDefaultLoc, ToColonLoc, ToSubStmt);
7193}
7194
7196
7197 Error Err = Error::success();
7198 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7199 auto ToLabelDecl = importChecked(Err, S->getDecl());
7200 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7201 if (Err)
7202 return std::move(Err);
7203
7204 return new (Importer.getToContext()) LabelStmt(
7205 ToIdentLoc, ToLabelDecl, ToSubStmt);
7206}
7207
7209 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7210 if (!ToAttrLocOrErr)
7211 return ToAttrLocOrErr.takeError();
7212 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7213 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7214 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7215 return std::move(Err);
7216 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7217 if (!ToSubStmtOrErr)
7218 return ToSubStmtOrErr.takeError();
7219
7221 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7222}
7223
7225
7226 Error Err = Error::success();
7227 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7228 auto ToInit = importChecked(Err, S->getInit());
7229 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7230 auto ToCond = importChecked(Err, S->getCond());
7231 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7232 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7233 auto ToThen = importChecked(Err, S->getThen());
7234 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7235 auto ToElse = importChecked(Err, S->getElse());
7236 if (Err)
7237 return std::move(Err);
7238
7239 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7240 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7241 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7242}
7243
7245
7246 Error Err = Error::success();
7247 auto ToInit = importChecked(Err, S->getInit());
7248 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7249 auto ToCond = importChecked(Err, S->getCond());
7250 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7251 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7252 auto ToBody = importChecked(Err, S->getBody());
7253 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7254 if (Err)
7255 return std::move(Err);
7256
7257 auto *ToStmt =
7258 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7259 ToCond, ToLParenLoc, ToRParenLoc);
7260 ToStmt->setBody(ToBody);
7261 ToStmt->setSwitchLoc(ToSwitchLoc);
7262
7263 // Now we have to re-chain the cases.
7264 SwitchCase *LastChainedSwitchCase = nullptr;
7265 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7266 SC = SC->getNextSwitchCase()) {
7267 Expected<SwitchCase *> ToSCOrErr = import(SC);
7268 if (!ToSCOrErr)
7269 return ToSCOrErr.takeError();
7270 if (LastChainedSwitchCase)
7271 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7272 else
7273 ToStmt->setSwitchCaseList(*ToSCOrErr);
7274 LastChainedSwitchCase = *ToSCOrErr;
7275 }
7276
7277 return ToStmt;
7278}
7279
7281
7282 Error Err = Error::success();
7283 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7284 auto ToCond = importChecked(Err, S->getCond());
7285 auto ToBody = importChecked(Err, S->getBody());
7286 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7287 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7288 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7289 if (Err)
7290 return std::move(Err);
7291
7292 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7293 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7294}
7295
7297
7298 Error Err = Error::success();
7299 auto ToBody = importChecked(Err, S->getBody());
7300 auto ToCond = importChecked(Err, S->getCond());
7301 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7302 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7303 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7304 if (Err)
7305 return std::move(Err);
7306
7307 return new (Importer.getToContext()) DoStmt(
7308 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7309}
7310
7312
7313 Error Err = Error::success();
7314 auto ToInit = importChecked(Err, S->getInit());
7315 auto ToCond = importChecked(Err, S->getCond());
7316 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7317 auto ToInc = importChecked(Err, S->getInc());
7318 auto ToBody = importChecked(Err, S->getBody());
7319 auto ToForLoc = importChecked(Err, S->getForLoc());
7320 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7321 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7322 if (Err)
7323 return std::move(Err);
7324
7325 return new (Importer.getToContext()) ForStmt(
7326 Importer.getToContext(),
7327 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7328 ToRParenLoc);
7329}
7330
7332
7333 Error Err = Error::success();
7334 auto ToLabel = importChecked(Err, S->getLabel());
7335 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7336 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7337 if (Err)
7338 return std::move(Err);
7339
7340 return new (Importer.getToContext()) GotoStmt(
7341 ToLabel, ToGotoLoc, ToLabelLoc);
7342}
7343
7345
7346 Error Err = Error::success();
7347 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7348 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7349 auto ToTarget = importChecked(Err, S->getTarget());
7350 if (Err)
7351 return std::move(Err);
7352
7353 return new (Importer.getToContext()) IndirectGotoStmt(
7354 ToGotoLoc, ToStarLoc, ToTarget);
7355}
7356
7357template <typename StmtClass>
7359 ASTImporter &Importer, StmtClass *S) {
7360 Error Err = Error::success();
7361 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7362 auto ToLabelLoc = S->hasLabelTarget()
7363 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7364 : SourceLocation();
7365 auto ToDecl = S->hasLabelTarget()
7366 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7367 : nullptr;
7368 if (Err)
7369 return std::move(Err);
7370 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7371}
7372
7376
7380
7382
7383 Error Err = Error::success();
7384 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7385 auto ToRetValue = importChecked(Err, S->getRetValue());
7386 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7387 if (Err)
7388 return std::move(Err);
7389
7390 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7391 ToNRVOCandidate);
7392}
7393
7395
7396 Error Err = Error::success();
7397 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7398 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7399 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7400 if (Err)
7401 return std::move(Err);
7402
7403 return new (Importer.getToContext()) CXXCatchStmt (
7404 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7405}
7406
7408 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7409 if (!ToTryLocOrErr)
7410 return ToTryLocOrErr.takeError();
7411
7412 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7413 if (!ToTryBlockOrErr)
7414 return ToTryBlockOrErr.takeError();
7415
7416 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7417 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7418 CXXCatchStmt *FromHandler = S->getHandler(HI);
7419 if (auto ToHandlerOrErr = import(FromHandler))
7420 ToHandlers[HI] = *ToHandlerOrErr;
7421 else
7422 return ToHandlerOrErr.takeError();
7423 }
7424
7425 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7426 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7427}
7428
7430
7431 Error Err = Error::success();
7432 auto ToInit = importChecked(Err, S->getInit());
7433 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7434 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7435 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7436 auto ToCond = importChecked(Err, S->getCond());
7437 auto ToInc = importChecked(Err, S->getInc());
7438 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7439 auto ToBody = importChecked(Err, S->getBody());
7440 auto ToForLoc = importChecked(Err, S->getForLoc());
7441 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7442 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7443 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7444 if (Err)
7445 return std::move(Err);
7446
7447 return new (Importer.getToContext()) CXXForRangeStmt(
7448 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7449 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7450}
7451
7454 Error Err = Error::success();
7455 auto ToElement = importChecked(Err, S->getElement());
7456 auto ToCollection = importChecked(Err, S->getCollection());
7457 auto ToBody = importChecked(Err, S->getBody());
7458 auto ToForLoc = importChecked(Err, S->getForLoc());
7459 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7460 if (Err)
7461 return std::move(Err);
7462
7463 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7464 ToCollection,
7465 ToBody,
7466 ToForLoc,
7467 ToRParenLoc);
7468}
7469
7471
7472 Error Err = Error::success();
7473 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7474 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7475 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7476 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7477 if (Err)
7478 return std::move(Err);
7479
7480 return new (Importer.getToContext()) ObjCAtCatchStmt (
7481 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7482}
7483
7485 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7486 if (!ToAtFinallyLocOrErr)
7487 return ToAtFinallyLocOrErr.takeError();
7488 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7489 if (!ToAtFinallyStmtOrErr)
7490 return ToAtFinallyStmtOrErr.takeError();
7491 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7492 *ToAtFinallyStmtOrErr);
7493}
7494
7496
7497 Error Err = Error::success();
7498 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7499 auto ToTryBody = importChecked(Err, S->getTryBody());
7500 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7501 if (Err)
7502 return std::move(Err);
7503
7504 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7505 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7506 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7507 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7508 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7509 else
7510 return ToCatchStmtOrErr.takeError();
7511 }
7512
7513 return ObjCAtTryStmt::Create(Importer.getToContext(),
7514 ToAtTryLoc, ToTryBody,
7515 ToCatchStmts.begin(), ToCatchStmts.size(),
7516 ToFinallyStmt);
7517}
7518
7521
7522 Error Err = Error::success();
7523 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7524 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7525 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7526 if (Err)
7527 return std::move(Err);
7528
7529 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7530 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7531}
7532
7534 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7535 if (!ToThrowLocOrErr)
7536 return ToThrowLocOrErr.takeError();
7537 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7538 if (!ToThrowExprOrErr)
7539 return ToThrowExprOrErr.takeError();
7540 return new (Importer.getToContext()) ObjCAtThrowStmt(
7541 *ToThrowLocOrErr, *ToThrowExprOrErr);
7542}
7543
7546 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7547 if (!ToAtLocOrErr)
7548 return ToAtLocOrErr.takeError();
7549 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7550 if (!ToSubStmtOrErr)
7551 return ToSubStmtOrErr.takeError();
7552 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7553 *ToSubStmtOrErr);
7554}
7555
7556//----------------------------------------------------------------------------
7557// Import Expressions
7558//----------------------------------------------------------------------------
7560 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7561 << E->getStmtClassName();
7562 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7563}
7564
7566 Error Err = Error::success();
7567 auto ToType = importChecked(Err, E->getType());
7568 auto BLoc = importChecked(Err, E->getBeginLoc());
7569 auto RParenLoc = importChecked(Err, E->getEndLoc());
7570 if (Err)
7571 return std::move(Err);
7572 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7573 if (!ParentContextOrErr)
7574 return ParentContextOrErr.takeError();
7575
7576 return new (Importer.getToContext())
7577 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7578 RParenLoc, *ParentContextOrErr);
7579}
7580
7582
7583 Error Err = Error::success();
7584 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7585 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7586 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7587 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7588 auto ToType = importChecked(Err, E->getType());
7589 if (Err)
7590 return std::move(Err);
7591
7592 return new (Importer.getToContext()) VAArgExpr(
7593 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7594 E->isMicrosoftABI());
7595}
7596
7598
7599 Error Err = Error::success();
7600 auto ToCond = importChecked(Err, E->getCond());
7601 auto ToLHS = importChecked(Err, E->getLHS());
7602 auto ToRHS = importChecked(Err, E->getRHS());
7603 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7604 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7605 auto ToType = importChecked(Err, E->getType());
7606 if (Err)
7607 return std::move(Err);
7608
7610 ExprObjectKind OK = E->getObjectKind();
7611
7612 // The value of CondIsTrue only matters if the value is not
7613 // condition-dependent.
7614 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7615
7616 return new (Importer.getToContext())
7617 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7618 ToRParenLoc, CondIsTrue);
7619}
7620
7622 Error Err = Error::success();
7623 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7624 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7625 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7626 auto ToType = importChecked(Err, E->getType());
7627 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7628 if (Err)
7629 return std::move(Err);
7630
7632 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7633 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7635}
7636
7638 Error Err = Error::success();
7639 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7640 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7641 auto ToType = importChecked(Err, E->getType());
7642 const unsigned NumSubExprs = E->getNumSubExprs();
7643
7645 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7646 ToSubExprs.resize(NumSubExprs);
7647
7648 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7649 return std::move(Err);
7650
7651 return new (Importer.getToContext()) ShuffleVectorExpr(
7652 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7653}
7654
7656 ExpectedType TypeOrErr = import(E->getType());
7657 if (!TypeOrErr)
7658 return TypeOrErr.takeError();
7659
7660 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7661 if (!BeginLocOrErr)
7662 return BeginLocOrErr.takeError();
7663
7664 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7665}
7666
7669 Error Err = Error::success();
7670 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7671 Expr *ToControllingExpr = nullptr;
7672 TypeSourceInfo *ToControllingType = nullptr;
7673 if (E->isExprPredicate())
7674 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7675 else
7676 ToControllingType = importChecked(Err, E->getControllingType());
7677 assert((ToControllingExpr || ToControllingType) &&
7678 "Either the controlling expr or type must be nonnull");
7679 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7680 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7681 if (Err)
7682 return std::move(Err);
7683
7685 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7686 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7687 return std::move(Err);
7688
7689 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7690 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7691 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7692 return std::move(Err);
7693
7694 const ASTContext &ToCtx = Importer.getToContext();
7695 if (E->isResultDependent()) {
7696 if (ToControllingExpr) {
7698 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7699 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7701 }
7703 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7704 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7706 }
7707
7708 if (ToControllingExpr) {
7710 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7711 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7713 }
7715 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7716 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7718}
7719
7721
7722 Error Err = Error::success();
7723 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7724 auto ToType = importChecked(Err, E->getType());
7725 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7726 if (Err)
7727 return std::move(Err);
7728
7729 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7730 E->getIdentKind(), E->isTransparent(),
7731 ToFunctionName);
7732}
7733
7735
7736 Error Err = Error::success();
7737 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7738 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7739 auto ToDecl = importChecked(Err, E->getDecl());
7740 auto ToLocation = importChecked(Err, E->getLocation());
7741 auto ToType = importChecked(Err, E->getType());
7742 if (Err)
7743 return std::move(Err);
7744
7745 NamedDecl *ToFoundD = nullptr;
7746 if (E->getDecl() != E->getFoundDecl()) {
7747 auto FoundDOrErr = import(E->getFoundDecl());
7748 if (!FoundDOrErr)
7749 return FoundDOrErr.takeError();
7750 ToFoundD = *FoundDOrErr;
7751 }
7752
7753 TemplateArgumentListInfo ToTAInfo;
7754 TemplateArgumentListInfo *ToResInfo = nullptr;
7755 if (E->hasExplicitTemplateArgs()) {
7756 if (Error Err =
7758 E->template_arguments(), ToTAInfo))
7759 return std::move(Err);
7760 ToResInfo = &ToTAInfo;
7761 }
7762
7763 auto *ToE = DeclRefExpr::Create(
7764 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7765 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7766 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7767 if (E->hadMultipleCandidates())
7768 ToE->setHadMultipleCandidates(true);
7769 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7770 return ToE;
7771}
7772
7774 ExpectedType TypeOrErr = import(E->getType());
7775 if (!TypeOrErr)
7776 return TypeOrErr.takeError();
7777
7778 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7779}
7780
7782 ExpectedExpr ToInitOrErr = import(E->getInit());
7783 if (!ToInitOrErr)
7784 return ToInitOrErr.takeError();
7785
7786 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7787 if (!ToEqualOrColonLocOrErr)
7788 return ToEqualOrColonLocOrErr.takeError();
7789
7790 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7791 // List elements from the second, the first is Init itself
7792 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7793 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7794 ToIndexExprs[I - 1] = *ToArgOrErr;
7795 else
7796 return ToArgOrErr.takeError();
7797 }
7798
7799 SmallVector<Designator, 4> ToDesignators(E->size());
7800 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7801 return std::move(Err);
7802
7804 Importer.getToContext(), ToDesignators,
7805 ToIndexExprs, *ToEqualOrColonLocOrErr,
7806 E->usesGNUSyntax(), *ToInitOrErr);
7807}
7808
7811 ExpectedType ToTypeOrErr = import(E->getType());
7812 if (!ToTypeOrErr)
7813 return ToTypeOrErr.takeError();
7814
7815 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7816 if (!ToLocationOrErr)
7817 return ToLocationOrErr.takeError();
7818
7819 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7820 *ToTypeOrErr, *ToLocationOrErr);
7821}
7822
7824 ExpectedType ToTypeOrErr = import(E->getType());
7825 if (!ToTypeOrErr)
7826 return ToTypeOrErr.takeError();
7827
7828 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7829 if (!ToLocationOrErr)
7830 return ToLocationOrErr.takeError();
7831
7833 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7834}
7835
7836
7838 ExpectedType ToTypeOrErr = import(E->getType());
7839 if (!ToTypeOrErr)
7840 return ToTypeOrErr.takeError();
7841
7842 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7843 if (!ToLocationOrErr)
7844 return ToLocationOrErr.takeError();
7845
7847 Importer.getToContext(), E->getValue(), E->isExact(),
7848 *ToTypeOrErr, *ToLocationOrErr);
7849}
7850
7852 auto ToTypeOrErr = import(E->getType());
7853 if (!ToTypeOrErr)
7854 return ToTypeOrErr.takeError();
7855
7856 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7857 if (!ToSubExprOrErr)
7858 return ToSubExprOrErr.takeError();
7859
7860 return new (Importer.getToContext()) ImaginaryLiteral(
7861 *ToSubExprOrErr, *ToTypeOrErr);
7862}
7863
7865 auto ToTypeOrErr = import(E->getType());
7866 if (!ToTypeOrErr)
7867 return ToTypeOrErr.takeError();
7868
7869 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7870 if (!ToLocationOrErr)
7871 return ToLocationOrErr.takeError();
7872
7873 return new (Importer.getToContext()) FixedPointLiteral(
7874 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7875 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7876}
7877
7879 ExpectedType ToTypeOrErr = import(E->getType());
7880 if (!ToTypeOrErr)
7881 return ToTypeOrErr.takeError();
7882
7883 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7884 if (!ToLocationOrErr)
7885 return ToLocationOrErr.takeError();
7886
7887 return new (Importer.getToContext()) CharacterLiteral(
7888 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7889}
7890
7892 ExpectedType ToTypeOrErr = import(E->getType());
7893 if (!ToTypeOrErr)
7894 return ToTypeOrErr.takeError();
7895
7897 if (Error Err = ImportArrayChecked(
7898 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7899 return std::move(Err);
7900
7901 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7902 E->getKind(), E->isPascal(), *ToTypeOrErr,
7903 ToLocations);
7904}
7905
7907
7908 Error Err = Error::success();
7909 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7910 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7911 auto ToType = importChecked(Err, E->getType());
7912 auto ToInitializer = importChecked(Err, E->getInitializer());
7913 if (Err)
7914 return std::move(Err);
7915
7916 return new (Importer.getToContext()) CompoundLiteralExpr(
7917 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7918 ToInitializer, E->isFileScope());
7919}
7920
7922
7923 Error Err = Error::success();
7924 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7925 auto ToType = importChecked(Err, E->getType());
7926 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7927 if (Err)
7928 return std::move(Err);
7929
7931 if (Error Err = ImportArrayChecked(
7932 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7933 ToExprs.begin()))
7934 return std::move(Err);
7935
7936 return new (Importer.getToContext()) AtomicExpr(
7937
7938 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7939}
7940
7942 Error Err = Error::success();
7943 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7944 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7945 auto ToLabel = importChecked(Err, E->getLabel());
7946 auto ToType = importChecked(Err, E->getType());
7947 if (Err)
7948 return std::move(Err);
7949
7950 return new (Importer.getToContext()) AddrLabelExpr(
7951 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7952}
7954 Error Err = Error::success();
7955 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7956 auto ToResult = importChecked(Err, E->getAPValueResult());
7957 if (Err)
7958 return std::move(Err);
7959
7960 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7961}
7963 Error Err = Error::success();
7964 auto ToLParen = importChecked(Err, E->getLParen());
7965 auto ToRParen = importChecked(Err, E->getRParen());
7966 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7967 if (Err)
7968 return std::move(Err);
7969
7970 return new (Importer.getToContext())
7971 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7972}
7973
7975 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7976 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7977 return std::move(Err);
7978
7979 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7980 if (!ToLParenLocOrErr)
7981 return ToLParenLocOrErr.takeError();
7982
7983 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7984 if (!ToRParenLocOrErr)
7985 return ToRParenLocOrErr.takeError();
7986
7987 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7988 ToExprs, *ToRParenLocOrErr);
7989}
7990
7992 Error Err = Error::success();
7993 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7994 auto ToType = importChecked(Err, E->getType());
7995 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7996 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7997 if (Err)
7998 return std::move(Err);
7999
8000 return new (Importer.getToContext())
8001 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8002 E->getTemplateDepth());
8003}
8004
8006 Error Err = Error::success();
8007 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8008 auto ToType = importChecked(Err, E->getType());
8009 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8010 if (Err)
8011 return std::move(Err);
8012
8013 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8014 E->hasStoredFPFeatures());
8015 UO->setType(ToType);
8016 UO->setSubExpr(ToSubExpr);
8017 UO->setOpcode(E->getOpcode());
8018 UO->setOperatorLoc(ToOperatorLoc);
8019 UO->setCanOverflow(E->canOverflow());
8020 if (E->hasStoredFPFeatures())
8021 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8022
8023 return UO;
8024}
8025
8027
8029 Error Err = Error::success();
8030 auto ToType = importChecked(Err, E->getType());
8031 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8032 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8033 if (Err)
8034 return std::move(Err);
8035
8036 if (E->isArgumentType()) {
8037 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8038 import(E->getArgumentTypeInfo());
8039 if (!ToArgumentTypeInfoOrErr)
8040 return ToArgumentTypeInfoOrErr.takeError();
8041
8042 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8043 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8044 ToRParenLoc);
8045 }
8046
8047 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8048 if (!ToArgumentExprOrErr)
8049 return ToArgumentExprOrErr.takeError();
8050
8051 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8052 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8053}
8054
8056 Error Err = Error::success();
8057 auto ToLHS = importChecked(Err, E->getLHS());
8058 auto ToRHS = importChecked(Err, E->getRHS());
8059 auto ToType = importChecked(Err, E->getType());
8060 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8061 if (Err)
8062 return std::move(Err);
8063
8065 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8066 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8067 E->getFPFeatures());
8068}
8069
8071 Error Err = Error::success();
8072 auto ToCond = importChecked(Err, E->getCond());
8073 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8074 auto ToLHS = importChecked(Err, E->getLHS());
8075 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8076 auto ToRHS = importChecked(Err, E->getRHS());
8077 auto ToType = importChecked(Err, E->getType());
8078 if (Err)
8079 return std::move(Err);
8080
8081 return new (Importer.getToContext()) ConditionalOperator(
8082 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8083 E->getValueKind(), E->getObjectKind());
8084}
8085
8088 Error Err = Error::success();
8089 auto ToCommon = importChecked(Err, E->getCommon());
8090 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8091 auto ToCond = importChecked(Err, E->getCond());
8092 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8093 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8094 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8095 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8096 auto ToType = importChecked(Err, E->getType());
8097 if (Err)
8098 return std::move(Err);
8099
8100 return new (Importer.getToContext()) BinaryConditionalOperator(
8101 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8102 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8103 E->getObjectKind());
8104}
8105
8108 Error Err = Error::success();
8109 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8110 if (Err)
8111 return std::move(Err);
8112
8113 return new (Importer.getToContext())
8114 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8115}
8116
8118 Error Err = Error::success();
8119 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8120 auto ToQueriedTypeSourceInfo =
8122 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8123 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8124 auto ToType = importChecked(Err, E->getType());
8125 if (Err)
8126 return std::move(Err);
8127
8128 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8129 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8130 ToDimensionExpression, ToEndLoc, ToType);
8131}
8132
8134 Error Err = Error::success();
8135 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8136 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8137 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8138 auto ToType = importChecked(Err, E->getType());
8139 if (Err)
8140 return std::move(Err);
8141
8142 return new (Importer.getToContext()) ExpressionTraitExpr(
8143 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8144 ToEndLoc, ToType);
8145}
8146
8148 Error Err = Error::success();
8149 auto ToLocation = importChecked(Err, E->getLocation());
8150 auto ToType = importChecked(Err, E->getType());
8151 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8152 if (Err)
8153 return std::move(Err);
8154
8155 return new (Importer.getToContext()) OpaqueValueExpr(
8156 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8157}
8158
8160 Error Err = Error::success();
8161 auto ToLHS = importChecked(Err, E->getLHS());
8162 auto ToRHS = importChecked(Err, E->getRHS());
8163 auto ToType = importChecked(Err, E->getType());
8164 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8165 if (Err)
8166 return std::move(Err);
8167
8168 return new (Importer.getToContext()) ArraySubscriptExpr(
8169 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8170 ToRBracketLoc);
8171}
8172
8175 Error Err = Error::success();
8176 auto ToLHS = importChecked(Err, E->getLHS());
8177 auto ToRHS = importChecked(Err, E->getRHS());
8178 auto ToType = importChecked(Err, E->getType());
8179 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8180 auto ToComputationResultType =
8182 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8183 if (Err)
8184 return std::move(Err);
8185
8187 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8188 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8189 E->getFPFeatures(),
8190 ToComputationLHSType, ToComputationResultType);
8191}
8192
8195 CXXCastPath Path;
8196 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8197 if (auto SpecOrErr = import(*I))
8198 Path.push_back(*SpecOrErr);
8199 else
8200 return SpecOrErr.takeError();
8201 }
8202 return Path;
8203}
8204
8206 ExpectedType ToTypeOrErr = import(E->getType());
8207 if (!ToTypeOrErr)
8208 return ToTypeOrErr.takeError();
8209
8210 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8211 if (!ToSubExprOrErr)
8212 return ToSubExprOrErr.takeError();
8213
8214 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8215 if (!ToBasePathOrErr)
8216 return ToBasePathOrErr.takeError();
8217
8219 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8220 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8221}
8222
8224 Error Err = Error::success();
8225 auto ToType = importChecked(Err, E->getType());
8226 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8227 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8228 if (Err)
8229 return std::move(Err);
8230
8231 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8232 if (!ToBasePathOrErr)
8233 return ToBasePathOrErr.takeError();
8234 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8235
8236 switch (E->getStmtClass()) {
8237 case Stmt::CStyleCastExprClass: {
8238 auto *CCE = cast<CStyleCastExpr>(E);
8239 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8240 if (!ToLParenLocOrErr)
8241 return ToLParenLocOrErr.takeError();
8242 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8243 if (!ToRParenLocOrErr)
8244 return ToRParenLocOrErr.takeError();
8246 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8247 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8248 *ToLParenLocOrErr, *ToRParenLocOrErr);
8249 }
8250
8251 case Stmt::CXXFunctionalCastExprClass: {
8252 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8253 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8254 if (!ToLParenLocOrErr)
8255 return ToLParenLocOrErr.takeError();
8256 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8257 if (!ToRParenLocOrErr)
8258 return ToRParenLocOrErr.takeError();
8260 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8261 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8262 *ToLParenLocOrErr, *ToRParenLocOrErr);
8263 }
8264
8265 case Stmt::ObjCBridgedCastExprClass: {
8266 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8267 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8268 if (!ToLParenLocOrErr)
8269 return ToLParenLocOrErr.takeError();
8270 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8271 if (!ToBridgeKeywordLocOrErr)
8272 return ToBridgeKeywordLocOrErr.takeError();
8273 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8274 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8275 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8276 }
8277 case Stmt::BuiltinBitCastExprClass: {
8278 auto *BBC = cast<BuiltinBitCastExpr>(E);
8279 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8280 if (!ToKWLocOrErr)
8281 return ToKWLocOrErr.takeError();
8282 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8283 if (!ToRParenLocOrErr)
8284 return ToRParenLocOrErr.takeError();
8285 return new (Importer.getToContext()) BuiltinBitCastExpr(
8286 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8287 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8288 }
8289 default:
8290 llvm_unreachable("Cast expression of unsupported type!");
8291 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8292 }
8293}
8294
8297 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8298 const OffsetOfNode &FromNode = E->getComponent(I);
8299
8300 SourceLocation ToBeginLoc, ToEndLoc;
8301
8302 if (FromNode.getKind() != OffsetOfNode::Base) {
8303 Error Err = Error::success();
8304 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8305 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8306 if (Err)
8307 return std::move(Err);
8308 }
8309
8310 switch (FromNode.getKind()) {
8312 ToNodes.push_back(
8313 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8314 break;
8315 case OffsetOfNode::Base: {
8316 auto ToBSOrErr = import(FromNode.getBase());
8317 if (!ToBSOrErr)
8318 return ToBSOrErr.takeError();
8319 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8320 break;
8321 }
8322 case OffsetOfNode::Field: {
8323 auto ToFieldOrErr = import(FromNode.getField());
8324 if (!ToFieldOrErr)
8325 return ToFieldOrErr.takeError();
8326 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8327 break;
8328 }
8330 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8331 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8332 break;
8333 }
8334 }
8335 }
8336
8338 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8339 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8340 if (!ToIndexExprOrErr)
8341 return ToIndexExprOrErr.takeError();
8342 ToExprs[I] = *ToIndexExprOrErr;
8343 }
8344
8345 Error Err = Error::success();
8346 auto ToType = importChecked(Err, E->getType());
8347 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8348 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8349 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8350 if (Err)
8351 return std::move(Err);
8352
8353 return OffsetOfExpr::Create(
8354 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8355 ToExprs, ToRParenLoc);
8356}
8357
8359 Error Err = Error::success();
8360 auto ToType = importChecked(Err, E->getType());
8361 auto ToOperand = importChecked(Err, E->getOperand());
8362 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8363 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8364 if (Err)
8365 return std::move(Err);
8366
8367 CanThrowResult ToCanThrow;
8368 if (E->isValueDependent())
8369 ToCanThrow = CT_Dependent;
8370 else
8371 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8372
8373 return new (Importer.getToContext()) CXXNoexceptExpr(
8374 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8375}
8376
8378 Error Err = Error::success();
8379 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8380 auto ToType = importChecked(Err, E->getType());
8381 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8382 if (Err)
8383 return std::move(Err);
8384
8385 return new (Importer.getToContext()) CXXThrowExpr(
8386 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8387}
8388
8390 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8391 if (!ToUsedLocOrErr)
8392 return ToUsedLocOrErr.takeError();
8393
8394 auto ToParamOrErr = import(E->getParam());
8395 if (!ToParamOrErr)
8396 return ToParamOrErr.takeError();
8397
8398 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8399 if (!UsedContextOrErr)
8400 return UsedContextOrErr.takeError();
8401
8402 // Import the default arg if it was not imported yet.
8403 // This is needed because it can happen that during the import of the
8404 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8405 // encountered here. The default argument for a ParmVarDecl is set in the
8406 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8407 // see VisitParmVarDecl).
8408 ParmVarDecl *ToParam = *ToParamOrErr;
8409 if (!ToParam->getDefaultArg()) {
8410 std::optional<ParmVarDecl *> FromParam =
8411 Importer.getImportedFromDecl(ToParam);
8412 assert(FromParam && "ParmVarDecl was not imported?");
8413
8414 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8415 return std::move(Err);
8416 }
8417 Expr *RewrittenInit = nullptr;
8418 if (E->hasRewrittenInit()) {
8419 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8420 if (!ExprOrErr)
8421 return ExprOrErr.takeError();
8422 RewrittenInit = ExprOrErr.get();
8423 }
8424 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8425 *ToParamOrErr, RewrittenInit,
8426 *UsedContextOrErr);
8427}
8428
8431 Error Err = Error::success();
8432 auto ToType = importChecked(Err, E->getType());
8433 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8434 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8435 if (Err)
8436 return std::move(Err);
8437
8438 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8439 ToType, ToTypeSourceInfo, ToRParenLoc);
8440}
8441
8444 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8445 if (!ToSubExprOrErr)
8446 return ToSubExprOrErr.takeError();
8447
8448 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8449 if (!ToDtorOrErr)
8450 return ToDtorOrErr.takeError();
8451
8452 ASTContext &ToCtx = Importer.getToContext();
8453 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8454 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8455}
8456
8458
8460 Error Err = Error::success();
8461 auto ToConstructor = importChecked(Err, E->getConstructor());
8462 auto ToType = importChecked(Err, E->getType());
8463 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8464 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8465 if (Err)
8466 return std::move(Err);
8467
8469 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8470 return std::move(Err);
8471
8473 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8474 ToParenOrBraceRange, E->hadMultipleCandidates(),
8477}
8478
8481 DeclContext *DC, *LexicalDC;
8482 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8483 return std::move(Err);
8484
8485 Error Err = Error::success();
8486 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8487 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8488 if (Err)
8489 return std::move(Err);
8490 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8491
8493 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8494 D->getManglingNumber()))
8495 return To;
8496
8497 To->setLexicalDeclContext(LexicalDC);
8498 LexicalDC->addDeclInternal(To);
8499 return To;
8500}
8501
8504 Error Err = Error::success();
8505 auto ToType = importChecked(Err, E->getType());
8506 Expr *ToTemporaryExpr = importChecked(
8507 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8508 auto ToMaterializedDecl =
8510 if (Err)
8511 return std::move(Err);
8512
8513 if (!ToTemporaryExpr)
8514 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8515
8516 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8517 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8518 ToMaterializedDecl);
8519
8520 return ToMTE;
8521}
8522
8524 Error Err = Error::success();
8525 auto *ToPattern = importChecked(Err, E->getPattern());
8526 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8527 if (Err)
8528 return std::move(Err);
8529
8530 return new (Importer.getToContext())
8531 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8532}
8533
8535 Error Err = Error::success();
8536 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8537 auto ToPack = importChecked(Err, E->getPack());
8538 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8539 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8540 if (Err)
8541 return std::move(Err);
8542
8543 UnsignedOrNone Length = std::nullopt;
8544 if (!E->isValueDependent())
8545 Length = E->getPackLength();
8546
8547 SmallVector<TemplateArgument, 8> ToPartialArguments;
8548 if (E->isPartiallySubstituted()) {
8550 ToPartialArguments))
8551 return std::move(Err);
8552 }
8553
8555 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8556 Length, ToPartialArguments);
8557}
8558
8559
8561 Error Err = Error::success();
8562 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8563 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8564 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8565 auto ToArraySize = importChecked(Err, E->getArraySize());
8566 auto ToInitializer = importChecked(Err, E->getInitializer());
8567 auto ToType = importChecked(Err, E->getType());
8568 auto ToAllocatedTypeSourceInfo =
8570 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8571 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8572 if (Err)
8573 return std::move(Err);
8574
8575 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8576 if (Error Err =
8577 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8578 return std::move(Err);
8579
8580 return CXXNewExpr::Create(
8581 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8582 ToOperatorDelete, E->implicitAllocationParameters(),
8583 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8584 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8585 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8586}
8587
8589 Error Err = Error::success();
8590 auto ToType = importChecked(Err, E->getType());
8591 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8592 auto ToArgument = importChecked(Err, E->getArgument());
8593 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8594 if (Err)
8595 return std::move(Err);
8596
8597 return new (Importer.getToContext()) CXXDeleteExpr(
8598 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8599 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8600 ToBeginLoc);
8601}
8602
8604 Error Err = Error::success();
8605 auto ToType = importChecked(Err, E->getType());
8606 auto ToLocation = importChecked(Err, E->getLocation());
8607 auto ToConstructor = importChecked(Err, E->getConstructor());
8608 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8609 if (Err)
8610 return std::move(Err);
8611
8613 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8614 return std::move(Err);
8615
8617 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8618 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8621 ToParenOrBraceRange);
8623 return ToE;
8624}
8625
8627 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8628 if (!ToSubExprOrErr)
8629 return ToSubExprOrErr.takeError();
8630
8632 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8633 return std::move(Err);
8634
8636 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8637 ToObjects);
8638}
8639
8641 Error Err = Error::success();
8642 auto ToCallee = importChecked(Err, E->getCallee());
8643 auto ToType = importChecked(Err, E->getType());
8644 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8645 if (Err)
8646 return std::move(Err);
8647
8649 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8650 return std::move(Err);
8651
8652 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8653 ToType, E->getValueKind(), ToRParenLoc,
8654 E->getFPFeatures());
8655}
8656
8658 ExpectedType ToTypeOrErr = import(E->getType());
8659 if (!ToTypeOrErr)
8660 return ToTypeOrErr.takeError();
8661
8662 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8663 if (!ToLocationOrErr)
8664 return ToLocationOrErr.takeError();
8665
8666 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8667 *ToTypeOrErr, E->isImplicit());
8668}
8669
8671 ExpectedType ToTypeOrErr = import(E->getType());
8672 if (!ToTypeOrErr)
8673 return ToTypeOrErr.takeError();
8674
8675 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8676 if (!ToLocationOrErr)
8677 return ToLocationOrErr.takeError();
8678
8679 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8680 *ToTypeOrErr, *ToLocationOrErr);
8681}
8682
8684 Error Err = Error::success();
8685 auto ToBase = importChecked(Err, E->getBase());
8686 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8687 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8688 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8689 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8690 auto ToType = importChecked(Err, E->getType());
8691 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8692 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8693 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8694 if (Err)
8695 return std::move(Err);
8696
8697 DeclAccessPair ToFoundDecl =
8699
8700 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8701
8702 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8703 if (E->hasExplicitTemplateArgs()) {
8704 if (Error Err =
8706 E->template_arguments(), ToTAInfo))
8707 return std::move(Err);
8708 ResInfo = &ToTAInfo;
8709 }
8710
8711 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8712 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8713 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8714 ResInfo, ToType, E->getValueKind(),
8715 E->getObjectKind(), E->isNonOdrUse());
8716}
8717
8720 Error Err = Error::success();
8721 auto ToBase = importChecked(Err, E->getBase());
8722 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8723 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8724 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8725 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8726 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8727 if (Err)
8728 return std::move(Err);
8729
8731 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8732 const IdentifierInfo *ToII = Importer.Import(FromII);
8733 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8734 if (!ToDestroyedTypeLocOrErr)
8735 return ToDestroyedTypeLocOrErr.takeError();
8736 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8737 } else {
8738 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8739 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8740 else
8741 return ToTIOrErr.takeError();
8742 }
8743
8744 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8745 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8746 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8747}
8748
8751 Error Err = Error::success();
8752 auto ToType = importChecked(Err, E->getType());
8753 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8754 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8755 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8756 auto ToFirstQualifierFoundInScope =
8758 if (Err)
8759 return std::move(Err);
8760
8761 Expr *ToBase = nullptr;
8762 if (!E->isImplicitAccess()) {
8763 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8764 ToBase = *ToBaseOrErr;
8765 else
8766 return ToBaseOrErr.takeError();
8767 }
8768
8769 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8770
8771 if (E->hasExplicitTemplateArgs()) {
8772 if (Error Err =
8774 E->template_arguments(), ToTAInfo))
8775 return std::move(Err);
8776 ResInfo = &ToTAInfo;
8777 }
8778 auto ToMember = importChecked(Err, E->getMember());
8779 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8780 if (Err)
8781 return std::move(Err);
8782 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8783
8784 // Import additional name location/type info.
8785 if (Error Err =
8786 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8787 return std::move(Err);
8788
8790 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8791 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8792 ToMemberNameInfo, ResInfo);
8793}
8794
8797 Error Err = Error::success();
8798 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8799 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8800 auto ToDeclName = importChecked(Err, E->getDeclName());
8801 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8802 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8803 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8804 if (Err)
8805 return std::move(Err);
8806
8807 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8808 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8809 return std::move(Err);
8810
8811 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8812 TemplateArgumentListInfo *ResInfo = nullptr;
8813 if (E->hasExplicitTemplateArgs()) {
8814 if (Error Err =
8816 return std::move(Err);
8817 ResInfo = &ToTAInfo;
8818 }
8819
8821 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8822 ToNameInfo, ResInfo);
8823}
8824
8827 Error Err = Error::success();
8828 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8829 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8830 auto ToType = importChecked(Err, E->getType());
8831 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8832 if (Err)
8833 return std::move(Err);
8834
8836 if (Error Err =
8837 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8838 return std::move(Err);
8839
8841 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8842 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8843}
8844
8847 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8848 if (!ToNamingClassOrErr)
8849 return ToNamingClassOrErr.takeError();
8850
8851 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8852 if (!ToQualifierLocOrErr)
8853 return ToQualifierLocOrErr.takeError();
8854
8855 Error Err = Error::success();
8856 auto ToName = importChecked(Err, E->getName());
8857 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8858 if (Err)
8859 return std::move(Err);
8860 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8861
8862 // Import additional name location/type info.
8863 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8864 return std::move(Err);
8865
8866 UnresolvedSet<8> ToDecls;
8867 for (auto *D : E->decls())
8868 if (auto ToDOrErr = import(D))
8869 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8870 else
8871 return ToDOrErr.takeError();
8872
8873 if (E->hasExplicitTemplateArgs()) {
8874 TemplateArgumentListInfo ToTAInfo;
8877 ToTAInfo))
8878 return std::move(Err);
8879
8880 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8881 if (!ToTemplateKeywordLocOrErr)
8882 return ToTemplateKeywordLocOrErr.takeError();
8883
8884 const bool KnownDependent =
8885 (E->getDependence() & ExprDependence::TypeValue) ==
8886 ExprDependence::TypeValue;
8888 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8889 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8890 ToDecls.begin(), ToDecls.end(), KnownDependent,
8891 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8892 }
8893
8895 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8896 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8897 /*KnownDependent=*/E->isTypeDependent(),
8898 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8899}
8900
8903 Error Err = Error::success();
8904 auto ToType = importChecked(Err, E->getType());
8905 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8906 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8907 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8908 auto ToName = importChecked(Err, E->getName());
8909 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8910 if (Err)
8911 return std::move(Err);
8912
8913 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8914 // Import additional name location/type info.
8915 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8916 return std::move(Err);
8917
8918 UnresolvedSet<8> ToDecls;
8919 for (Decl *D : E->decls())
8920 if (auto ToDOrErr = import(D))
8921 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8922 else
8923 return ToDOrErr.takeError();
8924
8925 TemplateArgumentListInfo ToTAInfo;
8926 TemplateArgumentListInfo *ResInfo = nullptr;
8927 if (E->hasExplicitTemplateArgs()) {
8928 TemplateArgumentListInfo FromTAInfo;
8929 E->copyTemplateArgumentsInto(FromTAInfo);
8930 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8931 return std::move(Err);
8932 ResInfo = &ToTAInfo;
8933 }
8934
8935 Expr *ToBase = nullptr;
8936 if (!E->isImplicitAccess()) {
8937 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8938 ToBase = *ToBaseOrErr;
8939 else
8940 return ToBaseOrErr.takeError();
8941 }
8942
8944 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8945 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8946 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8947}
8948
8950 Error Err = Error::success();
8951 auto ToCallee = importChecked(Err, E->getCallee());
8952 auto ToType = importChecked(Err, E->getType());
8953 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8954 if (Err)
8955 return std::move(Err);
8956
8957 unsigned NumArgs = E->getNumArgs();
8958 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8959 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8960 return std::move(Err);
8961
8962 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8964 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8965 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8966 OCE->getADLCallKind());
8967 }
8968
8969 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8970 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8971 /*MinNumArgs=*/0, E->getADLCallKind());
8972}
8973
8975 CXXRecordDecl *FromClass = E->getLambdaClass();
8976 auto ToClassOrErr = import(FromClass);
8977 if (!ToClassOrErr)
8978 return ToClassOrErr.takeError();
8979 CXXRecordDecl *ToClass = *ToClassOrErr;
8980
8981 auto ToCallOpOrErr = import(E->getCallOperator());
8982 if (!ToCallOpOrErr)
8983 return ToCallOpOrErr.takeError();
8984
8985 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8986 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8987 return std::move(Err);
8988
8989 Error Err = Error::success();
8990 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8991 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8992 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8993 if (Err)
8994 return std::move(Err);
8995
8996 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8997 E->getCaptureDefault(), ToCaptureDefaultLoc,
8999 E->hasExplicitResultType(), ToCaptureInits,
9000 ToEndLoc, E->containsUnexpandedParameterPack());
9001}
9002
9003
9005 Error Err = Error::success();
9006 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9007 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9008 auto ToType = importChecked(Err, E->getType());
9009 if (Err)
9010 return std::move(Err);
9011
9012 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9013 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9014 return std::move(Err);
9015
9016 ASTContext &ToCtx = Importer.getToContext();
9017 InitListExpr *To = new (ToCtx) InitListExpr(
9018 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
9019 To->setType(ToType);
9020
9021 if (E->hasArrayFiller()) {
9022 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9023 To->setArrayFiller(*ToFillerOrErr);
9024 else
9025 return ToFillerOrErr.takeError();
9026 }
9027
9028 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9029 if (auto ToFDOrErr = import(FromFD))
9030 To->setInitializedFieldInUnion(*ToFDOrErr);
9031 else
9032 return ToFDOrErr.takeError();
9033 }
9034
9035 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9036 if (auto ToSyntFormOrErr = import(SyntForm))
9037 To->setSyntacticForm(*ToSyntFormOrErr);
9038 else
9039 return ToSyntFormOrErr.takeError();
9040 }
9041
9042 // Copy InitListExprBitfields, which are not handled in the ctor of
9043 // InitListExpr.
9045
9046 return To;
9047}
9048
9051 ExpectedType ToTypeOrErr = import(E->getType());
9052 if (!ToTypeOrErr)
9053 return ToTypeOrErr.takeError();
9054
9055 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9056 if (!ToSubExprOrErr)
9057 return ToSubExprOrErr.takeError();
9058
9059 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9060 *ToTypeOrErr, *ToSubExprOrErr);
9061}
9062
9065 Error Err = Error::success();
9066 auto ToLocation = importChecked(Err, E->getLocation());
9067 auto ToType = importChecked(Err, E->getType());
9068 auto ToConstructor = importChecked(Err, E->getConstructor());
9069 if (Err)
9070 return std::move(Err);
9071
9072 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9073 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9074 E->inheritedFromVBase());
9075}
9076
9078 Error Err = Error::success();
9079 auto ToType = importChecked(Err, E->getType());
9080 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9081 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9082 if (Err)
9083 return std::move(Err);
9084
9085 return new (Importer.getToContext()) ArrayInitLoopExpr(
9086 ToType, ToCommonExpr, ToSubExpr);
9087}
9088
9090 ExpectedType ToTypeOrErr = import(E->getType());
9091 if (!ToTypeOrErr)
9092 return ToTypeOrErr.takeError();
9093 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9094}
9095
9097 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9098 if (!ToBeginLocOrErr)
9099 return ToBeginLocOrErr.takeError();
9100
9101 auto ToFieldOrErr = import(E->getField());
9102 if (!ToFieldOrErr)
9103 return ToFieldOrErr.takeError();
9104
9105 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9106 if (!UsedContextOrErr)
9107 return UsedContextOrErr.takeError();
9108
9109 FieldDecl *ToField = *ToFieldOrErr;
9110 assert(ToField->hasInClassInitializer() &&
9111 "Field should have in-class initializer if there is a default init "
9112 "expression that uses it.");
9113 if (!ToField->getInClassInitializer()) {
9114 // The in-class initializer may be not yet set in "To" AST even if the
9115 // field is already there. This must be set here to make construction of
9116 // CXXDefaultInitExpr work.
9117 auto ToInClassInitializerOrErr =
9118 import(E->getField()->getInClassInitializer());
9119 if (!ToInClassInitializerOrErr)
9120 return ToInClassInitializerOrErr.takeError();
9121 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9122 }
9123
9124 Expr *RewrittenInit = nullptr;
9125 if (E->hasRewrittenInit()) {
9126 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9127 if (!ExprOrErr)
9128 return ExprOrErr.takeError();
9129 RewrittenInit = ExprOrErr.get();
9130 }
9131
9132 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9133 ToField, *UsedContextOrErr, RewrittenInit);
9134}
9135
9137 Error Err = Error::success();
9138 auto ToType = importChecked(Err, E->getType());
9139 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9140 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9141 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9142 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9143 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9144 if (Err)
9145 return std::move(Err);
9146
9148 CastKind CK = E->getCastKind();
9149 auto ToBasePathOrErr = ImportCastPath(E);
9150 if (!ToBasePathOrErr)
9151 return ToBasePathOrErr.takeError();
9152
9153 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9155 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9156 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9157 ToAngleBrackets);
9158 } else if (isa<CXXDynamicCastExpr>(E)) {
9160 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9161 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9162 } else if (isa<CXXReinterpretCastExpr>(E)) {
9164 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9165 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9166 } else if (isa<CXXConstCastExpr>(E)) {
9168 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9169 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9170 } else {
9171 llvm_unreachable("Unknown cast type");
9172 return make_error<ASTImportError>();
9173 }
9174}
9175
9178 Error Err = Error::success();
9179 auto ToType = importChecked(Err, E->getType());
9180 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9181 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9182 auto ToReplacement = importChecked(Err, E->getReplacement());
9183 if (Err)
9184 return std::move(Err);
9185
9186 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9187 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9189 E->getFinal());
9190}
9191
9193 Error Err = Error::success();
9194 auto ToType = importChecked(Err, E->getType());
9195 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9196 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9197 if (Err)
9198 return std::move(Err);
9199
9201 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9202 return std::move(Err);
9203
9204 if (E->isStoredAsBoolean()) {
9205 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9206 // Value is always false.
9207 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9208 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9209 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9210 }
9211 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9212 E->getTrait(), ToArgs, ToEndLoc,
9213 E->getAPValue());
9214}
9215
9217 ExpectedType ToTypeOrErr = import(E->getType());
9218 if (!ToTypeOrErr)
9219 return ToTypeOrErr.takeError();
9220
9221 auto ToSourceRangeOrErr = import(E->getSourceRange());
9222 if (!ToSourceRangeOrErr)
9223 return ToSourceRangeOrErr.takeError();
9224
9225 if (E->isTypeOperand()) {
9226 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9227 return new (Importer.getToContext()) CXXTypeidExpr(
9228 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9229 else
9230 return ToTSIOrErr.takeError();
9231 }
9232
9233 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9234 if (!ToExprOperandOrErr)
9235 return ToExprOperandOrErr.takeError();
9236
9237 return new (Importer.getToContext()) CXXTypeidExpr(
9238 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9239}
9240
9242 Error Err = Error::success();
9243
9244 QualType ToType = importChecked(Err, E->getType());
9245 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9246 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9247 Expr *ToLHS = importChecked(Err, E->getLHS());
9248 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9249 Expr *ToRHS = importChecked(Err, E->getRHS());
9250 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9251
9252 if (Err)
9253 return std::move(Err);
9254
9255 return new (Importer.getToContext())
9256 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9257 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9258}
9259
9261 Error Err = Error::success();
9262 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9263 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9264 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9265
9266 auto Body = importChecked(Err, E->getBody());
9267 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9268 if (Err)
9269 return std::move(Err);
9270 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9271 if (Error Err =
9272 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9273 return std::move(Err);
9275 E->getRequirements().size());
9276 if (Error Err =
9277 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9278 return std::move(Err);
9279 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9280 LParenLoc, LocalParameters, RParenLoc,
9281 Requirements, RBraceLoc);
9282}
9283
9286 Error Err = Error::success();
9287 auto CL = importChecked(Err, E->getConceptReference());
9288 auto CSD = importChecked(Err, E->getSpecializationDecl());
9289 if (Err)
9290 return std::move(Err);
9291 if (E->isValueDependent())
9293 Importer.getToContext(), CL,
9294 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9295 ConstraintSatisfaction Satisfaction;
9296 if (Error Err =
9298 return std::move(Err);
9300 Importer.getToContext(), CL,
9301 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9302}
9303
9306 Error Err = Error::success();
9307 auto ToType = importChecked(Err, E->getType());
9308 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9309 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9310 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9311 if (Err)
9312 return std::move(Err);
9313
9314 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9315 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9316 E->getIndex(), E->getFinal());
9317}
9318
9321 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9322 return std::move(Err);
9323 auto ToSyntOrErr = import(E->getSyntacticForm());
9324 if (!ToSyntOrErr)
9325 return ToSyntOrErr.takeError();
9326 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9327 ToSemantics, E->getResultExprIndex());
9328}
9329
9332 Error Err = Error::success();
9333 auto ToType = importChecked(Err, E->getType());
9334 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9335 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9336 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9337 if (Err)
9338 return std::move(Err);
9339
9340 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9341 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9342 return std::move(Err);
9343 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9344 E->getUserSpecifiedInitExprs().size(),
9345 ToInitLoc, ToBeginLoc, ToEndLoc);
9346}
9347
9349 CXXMethodDecl *FromMethod) {
9350 Error ImportErrors = Error::success();
9351 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9352 if (auto ImportedOrErr = import(FromOverriddenMethod))
9354 (*ImportedOrErr)->getCanonicalDecl()));
9355 else
9356 ImportErrors =
9357 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9358 }
9359 return ImportErrors;
9360}
9361
9363 ASTContext &FromContext, FileManager &FromFileManager,
9364 bool MinimalImport,
9365 std::shared_ptr<ASTImporterSharedState> SharedState)
9366 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9367 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9368 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9369
9370 // Create a default state without the lookup table: LLDB case.
9371 if (!SharedState) {
9372 this->SharedState = std::make_shared<ASTImporterSharedState>();
9373 }
9374
9375 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9376 ToContext.getTranslationUnitDecl();
9377}
9378
9379ASTImporter::~ASTImporter() = default;
9380
9382 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9383 "Try to get field index for non-field.");
9384
9385 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9386 if (!Owner)
9387 return std::nullopt;
9388
9389 unsigned Index = 0;
9390 for (const auto *D : Owner->decls()) {
9391 if (D == F)
9392 return Index;
9393
9395 ++Index;
9396 }
9397
9398 llvm_unreachable("Field was not found in its parent context.");
9399
9400 return std::nullopt;
9401}
9402
9403ASTImporter::FoundDeclsTy
9404ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9405 // We search in the redecl context because of transparent contexts.
9406 // E.g. a simple C language enum is a transparent context:
9407 // enum E { A, B };
9408 // Now if we had a global variable in the TU
9409 // int A;
9410 // then the enum constant 'A' and the variable 'A' violates ODR.
9411 // We can diagnose this only if we search in the redecl context.
9412 DeclContext *ReDC = DC->getRedeclContext();
9413 if (SharedState->getLookupTable()) {
9414 if (ReDC->isNamespace()) {
9415 // Namespaces can be reopened.
9416 // Lookup table does not handle this, we must search here in all linked
9417 // namespaces.
9418 FoundDeclsTy Result;
9419 SmallVector<Decl *, 2> NSChain =
9421 dyn_cast<NamespaceDecl>(ReDC));
9422 for (auto *D : NSChain) {
9424 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9425 Name);
9427 }
9428 return Result;
9429 } else {
9431 SharedState->getLookupTable()->lookup(ReDC, Name);
9432 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9433 }
9434 } else {
9435 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9436 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9437 // We must search by the slow case of localUncachedLookup because that is
9438 // working even if there is no LookupPtr for the DC. We could use
9439 // DC::buildLookup() to create the LookupPtr, but that would load external
9440 // decls again, we must avoid that case.
9441 // Also, even if we had the LookupPtr, we must find Decls which are not
9442 // in the LookupPtr, so we need the slow case.
9443 // These cases are handled in ASTImporterLookupTable, but we cannot use
9444 // that with LLDB since that traverses through the AST which initiates the
9445 // load of external decls again via DC::decls(). And again, we must avoid
9446 // loading external decls during the import.
9447 if (Result.empty())
9448 ReDC->localUncachedLookup(Name, Result);
9449 return Result;
9450 }
9451}
9452
9453void ASTImporter::AddToLookupTable(Decl *ToD) {
9454 SharedState->addDeclToLookup(ToD);
9455}
9456
9458 // Import the decl using ASTNodeImporter.
9459 ASTNodeImporter Importer(*this);
9460 return Importer.Visit(FromD);
9461}
9462
9464 MapImported(FromD, ToD);
9465}
9466
9469 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9470 if (Expected<Expr *> R = Import(CLE))
9472 }
9473
9474 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9475 // ASTNodeImporter.
9476 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9477}
9478
9480 if (!FromT)
9481 return FromT;
9482
9483 // Check whether we've already imported this type.
9484 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9485 ImportedTypes.find(FromT);
9486 if (Pos != ImportedTypes.end())
9487 return Pos->second;
9488
9489 // Import the type.
9490 ASTNodeImporter Importer(*this);
9491 ExpectedType ToTOrErr = Importer.Visit(FromT);
9492 if (!ToTOrErr)
9493 return ToTOrErr.takeError();
9494
9495 // Record the imported type.
9496 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9497
9498 return ToTOrErr->getTypePtr();
9499}
9500
9502 if (FromT.isNull())
9503 return QualType{};
9504
9505 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9506 if (!ToTyOrErr)
9507 return ToTyOrErr.takeError();
9508
9509 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9510}
9511
9513 if (!FromTSI)
9514 return FromTSI;
9515
9516 // FIXME: For now we just create a "trivial" type source info based
9517 // on the type and a single location. Implement a real version of this.
9518 ExpectedType TOrErr = Import(FromTSI->getType());
9519 if (!TOrErr)
9520 return TOrErr.takeError();
9521 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9522 if (!BeginLocOrErr)
9523 return BeginLocOrErr.takeError();
9524
9525 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9526}
9527
9528namespace {
9529// To use this object, it should be created before the new attribute is created,
9530// and destructed after it is created. The construction already performs the
9531// import of the data.
9532template <typename T> struct AttrArgImporter {
9533 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9534 AttrArgImporter(AttrArgImporter<T> &&) = default;
9535 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9536 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9537
9538 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9539 : To(I.importChecked(Err, From)) {}
9540
9541 const T &value() { return To; }
9542
9543private:
9544 T To;
9545};
9546
9547// To use this object, it should be created before the new attribute is created,
9548// and destructed after it is created. The construction already performs the
9549// import of the data. The array data is accessible in a pointer form, this form
9550// is used by the attribute classes. This object should be created once for the
9551// array data to be imported (the array size is not imported, just copied).
9552template <typename T> struct AttrArgArrayImporter {
9553 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9554 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9555 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9556 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9557
9558 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9559 const llvm::iterator_range<T *> &From,
9560 unsigned ArraySize) {
9561 if (Err)
9562 return;
9563 To.reserve(ArraySize);
9564 Err = I.ImportContainerChecked(From, To);
9565 }
9566
9567 T *value() { return To.data(); }
9568
9569private:
9570 llvm::SmallVector<T, 2> To;
9571};
9572
9573class AttrImporter {
9574 Error Err{Error::success()};
9575 Attr *ToAttr = nullptr;
9576 ASTImporter &Importer;
9577 ASTNodeImporter NImporter;
9578
9579public:
9580 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9581
9582 // Useful for accessing the imported attribute.
9583 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9584 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9585
9586 // Create an "importer" for an attribute parameter.
9587 // Result of the 'value()' of that object is to be passed to the function
9588 // 'importAttr', in the order that is expected by the attribute class.
9589 template <class T> AttrArgImporter<T> importArg(const T &From) {
9590 return AttrArgImporter<T>(NImporter, Err, From);
9591 }
9592
9593 // Create an "importer" for an attribute parameter that has array type.
9594 // Result of the 'value()' of that object is to be passed to the function
9595 // 'importAttr', then the size of the array as next argument.
9596 template <typename T>
9597 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9598 unsigned ArraySize) {
9599 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9600 }
9601
9602 // Create an attribute object with the specified arguments.
9603 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9604 // should be values that are passed to the 'Create' function of the attribute.
9605 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9606 // used here.) As much data is copied or imported from the old attribute
9607 // as possible. The passed arguments should be already imported.
9608 // If an import error happens, the internal error is set to it, and any
9609 // further import attempt is ignored.
9610 template <typename T, typename... Arg>
9611 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9612 static_assert(std::is_base_of<Attr, T>::value,
9613 "T should be subclass of Attr.");
9614 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9615
9616 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9617 const IdentifierInfo *ToScopeName =
9618 Importer.Import(FromAttr->getScopeName());
9619 SourceRange ToAttrRange =
9620 NImporter.importChecked(Err, FromAttr->getRange());
9621 SourceLocation ToScopeLoc =
9622 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9623
9624 if (Err)
9625 return;
9626
9627 AttributeCommonInfo ToI(
9628 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9629 FromAttr->getParsedKind(), FromAttr->getForm());
9630 // The "SemanticSpelling" is not needed to be passed to the constructor.
9631 // That value is recalculated from the SpellingListIndex if needed.
9632 ToAttr = T::Create(Importer.getToContext(),
9633 std::forward<Arg>(ImportedArg)..., ToI);
9634
9635 ToAttr->setImplicit(FromAttr->isImplicit());
9636 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9637 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9638 ToInheritableAttr->setInherited(FromAttr->isInherited());
9639 }
9640
9641 // Create a clone of the 'FromAttr' and import its source range only.
9642 // This causes objects with invalid references to be created if the 'FromAttr'
9643 // contains other data that should be imported.
9644 void cloneAttr(const Attr *FromAttr) {
9645 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9646
9647 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9648 if (Err)
9649 return;
9650
9651 ToAttr = FromAttr->clone(Importer.getToContext());
9652 ToAttr->setRange(ToRange);
9653 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9654 }
9655
9656 // Get the result of the previous import attempt (can be used only once).
9657 llvm::Expected<Attr *> getResult() && {
9658 if (Err)
9659 return std::move(Err);
9660 assert(ToAttr && "Attribute should be created.");
9661 return ToAttr;
9662 }
9663};
9664} // namespace
9665
9667 AttrImporter AI(*this);
9668
9669 // FIXME: Is there some kind of AttrVisitor to use here?
9670 switch (FromAttr->getKind()) {
9671 case attr::Aligned: {
9672 auto *From = cast<AlignedAttr>(FromAttr);
9673 if (From->isAlignmentExpr())
9674 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9675 else
9676 AI.importAttr(From, false,
9677 AI.importArg(From->getAlignmentType()).value());
9678 break;
9679 }
9680
9681 case attr::AlignValue: {
9682 auto *From = cast<AlignValueAttr>(FromAttr);
9683 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9684 break;
9685 }
9686
9687 case attr::Format: {
9688 const auto *From = cast<FormatAttr>(FromAttr);
9689 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9690 From->getFirstArg());
9691 break;
9692 }
9693
9694 case attr::EnableIf: {
9695 const auto *From = cast<EnableIfAttr>(FromAttr);
9696 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9697 From->getMessage());
9698 break;
9699 }
9700
9701 case attr::AssertCapability: {
9702 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9703 AI.importAttr(From,
9704 AI.importArrayArg(From->args(), From->args_size()).value(),
9705 From->args_size());
9706 break;
9707 }
9708 case attr::AcquireCapability: {
9709 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9710 AI.importAttr(From,
9711 AI.importArrayArg(From->args(), From->args_size()).value(),
9712 From->args_size());
9713 break;
9714 }
9715 case attr::TryAcquireCapability: {
9716 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9717 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9718 AI.importArrayArg(From->args(), From->args_size()).value(),
9719 From->args_size());
9720 break;
9721 }
9722 case attr::ReleaseCapability: {
9723 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9724 AI.importAttr(From,
9725 AI.importArrayArg(From->args(), From->args_size()).value(),
9726 From->args_size());
9727 break;
9728 }
9729 case attr::RequiresCapability: {
9730 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9731 AI.importAttr(From,
9732 AI.importArrayArg(From->args(), From->args_size()).value(),
9733 From->args_size());
9734 break;
9735 }
9736 case attr::GuardedBy: {
9737 const auto *From = cast<GuardedByAttr>(FromAttr);
9738 AI.importAttr(From, AI.importArg(From->getArg()).value());
9739 break;
9740 }
9741 case attr::PtGuardedBy: {
9742 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9743 AI.importAttr(From, AI.importArg(From->getArg()).value());
9744 break;
9745 }
9746 case attr::AcquiredAfter: {
9747 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9748 AI.importAttr(From,
9749 AI.importArrayArg(From->args(), From->args_size()).value(),
9750 From->args_size());
9751 break;
9752 }
9753 case attr::AcquiredBefore: {
9754 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9755 AI.importAttr(From,
9756 AI.importArrayArg(From->args(), From->args_size()).value(),
9757 From->args_size());
9758 break;
9759 }
9760 case attr::LockReturned: {
9761 const auto *From = cast<LockReturnedAttr>(FromAttr);
9762 AI.importAttr(From, AI.importArg(From->getArg()).value());
9763 break;
9764 }
9765 case attr::LocksExcluded: {
9766 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9767 AI.importAttr(From,
9768 AI.importArrayArg(From->args(), From->args_size()).value(),
9769 From->args_size());
9770 break;
9771 }
9772 default: {
9773 // The default branch works for attributes that have no arguments to import.
9774 // FIXME: Handle every attribute type that has arguments of type to import
9775 // (most often Expr* or Decl* or type) in the switch above.
9776 AI.cloneAttr(FromAttr);
9777 break;
9778 }
9779 }
9780
9781 return std::move(AI).getResult();
9782}
9783
9785 return ImportedDecls.lookup(FromD);
9786}
9787
9789 auto FromDPos = ImportedFromDecls.find(ToD);
9790 if (FromDPos == ImportedFromDecls.end())
9791 return nullptr;
9792 return FromDPos->second->getTranslationUnitDecl();
9793}
9794
9796 if (!FromD)
9797 return nullptr;
9798
9799 // Push FromD to the stack, and remove that when we return.
9800 ImportPath.push(FromD);
9801 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9802
9803 // Check whether there was a previous failed import.
9804 // If yes return the existing error.
9805 if (auto Error = getImportDeclErrorIfAny(FromD))
9806 return make_error<ASTImportError>(*Error);
9807
9808 // Check whether we've already imported this declaration.
9809 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9810 if (ToD) {
9811 // Already imported (possibly from another TU) and with an error.
9812 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9813 setImportDeclError(FromD, *Error);
9814 return make_error<ASTImportError>(*Error);
9815 }
9816
9817 // If FromD has some updated flags after last import, apply it.
9818 updateFlags(FromD, ToD);
9819 // If we encounter a cycle during an import then we save the relevant part
9820 // of the import path associated to the Decl.
9821 if (ImportPath.hasCycleAtBack())
9822 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9823 return ToD;
9824 }
9825
9826 // Import the declaration.
9827 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9828 if (!ToDOrErr) {
9829 // Failed to import.
9830
9831 auto Pos = ImportedDecls.find(FromD);
9832 if (Pos != ImportedDecls.end()) {
9833 // Import failed after the object was created.
9834 // Remove all references to it.
9835 auto *ToD = Pos->second;
9836 ImportedDecls.erase(Pos);
9837
9838 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9839 // (e.g. with namespaces) that several decls from the 'from' context are
9840 // mapped to the same decl in the 'to' context. If we removed entries
9841 // from the LookupTable here then we may end up removing them multiple
9842 // times.
9843
9844 // The Lookuptable contains decls only which are in the 'to' context.
9845 // Remove from the Lookuptable only if it is *imported* into the 'to'
9846 // context (and do not remove it if it was added during the initial
9847 // traverse of the 'to' context).
9848 auto PosF = ImportedFromDecls.find(ToD);
9849 if (PosF != ImportedFromDecls.end()) {
9850 // In the case of TypedefNameDecl we create the Decl first and only
9851 // then we import and set its DeclContext. So, the DC might not be set
9852 // when we reach here.
9853 if (ToD->getDeclContext())
9854 SharedState->removeDeclFromLookup(ToD);
9855 ImportedFromDecls.erase(PosF);
9856 }
9857
9858 // FIXME: AST may contain remaining references to the failed object.
9859 // However, the ImportDeclErrors in the shared state contains all the
9860 // failed objects together with their error.
9861 }
9862
9863 // Error encountered for the first time.
9864 // After takeError the error is not usable any more in ToDOrErr.
9865 // Get a copy of the error object (any more simple solution for this?).
9866 ASTImportError ErrOut;
9867 handleAllErrors(ToDOrErr.takeError(),
9868 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9869 setImportDeclError(FromD, ErrOut);
9870 // Set the error for the mapped to Decl, which is in the "to" context.
9871 if (Pos != ImportedDecls.end())
9872 SharedState->setImportDeclError(Pos->second, ErrOut);
9873
9874 // Set the error for all nodes which have been created before we
9875 // recognized the error.
9876 for (const auto &Path : SavedImportPaths[FromD]) {
9877 // The import path contains import-dependency nodes first.
9878 // Save the node that was imported as dependency of the current node.
9879 Decl *PrevFromDi = FromD;
9880 for (Decl *FromDi : Path) {
9881 // Begin and end of the path equals 'FromD', skip it.
9882 if (FromDi == FromD)
9883 continue;
9884 // We should not set import error on a node and all following nodes in
9885 // the path if child import errors are ignored.
9886 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9887 PrevFromDi))
9888 break;
9889 PrevFromDi = FromDi;
9890 setImportDeclError(FromDi, ErrOut);
9891 //FIXME Should we remove these Decls from ImportedDecls?
9892 // Set the error for the mapped to Decl, which is in the "to" context.
9893 auto Ii = ImportedDecls.find(FromDi);
9894 if (Ii != ImportedDecls.end())
9895 SharedState->setImportDeclError(Ii->second, ErrOut);
9896 // FIXME Should we remove these Decls from the LookupTable,
9897 // and from ImportedFromDecls?
9898 }
9899 }
9900 SavedImportPaths.erase(FromD);
9901
9902 // Do not return ToDOrErr, error was taken out of it.
9903 return make_error<ASTImportError>(ErrOut);
9904 }
9905
9906 ToD = *ToDOrErr;
9907
9908 // FIXME: Handle the "already imported with error" case. We can get here
9909 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9910 // previously failed create was requested).
9911 // Later GetImportedOrCreateDecl can be updated to return the error.
9912 if (!ToD) {
9913 auto Err = getImportDeclErrorIfAny(FromD);
9914 assert(Err);
9915 return make_error<ASTImportError>(*Err);
9916 }
9917
9918 // We could import from the current TU without error. But previously we
9919 // already had imported a Decl as `ToD` from another TU (with another
9920 // ASTImporter object) and with an error.
9921 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9922 setImportDeclError(FromD, *Error);
9923 return make_error<ASTImportError>(*Error);
9924 }
9925 // Make sure that ImportImpl registered the imported decl.
9926 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9927
9928 if (FromD->hasAttrs())
9929 for (const Attr *FromAttr : FromD->getAttrs()) {
9930 auto ToAttrOrErr = Import(FromAttr);
9931 if (ToAttrOrErr)
9932 ToD->addAttr(*ToAttrOrErr);
9933 else
9934 return ToAttrOrErr.takeError();
9935 }
9936
9937 // Notify subclasses.
9938 Imported(FromD, ToD);
9939
9940 updateFlags(FromD, ToD);
9941 SavedImportPaths.erase(FromD);
9942 return ToDOrErr;
9943}
9944
9947 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9948}
9949
9951 if (!FromDC)
9952 return FromDC;
9953
9954 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9955 if (!ToDCOrErr)
9956 return ToDCOrErr.takeError();
9957 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9958
9959 // When we're using a record/enum/Objective-C class/protocol as a context, we
9960 // need it to have a definition.
9961 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9962 auto *FromRecord = cast<RecordDecl>(FromDC);
9963 if (ToRecord->isCompleteDefinition())
9964 return ToDC;
9965
9966 // If FromRecord is not defined we need to force it to be.
9967 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9968 // it will start the definition but we never finish it.
9969 // If there are base classes they won't be imported and we will
9970 // be missing anything that we inherit from those bases.
9971 if (FromRecord->getASTContext().getExternalSource() &&
9972 !FromRecord->isCompleteDefinition())
9973 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9974
9975 if (FromRecord->isCompleteDefinition())
9976 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9977 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9978 return std::move(Err);
9979 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9980 auto *FromEnum = cast<EnumDecl>(FromDC);
9981 if (ToEnum->isCompleteDefinition()) {
9982 // Do nothing.
9983 } else if (FromEnum->isCompleteDefinition()) {
9984 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9985 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9986 return std::move(Err);
9987 } else {
9988 CompleteDecl(ToEnum);
9989 }
9990 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9991 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9992 if (ToClass->getDefinition()) {
9993 // Do nothing.
9994 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9995 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9996 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9997 return std::move(Err);
9998 } else {
9999 CompleteDecl(ToClass);
10000 }
10001 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10002 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10003 if (ToProto->getDefinition()) {
10004 // Do nothing.
10005 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10006 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10007 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10008 return std::move(Err);
10009 } else {
10010 CompleteDecl(ToProto);
10011 }
10012 }
10013
10014 return ToDC;
10015}
10016
10018 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10019 return cast_or_null<Expr>(*ToSOrErr);
10020 else
10021 return ToSOrErr.takeError();
10022}
10023
10025 if (!FromS)
10026 return nullptr;
10027
10028 // Check whether we've already imported this statement.
10029 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10030 if (Pos != ImportedStmts.end())
10031 return Pos->second;
10032
10033 // Import the statement.
10034 ASTNodeImporter Importer(*this);
10035 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10036 if (!ToSOrErr)
10037 return ToSOrErr;
10038
10039 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10040 auto *FromE = cast<Expr>(FromS);
10041 // Copy ExprBitfields, which may not be handled in Expr subclasses
10042 // constructors.
10043 ToE->setValueKind(FromE->getValueKind());
10044 ToE->setObjectKind(FromE->getObjectKind());
10045 ToE->setDependence(FromE->getDependence());
10046 }
10047
10048 // Record the imported statement object.
10049 ImportedStmts[FromS] = *ToSOrErr;
10050 return ToSOrErr;
10051}
10052
10054 switch (FromNNS.getKind()) {
10057 return FromNNS;
10059 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10060 auto NSOrErr = Import(Namespace);
10061 if (!NSOrErr)
10062 return NSOrErr.takeError();
10063 auto PrefixOrErr = Import(Prefix);
10064 if (!PrefixOrErr)
10065 return PrefixOrErr.takeError();
10066 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10067 *PrefixOrErr);
10068 }
10070 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10071 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10072 else
10073 return RDOrErr.takeError();
10075 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10076 return NestedNameSpecifier(*TyOrErr);
10077 } else {
10078 return TyOrErr.takeError();
10079 }
10080 }
10081 llvm_unreachable("Invalid nested name specifier kind");
10082}
10083
10086 // Copied from NestedNameSpecifier mostly.
10088 NestedNameSpecifierLoc NNS = FromNNS;
10089
10090 // Push each of the nested-name-specifiers's onto a stack for
10091 // serialization in reverse order.
10092 while (NNS) {
10093 NestedNames.push_back(NNS);
10094 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10095 }
10096
10098
10099 while (!NestedNames.empty()) {
10100 NNS = NestedNames.pop_back_val();
10101 NestedNameSpecifier Spec = std::nullopt;
10102 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10103 return std::move(Err);
10104
10105 NestedNameSpecifier::Kind Kind = Spec.getKind();
10106
10107 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10109 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10110 return std::move(Err);
10111
10113 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10114 return std::move(Err);
10115 }
10116
10117 switch (Kind) {
10119 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10120 ToLocalBeginLoc, ToLocalEndLoc);
10121 break;
10122
10124 SourceLocation ToTLoc;
10125 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10126 return std::move(Err);
10128 QualType(Spec.getAsType(), 0), ToTLoc);
10129 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10130 break;
10131 }
10132
10134 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10135 break;
10136
10138 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10139 if (!ToSourceRangeOrErr)
10140 return ToSourceRangeOrErr.takeError();
10141
10142 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10143 ToSourceRangeOrErr->getBegin(),
10144 ToSourceRangeOrErr->getEnd());
10145 break;
10146 }
10148 llvm_unreachable("unexpected null nested name specifier");
10149 }
10150 }
10151
10152 return Builder.getWithLocInContext(getToContext());
10153}
10154
10156 switch (From.getKind()) {
10158 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10159 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10160 else
10161 return ToTemplateOrErr.takeError();
10162
10165 UnresolvedSet<2> ToTemplates;
10166 for (auto *I : *FromStorage) {
10167 if (auto ToOrErr = Import(I))
10168 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10169 else
10170 return ToOrErr.takeError();
10171 }
10172 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10173 ToTemplates.end());
10174 }
10175
10178 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10179 if (!DeclNameOrErr)
10180 return DeclNameOrErr.takeError();
10181 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10182 }
10183
10186 auto QualifierOrErr = Import(QTN->getQualifier());
10187 if (!QualifierOrErr)
10188 return QualifierOrErr.takeError();
10189 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10190 if (!TNOrErr)
10191 return TNOrErr.takeError();
10192 return ToContext.getQualifiedTemplateName(
10193 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10194 }
10195
10198 auto QualifierOrErr = Import(DTN->getQualifier());
10199 if (!QualifierOrErr)
10200 return QualifierOrErr.takeError();
10201 return ToContext.getDependentTemplateName(
10202 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10203 }
10204
10208 auto ReplacementOrErr = Import(Subst->getReplacement());
10209 if (!ReplacementOrErr)
10210 return ReplacementOrErr.takeError();
10211
10212 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10213 if (!AssociatedDeclOrErr)
10214 return AssociatedDeclOrErr.takeError();
10215
10216 return ToContext.getSubstTemplateTemplateParm(
10217 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10218 Subst->getPackIndex(), Subst->getFinal());
10219 }
10220
10224 ASTNodeImporter Importer(*this);
10225 auto ArgPackOrErr =
10226 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10227 if (!ArgPackOrErr)
10228 return ArgPackOrErr.takeError();
10229
10230 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10231 if (!AssociatedDeclOrErr)
10232 return AssociatedDeclOrErr.takeError();
10233
10234 return ToContext.getSubstTemplateTemplateParmPack(
10235 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10236 SubstPack->getFinal());
10237 }
10239 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10240 if (!UsingOrError)
10241 return UsingOrError.takeError();
10242 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10243 }
10245 llvm_unreachable("Unexpected DeducedTemplate");
10246 }
10247
10248 llvm_unreachable("Invalid template name kind");
10249}
10250
10252 if (FromLoc.isInvalid())
10253 return SourceLocation{};
10254
10255 SourceManager &FromSM = FromContext.getSourceManager();
10256 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10257
10258 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10259 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10260 if (!ToFileIDOrErr)
10261 return ToFileIDOrErr.takeError();
10262 SourceManager &ToSM = ToContext.getSourceManager();
10263 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10264}
10265
10267 SourceLocation ToBegin, ToEnd;
10268 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10269 return std::move(Err);
10270 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10271 return std::move(Err);
10272
10273 return SourceRange(ToBegin, ToEnd);
10274}
10275
10277 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10278 if (Pos != ImportedFileIDs.end())
10279 return Pos->second;
10280
10281 SourceManager &FromSM = FromContext.getSourceManager();
10282 SourceManager &ToSM = ToContext.getSourceManager();
10283 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10284
10285 // Map the FromID to the "to" source manager.
10286 FileID ToID;
10287 if (FromSLoc.isExpansion()) {
10288 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10289 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10290 if (!ToSpLoc)
10291 return ToSpLoc.takeError();
10292 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10293 if (!ToExLocS)
10294 return ToExLocS.takeError();
10295 unsigned ExLength = FromSM.getFileIDSize(FromID);
10296 SourceLocation MLoc;
10297 if (FromEx.isMacroArgExpansion()) {
10298 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10299 } else {
10300 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10301 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10302 FromEx.isExpansionTokenRange());
10303 else
10304 return ToExLocE.takeError();
10305 }
10306 ToID = ToSM.getFileID(MLoc);
10307 } else {
10308 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10309
10310 if (!IsBuiltin && !Cache->BufferOverridden) {
10311 // Include location of this file.
10312 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10313 if (!ToIncludeLoc)
10314 return ToIncludeLoc.takeError();
10315
10316 // Every FileID that is not the main FileID needs to have a valid include
10317 // location so that the include chain points to the main FileID. When
10318 // importing the main FileID (which has no include location), we need to
10319 // create a fake include location in the main file to keep this property
10320 // intact.
10321 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10322 if (FromID == FromSM.getMainFileID())
10323 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10324
10325 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10326 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10327 // the disk again
10328 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10329 // than mmap the files several times.
10330 auto Entry =
10331 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10332 // FIXME: The filename may be a virtual name that does probably not
10333 // point to a valid file and we get no Entry here. In this case try with
10334 // the memory buffer below.
10335 if (Entry)
10336 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10337 FromSLoc.getFile().getFileCharacteristic());
10338 }
10339 }
10340
10341 if (ToID.isInvalid() || IsBuiltin) {
10342 // FIXME: We want to re-use the existing MemoryBuffer!
10343 std::optional<llvm::MemoryBufferRef> FromBuf =
10344 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10345 FromSM.getFileManager(), SourceLocation{});
10346 if (!FromBuf)
10347 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10348
10349 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10350 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10351 FromBuf->getBufferIdentifier());
10352 ToID = ToSM.createFileID(std::move(ToBuf),
10353 FromSLoc.getFile().getFileCharacteristic());
10354 }
10355 }
10356
10357 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10358
10359 ImportedFileIDs[FromID] = ToID;
10360 return ToID;
10361}
10362
10364 ExpectedExpr ToExprOrErr = Import(From->getInit());
10365 if (!ToExprOrErr)
10366 return ToExprOrErr.takeError();
10367
10368 auto LParenLocOrErr = Import(From->getLParenLoc());
10369 if (!LParenLocOrErr)
10370 return LParenLocOrErr.takeError();
10371
10372 auto RParenLocOrErr = Import(From->getRParenLoc());
10373 if (!RParenLocOrErr)
10374 return RParenLocOrErr.takeError();
10375
10376 if (From->isBaseInitializer()) {
10377 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10378 if (!ToTInfoOrErr)
10379 return ToTInfoOrErr.takeError();
10380
10381 SourceLocation EllipsisLoc;
10382 if (From->isPackExpansion())
10383 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10384 return std::move(Err);
10385
10386 return new (ToContext) CXXCtorInitializer(
10387 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10388 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10389 } else if (From->isMemberInitializer()) {
10390 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10391 if (!ToFieldOrErr)
10392 return ToFieldOrErr.takeError();
10393
10394 auto MemberLocOrErr = Import(From->getMemberLocation());
10395 if (!MemberLocOrErr)
10396 return MemberLocOrErr.takeError();
10397
10398 return new (ToContext) CXXCtorInitializer(
10399 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10400 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10401 } else if (From->isIndirectMemberInitializer()) {
10402 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10403 if (!ToIFieldOrErr)
10404 return ToIFieldOrErr.takeError();
10405
10406 auto MemberLocOrErr = Import(From->getMemberLocation());
10407 if (!MemberLocOrErr)
10408 return MemberLocOrErr.takeError();
10409
10410 return new (ToContext) CXXCtorInitializer(
10411 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10412 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10413 } else if (From->isDelegatingInitializer()) {
10414 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10415 if (!ToTInfoOrErr)
10416 return ToTInfoOrErr.takeError();
10417
10418 return new (ToContext)
10419 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10420 *ToExprOrErr, *RParenLocOrErr);
10421 } else {
10422 // FIXME: assert?
10423 return make_error<ASTImportError>();
10424 }
10425}
10426
10429 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10430 if (Pos != ImportedCXXBaseSpecifiers.end())
10431 return Pos->second;
10432
10433 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10434 if (!ToSourceRange)
10435 return ToSourceRange.takeError();
10437 if (!ToTSI)
10438 return ToTSI.takeError();
10439 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10440 if (!ToEllipsisLoc)
10441 return ToEllipsisLoc.takeError();
10442 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10443 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10444 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10445 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10446 return Imported;
10447}
10448
10450 ASTNodeImporter Importer(*this);
10451 return Importer.ImportAPValue(FromValue);
10452}
10453
10455 ExpectedDecl ToOrErr = Import(From);
10456 if (!ToOrErr)
10457 return ToOrErr.takeError();
10458 Decl *To = *ToOrErr;
10459
10460 auto *FromDC = cast<DeclContext>(From);
10461 ASTNodeImporter Importer(*this);
10462
10463 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10464 if (!ToRecord->getDefinition()) {
10465 return Importer.ImportDefinition(
10466 cast<RecordDecl>(FromDC), ToRecord,
10468 }
10469 }
10470
10471 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10472 if (!ToEnum->getDefinition()) {
10473 return Importer.ImportDefinition(
10475 }
10476 }
10477
10478 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10479 if (!ToIFace->getDefinition()) {
10480 return Importer.ImportDefinition(
10481 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10483 }
10484 }
10485
10486 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10487 if (!ToProto->getDefinition()) {
10488 return Importer.ImportDefinition(
10489 cast<ObjCProtocolDecl>(FromDC), ToProto,
10491 }
10492 }
10493
10494 return Importer.ImportDeclContext(FromDC, true);
10495}
10496
10498 if (!FromName)
10499 return DeclarationName{};
10500
10501 switch (FromName.getNameKind()) {
10503 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10504
10508 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10509 return DeclarationName(*ToSelOrErr);
10510 else
10511 return ToSelOrErr.takeError();
10512
10514 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10515 return ToContext.DeclarationNames.getCXXConstructorName(
10516 ToContext.getCanonicalType(*ToTyOrErr));
10517 else
10518 return ToTyOrErr.takeError();
10519 }
10520
10522 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10523 return ToContext.DeclarationNames.getCXXDestructorName(
10524 ToContext.getCanonicalType(*ToTyOrErr));
10525 else
10526 return ToTyOrErr.takeError();
10527 }
10528
10530 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10531 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10532 cast<TemplateDecl>(*ToTemplateOrErr));
10533 else
10534 return ToTemplateOrErr.takeError();
10535 }
10536
10538 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10539 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10540 ToContext.getCanonicalType(*ToTyOrErr));
10541 else
10542 return ToTyOrErr.takeError();
10543 }
10544
10546 return ToContext.DeclarationNames.getCXXOperatorName(
10547 FromName.getCXXOverloadedOperator());
10548
10550 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10551 Import(FromName.getCXXLiteralIdentifier()));
10552
10554 // FIXME: STATICS!
10556 }
10557
10558 llvm_unreachable("Invalid DeclarationName Kind!");
10559}
10560
10562 if (!FromId)
10563 return nullptr;
10564
10565 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10566
10567 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10568 ToId->setBuiltinID(FromId->getBuiltinID());
10569
10570 return ToId;
10571}
10572
10575 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10576 return Import(FromII);
10577 return FromIO.getOperator();
10578}
10579
10581 if (FromSel.isNull())
10582 return Selector{};
10583
10585 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10586 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10587 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10588 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10589}
10590
10594 llvm::Error Err = llvm::Error::success();
10595 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10596 for (unsigned Idx = 0; Idx < Size; Idx++) {
10597 APValue Tmp = importChecked(Err, From[Idx]);
10598 To[Idx] = Tmp;
10599 }
10600 };
10601 switch (FromValue.getKind()) {
10602 case APValue::None:
10604 case APValue::Int:
10605 case APValue::Float:
10609 Result = FromValue;
10610 break;
10611 case APValue::Vector: {
10612 Result.MakeVector();
10614 Result.setVectorUninit(FromValue.getVectorLength());
10615 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10616 Elts.data(), FromValue.getVectorLength());
10617 break;
10618 }
10619 case APValue::Array:
10620 Result.MakeArray(FromValue.getArrayInitializedElts(),
10621 FromValue.getArraySize());
10622 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10623 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10624 FromValue.getArrayInitializedElts());
10625 break;
10626 case APValue::Struct:
10627 Result.MakeStruct(FromValue.getStructNumBases(),
10628 FromValue.getStructNumFields());
10629 ImportLoop(
10630 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10631 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10632 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10633 break;
10634 case APValue::Union: {
10635 Result.MakeUnion();
10636 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10637 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10638 if (Err)
10639 return std::move(Err);
10640 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10641 break;
10642 }
10644 Result.MakeAddrLabelDiff();
10645 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10646 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10647 if (Err)
10648 return std::move(Err);
10649 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10650 cast<AddrLabelExpr>(ImpRHS));
10651 break;
10652 }
10654 const Decl *ImpMemPtrDecl =
10655 importChecked(Err, FromValue.getMemberPointerDecl());
10656 if (Err)
10657 return std::move(Err);
10659 Result.setMemberPointerUninit(
10660 cast<const ValueDecl>(ImpMemPtrDecl),
10662 FromValue.getMemberPointerPath().size());
10663 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10664 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10665 Idx++) {
10666 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10667 if (Err)
10668 return std::move(Err);
10669 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10670 }
10671 break;
10672 }
10673 case APValue::LValue:
10675 QualType FromElemTy;
10676 if (FromValue.getLValueBase()) {
10677 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10678 "in C++20 dynamic allocation are transient so they shouldn't "
10679 "appear in the AST");
10680 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10681 if (const auto *E =
10682 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10683 FromElemTy = E->getType();
10684 const Expr *ImpExpr = importChecked(Err, E);
10685 if (Err)
10686 return std::move(Err);
10687 Base = APValue::LValueBase(ImpExpr,
10688 FromValue.getLValueBase().getCallIndex(),
10689 FromValue.getLValueBase().getVersion());
10690 } else {
10691 FromElemTy =
10692 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10693 const Decl *ImpDecl = importChecked(
10694 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10695 if (Err)
10696 return std::move(Err);
10698 FromValue.getLValueBase().getCallIndex(),
10699 FromValue.getLValueBase().getVersion());
10700 }
10701 } else {
10702 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10703 const Type *ImpTypeInfo = importChecked(
10704 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10705 QualType ImpType =
10706 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10707 if (Err)
10708 return std::move(Err);
10710 ImpType);
10711 }
10712 }
10713 CharUnits Offset = FromValue.getLValueOffset();
10714 unsigned PathLength = FromValue.getLValuePath().size();
10715 Result.MakeLValue();
10716 if (FromValue.hasLValuePath()) {
10717 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10718 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10719 FromValue.isNullPointer());
10721 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10722 if (FromElemTy->isRecordType()) {
10723 const Decl *FromDecl =
10724 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10725 const Decl *ImpDecl = importChecked(Err, FromDecl);
10726 if (Err)
10727 return std::move(Err);
10728 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10729 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10730 else
10731 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10733 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10734 } else {
10735 FromElemTy =
10736 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10737 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10738 FromPath[LoopIdx].getAsArrayIndex());
10739 }
10740 }
10741 } else
10742 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10743 FromValue.isNullPointer());
10744 }
10745 if (Err)
10746 return std::move(Err);
10747 return Result;
10748}
10749
10751 DeclContext *DC,
10752 unsigned IDNS,
10753 NamedDecl **Decls,
10754 unsigned NumDecls) {
10755 if (ODRHandling == ODRHandlingType::Conservative)
10756 // Report error at any name conflict.
10757 return make_error<ASTImportError>(ASTImportError::NameConflict);
10758 else
10759 // Allow to create the new Decl with the same name.
10760 return Name;
10761}
10762
10764 if (LastDiagFromFrom)
10765 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10766 FromContext.getDiagnostics());
10767 LastDiagFromFrom = false;
10768 return ToContext.getDiagnostics().Report(Loc, DiagID);
10769}
10770
10772 if (!LastDiagFromFrom)
10773 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10774 ToContext.getDiagnostics());
10775 LastDiagFromFrom = true;
10776 return FromContext.getDiagnostics().Report(Loc, DiagID);
10777}
10778
10780 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10781 if (!ID->getDefinition())
10782 ID->startDefinition();
10783 }
10784 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10785 if (!PD->getDefinition())
10786 PD->startDefinition();
10787 }
10788 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10789 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10790 TD->startDefinition();
10791 TD->setCompleteDefinition(true);
10792 }
10793 }
10794 else {
10795 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10796 }
10797}
10798
10800 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10801 assert((Inserted || Pos->second == To) &&
10802 "Try to import an already imported Decl");
10803 if (!Inserted)
10804 return Pos->second;
10805 // This mapping should be maintained only in this function. Therefore do not
10806 // check for additional consistency.
10807 ImportedFromDecls[To] = From;
10808 // In the case of TypedefNameDecl we create the Decl first and only then we
10809 // import and set its DeclContext. So, the DC is still not set when we reach
10810 // here from GetImportedOrCreateDecl.
10811 if (To->getDeclContext())
10812 AddToLookupTable(To);
10813 return To;
10814}
10815
10816std::optional<ASTImportError>
10818 auto Pos = ImportDeclErrors.find(FromD);
10819 if (Pos != ImportDeclErrors.end())
10820 return Pos->second;
10821 else
10822 return std::nullopt;
10823}
10824
10826 auto InsertRes = ImportDeclErrors.insert({From, Error});
10827 (void)InsertRes;
10828 // Either we set the error for the first time, or we already had set one and
10829 // now we want to set the same error.
10830 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10831}
10832
10834 bool Complain) {
10835 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10836 ImportedTypes.find(From.getTypePtr());
10837 if (Pos != ImportedTypes.end()) {
10838 if (ExpectedType ToFromOrErr = Import(From)) {
10839 if (ToContext.hasSameType(*ToFromOrErr, To))
10840 return true;
10841 } else {
10842 llvm::consumeError(ToFromOrErr.takeError());
10843 }
10844 }
10845
10847 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10848 getStructuralEquivalenceKind(*this), false, Complain);
10849 return Ctx.IsEquivalent(From, To);
10850}
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:944
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:4381
SourceLocation getQuestionLoc() const
Definition Expr.h:4380
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:4550
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4565
SourceLocation getLabelLoc() const
Definition Expr.h:4567
LabelDecl * getLabel() const
Definition Expr.h:4573
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6021
Represents a loop initializing the elements of an array.
Definition Expr.h:5968
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5983
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5988
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:3723
bool isVolatile() const
Definition Stmt.h:3305
outputs_range outputs()
Definition Stmt.h:3412
SourceLocation getAsmLoc() const
Definition Stmt.h:3299
inputs_range inputs()
Definition Stmt.h:3383
unsigned getNumClobbers() const
Definition Stmt.h:3360
unsigned getNumOutputs() const
Definition Stmt.h:3328
unsigned getNumInputs() const
Definition Stmt.h:3350
bool isSimple() const
Definition Stmt.h:3302
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6880
Expr ** getSubExprs()
Definition Expr.h:6955
SourceLocation getRParenLoc() const
Definition Expr.h:7009
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5156
AtomicOp getOp() const
Definition Expr.h:6943
SourceLocation getBuiltinLoc() const
Definition Expr.h:7008
Attr - This represents one attribute.
Definition Attr.h:46
attr::Kind getKind() const
Definition Attr.h:92
void setPackExpansion(bool PE)
Definition Attr.h:108
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition Attr.h:106
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition Stmt.h:2195
Stmt * getSubStmt()
Definition Stmt.h:2231
SourceLocation getAttrLoc() const
Definition Stmt.h:2226
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2227
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition Stmt.cpp:436
Represents a C++ declaration that introduces decls from somewhere else.
Definition DeclCXX.h:3492
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3456
shadow_range shadows() const
Definition DeclCXX.h:3558
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4453
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4507
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4491
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4495
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4500
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4488
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4038
Expr * getLHS() const
Definition Expr.h:4088
SourceLocation getOperatorLoc() const
Definition Expr.h:4080
Expr * getRHS() const
Definition Expr.h:4090
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:4982
Opcode getOpcode() const
Definition Expr.h:4083
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4258
A binding in a decomposition declaration.
Definition DeclCXX.h:4181
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4214
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4207
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:4219
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4225
BreakStmt - This represents a break.
Definition Stmt.h:3127
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:3165
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:2103
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:2939
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:2943
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:1516
ADLCallKind getADLCallKind() const
Definition Expr.h:3094
Expr * getCallee()
Definition Expr.h:3090
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3242
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3134
arg_range arguments()
Definition Expr.h:3195
SourceLocation getRParenLoc() const
Definition Expr.h:3274
CaseStmt - Represent a case statement.
Definition Stmt.h:1912
Stmt * getSubStmt()
Definition Stmt.h:2025
Expr * getLHS()
Definition Stmt.h:1995
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:1981
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition Stmt.cpp:1301
SourceLocation getCaseLoc() const
Definition Stmt.h:1977
Expr * getRHS()
Definition Stmt.h:2007
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3676
path_iterator path_begin()
Definition Expr.h:3746
CastKind getCastKind() const
Definition Expr.h:3720
path_iterator path_end()
Definition Expr.h:3747
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3796
Expr * getSubExpr()
Definition Expr.h:3726
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:4848
SourceLocation getBuiltinLoc() const
Definition Expr.h:4895
Expr * getLHS() const
Definition Expr.h:4890
bool isConditionDependent() const
Definition Expr.h:4878
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4871
Expr * getRHS() const
Definition Expr.h:4892
SourceLocation getRParenLoc() const
Definition Expr.h:4898
Expr * getCond() const
Definition Expr.h:4888
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:4300
QualType getComputationLHSType() const
Definition Expr.h:4334
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:5004
QualType getComputationResultType() const
Definition Expr.h:4337
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3605
SourceLocation getLParenLoc() const
Definition Expr.h:3640
bool isFileScope() const
Definition Expr.h:3637
const Expr * getInitializer() const
Definition Expr.h:3633
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3643
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1732
unsigned size() const
Definition Stmt.h:1777
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1782
body_range body()
Definition Stmt.h:1795
SourceLocation getLBracLoc() const
Definition Stmt.h:1849
bool hasStoredFPFeatures() const
Definition Stmt.h:1779
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition Stmt.cpp:394
SourceLocation getRBracLoc() const
Definition Stmt.h:1850
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
A reference to a concept and its template args, as it appears in the code.
Definition ASTConcept.h:130
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ASTConcept.h:170
NamedDecl * getFoundDecl() const
Definition ASTConcept.h:197
const DeclarationNameInfo & getConceptNameInfo() const
Definition ASTConcept.h:174
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:203
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
TemplateDecl * getNamedConcept() const
Definition ASTConcept.h:201
SourceLocation getTemplateKWLoc() const
Definition ASTConcept.h:180
Represents the specialization of a concept - evaluates to a prvalue of type bool.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
ConceptReference * getConceptReference() const
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
ConditionalOperator - The ?
Definition Expr.h:4391
Expr * getLHS() const
Definition Expr.h:4425
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4414
Expr * getRHS() const
Definition Expr.h:4426
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:412
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:349
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:3673
ContinueStmt - This represents a continue.
Definition Stmt.h:3111
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4719
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4787
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4823
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:5559
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4820
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4812
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4809
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:487
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:1623
SourceLocation getEndLoc() const
Definition Stmt.h:1646
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1641
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1649
A simple visitor class that helps create declaration visitors.
Definition DeclVisitor.h:68
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:435
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition DeclBase.cpp:285
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition DeclBase.h:1226
bool hasAttrs() const
Definition DeclBase.h:518
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
void addAttr(Attr *A)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:593
@ FOK_None
Not a friend object.
Definition DeclBase.h:1217
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition DeclBase.h:1180
void setAccess(AccessSpecifier AS)
Definition DeclBase.h:502
SourceLocation getLocation() const
Definition DeclBase.h:439
const char * getDeclKindName() const
Definition DeclBase.cpp:169
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
void setImplicit(bool I=true)
Definition DeclBase.h:594
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition DeclBase.h:608
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:575
DeclContext * getDeclContext()
Definition DeclBase.h:448
AccessSpecifier getAccess() const
Definition DeclBase.h:507
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:439
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:431
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:531
AttrVec & getAttrs()
Definition DeclBase.h:524
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:382
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:918
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:386
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:978
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:831
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:814
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2011
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:4245
SourceLocation getDefaultLoc() const
Definition Stmt.h:2077
Stmt * getSubStmt()
Definition Stmt.h:2073
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:5594
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5721
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5675
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5711
SourceLocation getFieldLoc() const
Definition Expr.h:5702
SourceLocation getRBracketLoc() const
Definition Expr.h:5750
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4674
SourceLocation getEllipsisLoc() const
Definition Expr.h:5744
SourceLocation getDotLoc() const
Definition Expr.h:5697
SourceLocation getLBracketLoc() const
Definition Expr.h:5738
Represents a C99 designated initializer expression.
Definition Expr.h:5551
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5833
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5815
MutableArrayRef< Designator > designators()
Definition Expr.h:5784
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5819
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5781
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5806
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5831
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4715
A little helper class used to produce diagnostics.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2824
Stmt * getBody()
Definition Stmt.h:2849
Expr * getCond()
Definition Stmt.h:2842
SourceLocation getWhileLoc() const
Definition Stmt.h:2855
SourceLocation getDoLoc() const
Definition Stmt.h:2853
SourceLocation getRParenLoc() const
Definition Stmt.h:2857
Symbolic representation of a dynamic allocation.
Definition APValue.h:65
Represents an empty-declaration.
Definition Decl.h:5178
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:4010
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4282
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4228
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4220
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4231
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4192
EnumDecl * getMostRecentDecl()
Definition Decl.h:4115
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4237
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5089
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4183
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5149
EnumDecl * getDefinition() const
Definition Decl.h:4122
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4209
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4175
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3928
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3950
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:4725
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:4735
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:4835
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:1075
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:2880
Stmt * getInit()
Definition Stmt.h:2895
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1115
SourceLocation getRParenLoc() const
Definition Stmt.h:2940
Stmt * getBody()
Definition Stmt.h:2924
Expr * getInc()
Definition Stmt.h:2923
SourceLocation getForLoc() const
Definition Stmt.h:2936
Expr * getCond()
Definition Stmt.h:2922
SourceLocation getLParenLoc() const
Definition Stmt.h:2938
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:54
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition DeclFriend.h:58
SourceLocation getFriendLoc() const
Retrieves the location of the 'friend' keyword.
Definition DeclFriend.h:144
SourceLocation getEllipsisLoc() const
Retrieves the location of the '...', if present.
Definition DeclFriend.h:149
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:139
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:125
const Expr * getSubExpr() const
Definition Expr.h:1062
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3140
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:3279
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2476
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4198
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4193
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3298
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3160
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2701
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3551
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:4172
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4323
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:4389
@ 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:4144
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4211
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:4378
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:3555
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:3559
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3563
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:4217
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4417
void setDefaulted(bool D=true)
Definition Decl.h:2386
void setBody(Stmt *B)
Definition Decl.cpp:3291
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:3169
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:4165
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2211
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3199
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:5269
QualType desugar() const
Definition TypeBase.h:5850
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5558
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5723
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5709
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:4821
QualType getReturnType() const
Definition TypeBase.h:4805
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3438
unsigned getNumLabels() const
Definition Stmt.h:3588
labels_range labels()
Definition Stmt.h:3611
SourceLocation getRParenLoc() const
Definition Stmt.h:3460
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3553
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3540
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3566
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3529
const Expr * getAsmStringExpr() const
Definition Stmt.h:3465
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3645
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4923
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4940
Represents a C11 generic selection.
Definition Expr.h:6178
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6453
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6473
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6434
SourceLocation getGenericLoc() const
Definition Expr.h:6531
SourceLocation getRParenLoc() const
Definition Expr.h:6535
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6423
SourceLocation getDefaultLoc() const
Definition Expr.h:6534
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:4604
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6430
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6441
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6478
GotoStmt - This represents a direct goto.
Definition Stmt.h:2961
SourceLocation getLabelLoc() const
Definition Stmt.h:2979
SourceLocation getGotoLoc() const
Definition Stmt.h:2977
LabelDecl * getLabel() const
Definition Stmt.h:2974
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setBuiltinID(unsigned ID)
StringRef getName() const
Return the actual identifier string.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2251
Stmt * getThen()
Definition Stmt.h:2340
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition Stmt.cpp:1039
SourceLocation getIfLoc() const
Definition Stmt.h:2417
IfStatementKind getStatementKind() const
Definition Stmt.h:2452
SourceLocation getElseLoc() const
Definition Stmt.h:2420
Stmt * getInit()
Definition Stmt.h:2401
SourceLocation getLParenLoc() const
Definition Stmt.h:2469
Expr * getCond()
Definition Stmt.h:2328
Stmt * getElse()
Definition Stmt.h:2349
SourceLocation getRParenLoc() const
Definition Stmt.h:2471
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1063
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:3853
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2072
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:6057
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5052
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3467
unsigned getChainingSize() const
Definition Decl.h:3492
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3488
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3000
SourceLocation getGotoLoc() const
Definition Stmt.h:3016
SourceLocation getStarLoc() const
Definition Stmt.h:3018
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h: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:5299
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5411
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5476
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5425
unsigned getNumInits() const
Definition Expr.h:5329
SourceLocation getLBraceLoc() const
Definition Expr.h:5460
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2437
InitListExpr * getSyntacticForm() const
Definition Expr.h:5472
bool hadArrayRangeDesignator() const
Definition Expr.h:5483
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5401
SourceLocation getRBraceLoc() const
Definition Expr.h:5462
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5431
ArrayRef< Expr * > inits()
Definition Expr.h:5349
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5486
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:974
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:2138
LabelDecl * getDecl() const
Definition Stmt.h:2156
Stmt * getSubStmt()
Definition Stmt.h:2160
SourceLocation getIdentLoc() const
Definition Stmt.h:2153
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool capturesVariable() const
Determine whether this capture handles a variable.
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition ExprCXX.cpp:1264
ValueDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
SourceLocation getLocation() const
Retrieve the source location of the capture.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h: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:3304
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3350
Represents a linkage specification.
Definition DeclCXX.h:3011
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3053
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3034
SourceLocation getExternLoc() const
Definition DeclCXX.h:3050
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3051
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3045
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:3364
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3536
SourceLocation getOperatorLoc() const
Definition Expr.h:3546
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3481
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3466
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3447
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3508
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3588
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:1749
Expr * getBase() const
Definition Expr.h:3441
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3497
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3489
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3541
bool isArrow() const
Definition Expr.h:3548
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3451
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:3197
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3258
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3280
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3283
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3286
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3267
Represent a C++ namespace.
Definition Decl.h:592
SourceLocation getRBraceLoc() const
Definition Decl.h:692
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:691
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:675
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:657
void setRBraceLoc(SourceLocation L)
Definition Decl.h:694
Class that aids in the construction of nested-name-specifiers along with source-location information ...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1695
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1709
SourceLocation getSemiLoc() const
Definition Stmt.h:1706
Represents Objective-C's @catch statement.
Definition StmtObjC.h:77
const VarDecl * getCatchParamDecl() const
Definition StmtObjC.h:97
const Stmt * getCatchBody() const
Definition StmtObjC.h:93
SourceLocation getAtCatchLoc() const
Definition StmtObjC.h:105
SourceLocation getRParenLoc() const
Definition StmtObjC.h:107
Represents Objective-C's @finally statement.
Definition StmtObjC.h:127
const Stmt * getFinallyBody() const
Definition StmtObjC.h:139
SourceLocation getAtFinallyLoc() const
Definition StmtObjC.h:148
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
const Expr * getSynchExpr() const
Definition StmtObjC.h:331
const CompoundStmt * getSynchBody() const
Definition StmtObjC.h:323
SourceLocation getAtSynchronizedLoc() const
Definition StmtObjC.h:320
Represents Objective-C's @throw statement.
Definition StmtObjC.h:358
const Expr * getThrowExpr() const
Definition StmtObjC.h:370
SourceLocation getThrowLoc() const LLVM_READONLY
Definition StmtObjC.h:374
Represents Objective-C's @try ... @catch ... @finally statement.
Definition StmtObjC.h:167
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition StmtObjC.h:241
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition StmtObjC.cpp:45
unsigned getNumCatchStmts() const
Retrieve the number of @catch statements in this try-catch-finally block.
Definition StmtObjC.h:220
const ObjCAtCatchStmt * getCatchStmt(unsigned I) const
Retrieve a @catch statement.
Definition StmtObjC.h:223
const Stmt * getTryBody() const
Retrieve the @try body.
Definition StmtObjC.h:214
SourceLocation getAtTryLoc() const
Retrieve the location of the @ in the @try.
Definition StmtObjC.h:210
Represents Objective-C's @autoreleasepool Statement.
Definition StmtObjC.h:394
SourceLocation getAtLoc() const
Definition StmtObjC.h:414
const Stmt * getSubStmt() const
Definition StmtObjC.h:405
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1640
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2329
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:2391
ObjCCategoryImplDecl * getImplementation() const
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2372
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2377
protocol_iterator protocol_end() const
Definition DeclObjC.h:2411
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2414
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2464
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2466
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2421
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2407
void setImplementation(ObjCCategoryImplDecl *ImplD)
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2400
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2460
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2545
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2572
ObjCCategoryDecl * getCategoryDecl() const
SourceLocation getAtStartLoc() const
Definition DeclObjC.h:1096
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
SourceLocation getForLoc() const
Definition StmtObjC.h:52
SourceLocation getRParenLoc() const
Definition StmtObjC.h:54
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2486
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2597
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2744
SourceLocation getSuperClassLoc() const
Definition DeclObjC.h:2737
const ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.h:2735
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2742
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:1485
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition DeclObjC.h:1893
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition DeclObjC.h:1303
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:1392
void setImplementation(ObjCImplementationDecl *ImplD)
known_categories_range known_categories() const
Definition DeclObjC.h:1687
void setSuperClass(TypeSourceInfo *superClass)
Definition DeclObjC.h:1588
protocol_iterator protocol_end() const
Definition DeclObjC.h:1374
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition DeclObjC.cpp:369
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition DeclObjC.h:1523
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition DeclObjC.cpp:340
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:1356
ObjCImplementationDecl * getImplementation() const
protocol_iterator protocol_begin() const
Definition DeclObjC.h:1363
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:1385
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition DeclObjC.cpp:613
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition DeclObjC.h:1915
ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.cpp:349
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition DeclObjC.h:1542
TypeSourceInfo * getSuperClassTInfo() const
Definition DeclObjC.h:1573
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:1652
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:1687
@ 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:6123
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4854
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6110
SourceLocation getLParenLoc() const
Definition Expr.h:6125
SourceLocation getRParenLoc() const
Definition Expr.h:6126
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:3022
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:3047
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:3010
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3052
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3058
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:632
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:6756
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6798
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5076
ArrayRef< Expr * > semantics()
Definition Expr.h:6828
unsigned getNumSemanticExprs() const
Definition Expr.h:6813
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6793
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:8292
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8324
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:4324
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5241
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4380
field_range fields() const
Definition Decl.h:4527
RecordDecl * getMostRecentDecl()
Definition Decl.h:4350
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5286
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4508
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4376
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:5329
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:3152
SourceLocation getReturnLoc() const
Definition Stmt.h:3201
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3188
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition Stmt.cpp:1285
Expr * getRetValue()
Definition Stmt.h:3179
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4643
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4679
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4676
SourceLocation getRParenLoc() const
Definition Expr.h:4663
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4666
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:5017
SourceLocation getBeginLoc() const
Definition Expr.h:5062
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5058
SourceLocation getEndLoc() const
Definition Expr.h:5063
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5037
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:4132
bool isFailed() const
Definition DeclCXX.h:4161
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4163
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4595
CompoundStmt * getSubStmt()
Definition Expr.h:4612
unsigned getTemplateDepth() const
Definition Expr.h:4624
SourceLocation getRParenLoc() const
Definition Expr.h:4621
SourceLocation getLParenLoc() const
Definition Expr.h:4619
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:86
child_iterator child_begin()
Definition Stmt.h:1583
StmtClass getStmtClass() const
Definition Stmt.h:1485
child_iterator child_end()
Definition Stmt.h:1584
const char * getStmtClassName() const
Definition Stmt.cpp: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:1187
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:1887
SourceLocation getColonLoc() const
Definition Stmt.h:1891
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1885
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2501
SourceLocation getSwitchLoc() const
Definition Stmt.h:2636
SourceLocation getLParenLoc() const
Definition Stmt.h:2638
SourceLocation getRParenLoc() const
Definition Stmt.h:2640
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition Stmt.cpp:1162
Expr * getCond()
Definition Stmt.h:2564
Stmt * getBody()
Definition Stmt.h:2576
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1181
Stmt * getInit()
Definition Stmt.h:2581
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2632
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
SourceRange getBraceRange() const
Definition Decl.h:3791
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3835
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4929
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3810
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3815
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:3968
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3951
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4906
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4901
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4943
TagKind getTagKind() const
Definition Decl.h:3914
void setBraceRange(SourceRange R)
Definition Decl.h:3792
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3818
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:8263
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:8274
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:8628
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:753
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2783
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9064
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2436
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:9111
bool isRecordType() const
Definition TypeBase.h:8656
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:5018
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:4033
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4063
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4067
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4060
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4084
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3936
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3967
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3977
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3984
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:3994
Represents a C++ using-declaration.
Definition DeclCXX.h:3587
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3636
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3621
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3628
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3614
Represents C++ using-directive.
Definition DeclCXX.h:3092
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3163
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3297
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3159
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3167
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3170
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3137
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3788
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3812
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3824
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3808
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3869
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3898
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3902
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3395
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3459
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3427
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4957
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:4981
SourceLocation getBuiltinLoc() const
Definition Expr.h:4984
SourceLocation getRParenLoc() const
Definition Expr.h:4987
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4978
const Expr * getSubExpr() const
Definition Expr.h:4973
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:2821
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:2946
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:2271
bool isInlineSpecified() const
Definition Decl.h:1554
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2377
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2582
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2568
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:2783
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:2488
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2826
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:2909
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:2689
Expr * getCond()
Definition Stmt.h:2741
SourceLocation getWhileLoc() const
Definition Stmt.h:2794
SourceLocation getRParenLoc() const
Definition Stmt.h:2799
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1242
SourceLocation getLParenLoc() const
Definition Stmt.h:2797
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition Stmt.cpp:1224
Stmt * getBody()
Definition Stmt.h:2753
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
ConceptSpecializationExpr * getReturnTypeRequirementSubstitutedConstraintExpr() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SatisfactionStatus getSatisfactionStatus() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
A requires-expression requirement which queries the existence of a type name or type template special...
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
Definition SPIR.cpp:35
Definition SPIR.cpp:47
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
Definition Address.h:330
llvm::Expected< SourceLocation > ExpectedSLoc
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
llvm::Expected< const Type * > ExpectedTypePtr
CanThrowResult
Possible results from evaluation of a noexcept expression.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:149
std::pair< FileID, unsigned > FileIDAndOffset
llvm::Expected< DeclarationName > ExpectedName
llvm::Expected< Decl * > ExpectedDecl
@ Property
The type of a property.
Definition TypeBase.h:911
@ Result
The result type of a method or function.
Definition TypeBase.h:905
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:584
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:5338
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5342
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5328
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5331
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5334
Extra information about a function prototype.
Definition TypeBase.h:5354
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