clang 23.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 if (auto *VD = dyn_cast<VarDecl>(D))
125 if (auto *TD = dyn_cast<TagDecl>(D))
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 // Use this to import pointers of specific type.
189 template <typename ImportT>
190 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
191 auto ToOrErr = Importer.Import(From);
192 if (ToOrErr)
193 To = cast_or_null<ImportT>(*ToOrErr);
194 return ToOrErr.takeError();
195 }
196
197 // Call the import function of ASTImporter for a baseclass of type `T` and
198 // cast the return value to `T`.
199 template <typename T>
200 auto import(T *From)
201 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203 auto ToOrErr = Importer.Import(From);
204 if (!ToOrErr)
205 return ToOrErr.takeError();
206 return cast_or_null<T>(*ToOrErr);
207 }
208
209 template <typename T>
210 auto import(const T *From) {
211 return import(const_cast<T *>(From));
212 }
213
214 // Call the import function of ASTImporter for type `T`.
215 template <typename T>
216 Expected<T> import(const T &From) {
217 return Importer.Import(From);
218 }
219
220 // Import an std::optional<T> by importing the contained T, if any.
221 template <typename T>
222 Expected<std::optional<T>> import(std::optional<T> From) {
223 if (!From)
224 return std::nullopt;
225 return import(*From);
226 }
227
228 ExplicitSpecifier importExplicitSpecifier(Error &Err,
229 ExplicitSpecifier ESpec);
230
231 // Wrapper for an overload set.
232 template <typename ToDeclT> struct CallOverloadedCreateFun {
233 template <typename... Args> decltype(auto) operator()(Args &&... args) {
234 return ToDeclT::Create(std::forward<Args>(args)...);
235 }
236 };
237
238 // Always use these functions to create a Decl during import. There are
239 // certain tasks which must be done after the Decl was created, e.g. we
240 // must immediately register that as an imported Decl. The parameter `ToD`
241 // will be set to the newly created Decl or if had been imported before
242 // then to the already imported Decl. Returns a bool value set to true if
243 // the `FromD` had been imported before.
244 template <typename ToDeclT, typename FromDeclT, typename... Args>
245 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
246 Args &&...args) {
247 // There may be several overloads of ToDeclT::Create. We must make sure
248 // to call the one which would be chosen by the arguments, thus we use a
249 // wrapper for the overload set.
250 CallOverloadedCreateFun<ToDeclT> OC;
251 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
252 std::forward<Args>(args)...);
253 }
254 // Use this overload if a special Type is needed to be created. E.g if we
255 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
256 // then:
257 // TypedefNameDecl *ToTypedef;
258 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
259 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
260 typename... Args>
261 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
262 Args &&...args) {
263 CallOverloadedCreateFun<NewDeclT> OC;
264 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
265 std::forward<Args>(args)...);
266 }
267 // Use this version if a special create function must be
268 // used, e.g. CXXRecordDecl::CreateLambda .
269 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
270 typename... Args>
271 [[nodiscard]] bool
272 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
273 FromDeclT *FromD, Args &&...args) {
274 if (Importer.getImportDeclErrorIfAny(FromD)) {
275 ToD = nullptr;
276 return true; // Already imported but with error.
277 }
278 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
279 if (ToD)
280 return true; // Already imported.
281 ToD = CreateFun(std::forward<Args>(args)...);
282 // Keep track of imported Decls.
283 Importer.RegisterImportedDecl(FromD, ToD);
284 Importer.SharedState->markAsNewDecl(ToD);
285 InitializeImportedDecl(FromD, ToD);
286 return false; // A new Decl is created.
287 }
288
289 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
290 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
291 if (FromD->isUsed())
292 ToD->setIsUsed();
293 if (FromD->isImplicit())
294 ToD->setImplicit();
295 }
296
297 // Check if we have found an existing definition. Returns with that
298 // definition if yes, otherwise returns null.
299 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
300 const FunctionDecl *Definition = nullptr;
302 FoundFunction->hasBody(Definition))
303 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
304 return nullptr;
305 }
306
307 void addDeclToContexts(Decl *FromD, Decl *ToD) {
308 if (Importer.isMinimalImport()) {
309 // In minimal import case the decl must be added even if it is not
310 // contained in original context, for LLDB compatibility.
311 // FIXME: Check if a better solution is possible.
312 if (!FromD->getDescribedTemplate() &&
313 FromD->getFriendObjectKind() == Decl::FOK_None)
315 return;
316 }
317
318 DeclContext *FromDC = FromD->getDeclContext();
319 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
320 DeclContext *ToDC = ToD->getDeclContext();
321 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
322
323 bool Visible = false;
324 if (FromDC->containsDeclAndLoad(FromD)) {
325 ToDC->addDeclInternal(ToD);
326 Visible = true;
327 }
328 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
329 ToLexicalDC->addDeclInternal(ToD);
330 Visible = true;
331 }
332
333 // If the Decl was added to any context, it was made already visible.
334 // Otherwise it is still possible that it should be visible.
335 if (!Visible) {
336 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
337 auto *ToNamed = cast<NamedDecl>(ToD);
338 DeclContextLookupResult FromLookup =
339 FromDC->lookup(FromNamed->getDeclName());
340 if (llvm::is_contained(FromLookup, FromNamed))
341 ToDC->makeDeclVisibleInContext(ToNamed);
342 }
343 }
344 }
345
346 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
347 DeclContext *OldDC) {
348 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
349 if (!LT)
350 return;
351
352 for (NamedDecl *TP : Params)
353 LT->update(TP, OldDC);
354 }
355
356 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
357 updateLookupTableForTemplateParameters(
358 Params, Importer.getToContext().getTranslationUnitDecl());
359 }
360
361 template <typename TemplateParmDeclT>
362 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
363 TemplateParmDeclT *ToD) {
364 if (D->hasDefaultArgument()) {
365 if (D->defaultArgumentWasInherited()) {
366 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
367 import(D->getDefaultArgStorage().getInheritedFrom());
368 if (!ToInheritedFromOrErr)
369 return ToInheritedFromOrErr.takeError();
370 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
371 if (!ToInheritedFrom->hasDefaultArgument()) {
372 // Resolve possible circular dependency between default value of the
373 // template argument and the template declaration.
374 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
375 import(D->getDefaultArgStorage()
376 .getInheritedFrom()
377 ->getDefaultArgument());
378 if (!ToInheritedDefaultArgOrErr)
379 return ToInheritedDefaultArgOrErr.takeError();
380 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
381 *ToInheritedDefaultArgOrErr);
382 }
383 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
384 ToInheritedFrom);
385 } else {
386 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
387 import(D->getDefaultArgument());
388 if (!ToDefaultArgOrErr)
389 return ToDefaultArgOrErr.takeError();
390 // Default argument could have been set in the
391 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
392 if (!ToD->hasDefaultArgument())
393 ToD->setDefaultArgument(Importer.getToContext(),
394 *ToDefaultArgOrErr);
395 }
396 }
397 return Error::success();
398 }
399
400 public:
401 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
402
406
407 // Importing types
408 ExpectedType VisitType(const Type *T);
409#define TYPE(Class, Base) \
410 ExpectedType Visit##Class##Type(const Class##Type *T);
411#include "clang/AST/TypeNodes.inc"
412
413 // Importing declarations
415 SourceLocation &Loc);
417 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
418 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
419 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
422 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
424 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
426
427 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
429 Expected<APValue> ImportAPValue(const APValue &FromValue);
430
432
433 /// What we should import from the definition.
435 /// Import the default subset of the definition, which might be
436 /// nothing (if minimal import is set) or might be everything (if minimal
437 /// import is not set).
439 /// Import everything.
441 /// Import only the bare bones needed to establish a valid
442 /// DeclContext.
444 };
445
447 return IDK == IDK_Everything ||
448 (IDK == IDK_Default && !Importer.isMinimalImport());
449 }
450
453 RecordDecl *From, RecordDecl *To,
456 EnumDecl *From, EnumDecl *To,
468
469 template <typename InContainerTy>
471 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
472
473 template<typename InContainerTy>
475 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
476 const InContainerTy &Container, TemplateArgumentListInfo &Result);
477
480 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
483 FunctionDecl *FromFD);
484
485 template <typename DeclTy>
486 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
487
489
491
493 ParmVarDecl *ToParam);
494
497
498 // Use for allocating string for newly imported object.
499 StringRef ImportASTStringRef(StringRef FromStr);
508
509 template <typename T>
511
512 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
513 bool IgnoreTemplateParmDepth = false);
560
563
582
583 // Importing statements
603 // FIXME: MSAsmStmt
604 // FIXME: SEHExceptStmt
605 // FIXME: SEHFinallyStmt
606 // FIXME: SEHTryStmt
607 // FIXME: SEHLeaveStmt
608 // FIXME: CapturedStmt
612 // FIXME: MSDependentExistsStmt
620
621 // Importing expressions
704
705 // Helper for chaining together multiple imports. If an error is detected,
706 // subsequent imports will return default constructed nodes, so that failure
707 // can be detected with a single conditional branch after a sequence of
708 // imports.
709 template <typename T> T importChecked(Error &Err, const T &From) {
710 // Don't attempt to import nodes if we hit an error earlier.
711 if (Err)
712 return T{};
713 Expected<T> MaybeVal = import(From);
714 if (!MaybeVal) {
715 Err = MaybeVal.takeError();
716 return T{};
717 }
718 return *MaybeVal;
719 }
720
721 template<typename IIter, typename OIter>
722 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
723 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
724 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
725 Expected<ItemT> ToOrErr = import(*Ibegin);
726 if (!ToOrErr)
727 return ToOrErr.takeError();
728 *Obegin = *ToOrErr;
729 }
730 return Error::success();
731 }
732
733 // Import every item from a container structure into an output container.
734 // If error occurs, stops at first error and returns the error.
735 // The output container should have space for all needed elements (it is not
736 // expanded, new items are put into from the beginning).
737 template<typename InContainerTy, typename OutContainerTy>
739 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
740 return ImportArrayChecked(
741 InContainer.begin(), InContainer.end(), OutContainer.begin());
742 }
743
744 template<typename InContainerTy, typename OIter>
745 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
746 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
747 }
748
750 CXXMethodDecl *FromMethod);
751
753 FunctionDecl *FromFD);
754
755 // Returns true if the given function has a placeholder return type and
756 // that type is declared inside the body of the function.
757 // E.g. auto f() { struct X{}; return X(); }
759 };
760
761template <typename InContainerTy>
763 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
764 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
765 auto ToLAngleLocOrErr = import(FromLAngleLoc);
766 if (!ToLAngleLocOrErr)
767 return ToLAngleLocOrErr.takeError();
768 auto ToRAngleLocOrErr = import(FromRAngleLoc);
769 if (!ToRAngleLocOrErr)
770 return ToRAngleLocOrErr.takeError();
771
772 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
773 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
774 return Err;
775 Result = std::move(ToTAInfo);
776 return Error::success();
777}
778
779template <>
785
786template <>
794
797 FunctionDecl *FromFD) {
798 assert(FromFD->getTemplatedKind() ==
800
802
803 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
804 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
805 return std::move(Err);
806
807 // Import template arguments.
808 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
809 std::get<1>(Result)))
810 return std::move(Err);
811
812 return Result;
813}
814
815template <>
817ASTNodeImporter::import(TemplateParameterList *From) {
819 if (Error Err = ImportContainerChecked(*From, To))
820 return std::move(Err);
821
822 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
823 if (!ToRequiresClause)
824 return ToRequiresClause.takeError();
825
826 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
827 if (!ToTemplateLocOrErr)
828 return ToTemplateLocOrErr.takeError();
829 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
830 if (!ToLAngleLocOrErr)
831 return ToLAngleLocOrErr.takeError();
832 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
833 if (!ToRAngleLocOrErr)
834 return ToRAngleLocOrErr.takeError();
835
837 Importer.getToContext(),
838 *ToTemplateLocOrErr,
839 *ToLAngleLocOrErr,
840 To,
841 *ToRAngleLocOrErr,
842 *ToRequiresClause);
843}
844
845template <>
847ASTNodeImporter::import(const TemplateArgument &From) {
848 switch (From.getKind()) {
850 return TemplateArgument();
851
853 ExpectedType ToTypeOrErr = import(From.getAsType());
854 if (!ToTypeOrErr)
855 return ToTypeOrErr.takeError();
856 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
857 From.getIsDefaulted());
858 }
859
861 ExpectedType ToTypeOrErr = import(From.getIntegralType());
862 if (!ToTypeOrErr)
863 return ToTypeOrErr.takeError();
864 return TemplateArgument(From, *ToTypeOrErr);
865 }
866
868 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
869 if (!ToOrErr)
870 return ToOrErr.takeError();
871 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
872 if (!ToTypeOrErr)
873 return ToTypeOrErr.takeError();
874 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
875 *ToTypeOrErr, From.getIsDefaulted());
876 }
877
879 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
880 if (!ToTypeOrErr)
881 return ToTypeOrErr.takeError();
882 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
883 From.getIsDefaulted());
884 }
885
887 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
888 if (!ToTypeOrErr)
889 return ToTypeOrErr.takeError();
890 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
891 if (!ToValueOrErr)
892 return ToValueOrErr.takeError();
893 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
894 *ToValueOrErr);
895 }
896
898 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
899 if (!ToTemplateOrErr)
900 return ToTemplateOrErr.takeError();
901
902 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
903 }
904
906 Expected<TemplateName> ToTemplateOrErr =
907 import(From.getAsTemplateOrTemplatePattern());
908 if (!ToTemplateOrErr)
909 return ToTemplateOrErr.takeError();
910
911 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
912 From.getIsDefaulted());
913 }
914
916 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
917 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
918 From.getIsDefaulted());
919 else
920 return ToExpr.takeError();
921
924 ToPack.reserve(From.pack_size());
925 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
926 return std::move(Err);
927
928 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
929 }
930 }
931
932 llvm_unreachable("Invalid template argument kind");
933}
934
935template <>
937ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
938 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
939 if (!ArgOrErr)
940 return ArgOrErr.takeError();
941 TemplateArgument Arg = *ArgOrErr;
942
943 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
944
947 ExpectedExpr E = import(FromInfo.getAsExpr());
948 if (!E)
949 return E.takeError();
950 ToInfo = TemplateArgumentLocInfo(*E);
951 } else if (Arg.getKind() == TemplateArgument::Type) {
952 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
953 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
954 else
955 return TSIOrErr.takeError();
956 } else {
957 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
958 if (!ToTemplateKWLocOrErr)
959 return ToTemplateKWLocOrErr.takeError();
960 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
961 if (!ToTemplateQualifierLocOrErr)
962 return ToTemplateQualifierLocOrErr.takeError();
963 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
964 if (!ToTemplateNameLocOrErr)
965 return ToTemplateNameLocOrErr.takeError();
966 auto ToTemplateEllipsisLocOrErr =
967 import(FromInfo.getTemplateEllipsisLoc());
968 if (!ToTemplateEllipsisLocOrErr)
969 return ToTemplateEllipsisLocOrErr.takeError();
971 Importer.getToContext(), *ToTemplateKWLocOrErr,
972 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
973 *ToTemplateEllipsisLocOrErr);
974 }
975
976 return TemplateArgumentLoc(Arg, ToInfo);
977}
978
979template <>
980Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
981 if (DG.isNull())
982 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
983 size_t NumDecls = DG.end() - DG.begin();
985 ToDecls.reserve(NumDecls);
986 for (Decl *FromD : DG) {
987 if (auto ToDOrErr = import(FromD))
988 ToDecls.push_back(*ToDOrErr);
989 else
990 return ToDOrErr.takeError();
991 }
992 return DeclGroupRef::Create(Importer.getToContext(),
993 ToDecls.begin(),
994 NumDecls);
995}
996
997template <>
999ASTNodeImporter::import(const Designator &D) {
1000 if (D.isFieldDesignator()) {
1001 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
1002
1003 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
1004 if (!ToDotLocOrErr)
1005 return ToDotLocOrErr.takeError();
1006
1007 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1008 if (!ToFieldLocOrErr)
1009 return ToFieldLocOrErr.takeError();
1010
1012 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1013 }
1014
1015 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1016 if (!ToLBracketLocOrErr)
1017 return ToLBracketLocOrErr.takeError();
1018
1019 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1020 if (!ToRBracketLocOrErr)
1021 return ToRBracketLocOrErr.takeError();
1022
1023 if (D.isArrayDesignator())
1025 *ToLBracketLocOrErr,
1026 *ToRBracketLocOrErr);
1027
1028 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1029 if (!ToEllipsisLocOrErr)
1030 return ToEllipsisLocOrErr.takeError();
1031
1032 assert(D.isArrayRangeDesignator());
1034 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1035 *ToRBracketLocOrErr);
1036}
1037
1038template <>
1039Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1040 Error Err = Error::success();
1041 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1042 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1043 auto ToConceptNameLoc =
1044 importChecked(Err, From->getConceptNameInfo().getLoc());
1045 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1046 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1047 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1048 if (Err)
1049 return std::move(Err);
1050 TemplateArgumentListInfo ToTAInfo;
1051 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1052 if (ASTTemplateArgs)
1053 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1054 return std::move(Err);
1055 auto *ConceptRef = ConceptReference::Create(
1056 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1057 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1058 ToNamedConcept,
1059 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1060 Importer.getToContext(), ToTAInfo)
1061 : nullptr);
1062 return ConceptRef;
1063}
1064
1065StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1066 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1067 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1068 return StringRef(ToStore, FromStr.size());
1069}
1070
1072 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1073 ToSat.IsSatisfied = FromSat.IsSatisfied;
1074 ToSat.ContainsErrors = FromSat.ContainsErrors;
1075 if (!ToSat.IsSatisfied) {
1076 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1077 if (const Expr *E = Record->dyn_cast<const Expr *>()) {
1078 ExpectedExpr ToSecondExpr = import(E);
1079 if (!ToSecondExpr)
1080 return ToSecondExpr.takeError();
1081 ToSat.Details.emplace_back(ToSecondExpr.get());
1082 } else if (auto CR = Record->dyn_cast<const ConceptReference *>()) {
1083 Expected<ConceptReference *> ToCROrErr = import(CR);
1084 if (!ToCROrErr)
1085 return ToCROrErr.takeError();
1086 ToSat.Details.emplace_back(ToCROrErr.get());
1087 } else {
1088 auto Pair =
1089 Record->dyn_cast<const ConstraintSubstitutionDiagnostic *>();
1090
1091 ExpectedSLoc ToPairFirst = import(Pair->first);
1092 if (!ToPairFirst)
1093 return ToPairFirst.takeError();
1094 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1095 ToSat.Details.emplace_back(new (Importer.getToContext())
1097 ToPairFirst.get(), ToPairSecond});
1098 }
1099 }
1100 }
1101 return Error::success();
1102}
1103
1104template <>
1106ASTNodeImporter::import(
1108 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1109 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1110 if (!ToLoc)
1111 return ToLoc.takeError();
1112 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1113 return new (Importer.getToContext())
1115 ToDiagMessage};
1116}
1117
1120 using namespace concepts;
1121
1122 if (From->isSubstitutionFailure()) {
1123 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1124 if (!DiagOrErr)
1125 return DiagOrErr.takeError();
1126 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1127 } else {
1128 Expected<TypeSourceInfo *> ToType = import(From->getType());
1129 if (!ToType)
1130 return ToType.takeError();
1131 return new (Importer.getToContext()) TypeRequirement(*ToType);
1132 }
1133}
1134
1137 using namespace concepts;
1138
1139 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1140 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1141
1142 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1143 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1144
1145 if (IsRKSimple) {
1146 Req.emplace();
1147 } else {
1148 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1150
1151 if (FromTypeRequirement.isTypeConstraint()) {
1152 const bool IsDependent = FromTypeRequirement.isDependent();
1153 auto ParamsOrErr =
1154 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1155 if (!ParamsOrErr)
1156 return ParamsOrErr.takeError();
1157 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1158 auto SubstConstraintExprOrErr =
1160 if (!SubstConstraintExprOrErr)
1161 return SubstConstraintExprOrErr.takeError();
1162 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1163 }
1164 Req.emplace(ParamsOrErr.get(), IsDependent);
1165 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1166 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1167 if (!DiagOrErr)
1168 return DiagOrErr.takeError();
1169 Req.emplace(DiagOrErr.get());
1170 } else {
1171 Req.emplace();
1172 }
1173 }
1174
1175 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1176 if (!NoexceptLocOrErr)
1177 return NoexceptLocOrErr.takeError();
1178
1179 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1180 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1181 if (!DiagOrErr)
1182 return DiagOrErr.takeError();
1183 return new (Importer.getToContext()) ExprRequirement(
1184 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1185 } else {
1186 Expected<Expr *> ExprOrErr = import(From->getExpr());
1187 if (!ExprOrErr)
1188 return ExprOrErr.takeError();
1189 return new (Importer.getToContext()) concepts::ExprRequirement(
1190 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1191 SubstitutedConstraintExpr);
1192 }
1193}
1194
1197 using namespace concepts;
1198
1199 const ASTConstraintSatisfaction &FromSatisfaction =
1201 if (From->hasInvalidConstraint()) {
1202 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1203 ASTConstraintSatisfaction *ToSatisfaction =
1204 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1205 FromSatisfaction);
1206 return new (Importer.getToContext())
1207 NestedRequirement(ToEntity, ToSatisfaction);
1208 } else {
1209 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1210 if (!ToExpr)
1211 return ToExpr.takeError();
1212 if (ToExpr.get()->isInstantiationDependent()) {
1213 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1214 } else {
1215 ConstraintSatisfaction Satisfaction;
1216 if (Error Err =
1217 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1218 return std::move(Err);
1219 return new (Importer.getToContext()) NestedRequirement(
1220 Importer.getToContext(), ToExpr.get(), Satisfaction);
1221 }
1222 }
1223}
1224
1225template <>
1227ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1228 switch (FromRequire->getKind()) {
1237 }
1238 llvm_unreachable("Unhandled requirement kind");
1239}
1240
1241template <>
1242Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1243 ValueDecl *Var = nullptr;
1244 if (From.capturesVariable()) {
1245 if (auto VarOrErr = import(From.getCapturedVar()))
1246 Var = *VarOrErr;
1247 else
1248 return VarOrErr.takeError();
1249 }
1250
1251 auto LocationOrErr = import(From.getLocation());
1252 if (!LocationOrErr)
1253 return LocationOrErr.takeError();
1254
1255 SourceLocation EllipsisLoc;
1256 if (From.isPackExpansion())
1257 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1258 return std::move(Err);
1259
1260 return LambdaCapture(
1261 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1262 EllipsisLoc);
1263}
1264
1265template <typename T>
1267 if (Found->getLinkageInternal() != From->getLinkageInternal())
1268 return false;
1269
1270 if (From->hasExternalFormalLinkage())
1271 return Found->hasExternalFormalLinkage();
1272 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1273 return false;
1274 if (From->isInAnonymousNamespace())
1275 return Found->isInAnonymousNamespace();
1276 else
1277 return !Found->isInAnonymousNamespace() &&
1278 !Found->hasExternalFormalLinkage();
1279}
1280
1281template <>
1283 TypedefNameDecl *From) {
1284 if (Found->getLinkageInternal() != From->getLinkageInternal())
1285 return false;
1286
1287 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1288 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1289 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1290}
1291
1292} // namespace clang
1293
1294//----------------------------------------------------------------------------
1295// Import Types
1296//----------------------------------------------------------------------------
1297
1298using namespace clang;
1299
1301 const FunctionDecl *D) {
1302 const FunctionDecl *LambdaD = nullptr;
1303 if (!isCycle(D) && D) {
1304 FunctionDeclsWithImportInProgress.insert(D);
1305 LambdaD = D;
1306 }
1307 return llvm::scope_exit([this, LambdaD]() {
1308 if (LambdaD) {
1309 FunctionDeclsWithImportInProgress.erase(LambdaD);
1310 }
1311 });
1312}
1313
1315 const FunctionDecl *D) const {
1316 return FunctionDeclsWithImportInProgress.find(D) !=
1317 FunctionDeclsWithImportInProgress.end();
1318}
1319
1321 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1322 << T->getTypeClassName();
1323 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1324}
1325
1326ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1327 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1328 if (!UnderlyingTypeOrErr)
1329 return UnderlyingTypeOrErr.takeError();
1330
1331 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1332}
1333
1334ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1335 switch (T->getKind()) {
1336#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1337 case BuiltinType::Id: \
1338 return Importer.getToContext().SingletonId;
1339#include "clang/Basic/OpenCLImageTypes.def"
1340#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1341 case BuiltinType::Id: \
1342 return Importer.getToContext().Id##Ty;
1343#include "clang/Basic/OpenCLExtensionTypes.def"
1344#define SVE_TYPE(Name, Id, SingletonId) \
1345 case BuiltinType::Id: \
1346 return Importer.getToContext().SingletonId;
1347#include "clang/Basic/AArch64ACLETypes.def"
1348#define PPC_VECTOR_TYPE(Name, Id, Size) \
1349 case BuiltinType::Id: \
1350 return Importer.getToContext().Id##Ty;
1351#include "clang/Basic/PPCTypes.def"
1352#define RVV_TYPE(Name, Id, SingletonId) \
1353 case BuiltinType::Id: \
1354 return Importer.getToContext().SingletonId;
1355#include "clang/Basic/RISCVVTypes.def"
1356#define WASM_TYPE(Name, Id, SingletonId) \
1357 case BuiltinType::Id: \
1358 return Importer.getToContext().SingletonId;
1359#include "clang/Basic/WebAssemblyReferenceTypes.def"
1360#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1361 case BuiltinType::Id: \
1362 return Importer.getToContext().SingletonId;
1363#include "clang/Basic/AMDGPUTypes.def"
1364#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1365 case BuiltinType::Id: \
1366 return Importer.getToContext().SingletonId;
1367#include "clang/Basic/HLSLIntangibleTypes.def"
1368#define SHARED_SINGLETON_TYPE(Expansion)
1369#define BUILTIN_TYPE(Id, SingletonId) \
1370 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1371#include "clang/AST/BuiltinTypes.def"
1372
1373 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1374 // context supports C++.
1375
1376 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1377 // context supports ObjC.
1378
1379 case BuiltinType::Char_U:
1380 // The context we're importing from has an unsigned 'char'. If we're
1381 // importing into a context with a signed 'char', translate to
1382 // 'unsigned char' instead.
1383 if (Importer.getToContext().getLangOpts().CharIsSigned)
1384 return Importer.getToContext().UnsignedCharTy;
1385
1386 return Importer.getToContext().CharTy;
1387
1388 case BuiltinType::Char_S:
1389 // The context we're importing from has an unsigned 'char'. If we're
1390 // importing into a context with a signed 'char', translate to
1391 // 'unsigned char' instead.
1392 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1393 return Importer.getToContext().SignedCharTy;
1394
1395 return Importer.getToContext().CharTy;
1396
1397 case BuiltinType::WChar_S:
1398 case BuiltinType::WChar_U:
1399 // FIXME: If not in C++, shall we translate to the C equivalent of
1400 // wchar_t?
1401 return Importer.getToContext().WCharTy;
1402 }
1403
1404 llvm_unreachable("Invalid BuiltinType Kind!");
1405}
1406
1407ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1408 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1409 if (!ToOriginalTypeOrErr)
1410 return ToOriginalTypeOrErr.takeError();
1411
1412 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1413}
1414
1415ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1416 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1417 if (!ToElementTypeOrErr)
1418 return ToElementTypeOrErr.takeError();
1419
1420 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1421}
1422
1423ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1424 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1425 if (!ToPointeeTypeOrErr)
1426 return ToPointeeTypeOrErr.takeError();
1427
1428 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1429}
1430
1431ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1432 // FIXME: Check for blocks support in "to" context.
1433 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1434 if (!ToPointeeTypeOrErr)
1435 return ToPointeeTypeOrErr.takeError();
1436
1437 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1438}
1439
1441ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1442 // FIXME: Check for C++ support in "to" context.
1443 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1444 if (!ToPointeeTypeOrErr)
1445 return ToPointeeTypeOrErr.takeError();
1446
1447 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1448}
1449
1451ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1452 // FIXME: Check for C++0x support in "to" context.
1453 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1454 if (!ToPointeeTypeOrErr)
1455 return ToPointeeTypeOrErr.takeError();
1456
1457 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1458}
1459
1461ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1462 // FIXME: Check for C++ support in "to" context.
1463 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1464 if (!ToPointeeTypeOrErr)
1465 return ToPointeeTypeOrErr.takeError();
1466
1467 auto QualifierOrErr = import(T->getQualifier());
1468 if (!QualifierOrErr)
1469 return QualifierOrErr.takeError();
1470
1471 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1472 if (!ClsOrErr)
1473 return ClsOrErr.takeError();
1474
1475 return Importer.getToContext().getMemberPointerType(
1476 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1477}
1478
1480ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1481 Error Err = Error::success();
1482 auto ToElementType = importChecked(Err, T->getElementType());
1483 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1484 if (Err)
1485 return std::move(Err);
1486
1487 return Importer.getToContext().getConstantArrayType(
1488 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1490}
1491
1493ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1494 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1495 if (!ToArrayTypeOrErr)
1496 return ToArrayTypeOrErr.takeError();
1497
1498 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1499}
1500
1502ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1503 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1504 if (!ToElementTypeOrErr)
1505 return ToElementTypeOrErr.takeError();
1506
1507 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1508 T->getSizeModifier(),
1510}
1511
1513ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1514 Error Err = Error::success();
1515 QualType ToElementType = importChecked(Err, T->getElementType());
1516 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1517 if (Err)
1518 return std::move(Err);
1519 return Importer.getToContext().getVariableArrayType(
1520 ToElementType, ToSizeExpr, T->getSizeModifier(),
1522}
1523
1524ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1525 const DependentSizedArrayType *T) {
1526 Error Err = Error::success();
1527 QualType ToElementType = importChecked(Err, T->getElementType());
1528 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1529 if (Err)
1530 return std::move(Err);
1531 // SizeExpr may be null if size is not specified directly.
1532 // For example, 'int a[]'.
1533
1534 return Importer.getToContext().getDependentSizedArrayType(
1535 ToElementType, ToSizeExpr, T->getSizeModifier(),
1537}
1538
1539ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1540 const DependentSizedExtVectorType *T) {
1541 Error Err = Error::success();
1542 QualType ToElementType = importChecked(Err, T->getElementType());
1543 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1544 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1545 if (Err)
1546 return std::move(Err);
1547 return Importer.getToContext().getDependentSizedExtVectorType(
1548 ToElementType, ToSizeExpr, ToAttrLoc);
1549}
1550
1551ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1552 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1553 if (!ToElementTypeOrErr)
1554 return ToElementTypeOrErr.takeError();
1555
1556 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1557 T->getNumElements(),
1558 T->getVectorKind());
1559}
1560
1561ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1562 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1563 if (!ToElementTypeOrErr)
1564 return ToElementTypeOrErr.takeError();
1565
1566 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1567 T->getNumElements());
1568}
1569
1571ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1572 // FIXME: What happens if we're importing a function without a prototype
1573 // into C++? Should we make it variadic?
1574 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1575 if (!ToReturnTypeOrErr)
1576 return ToReturnTypeOrErr.takeError();
1577
1578 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1579 T->getExtInfo());
1580}
1581
1583ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1584 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1585 if (!ToReturnTypeOrErr)
1586 return ToReturnTypeOrErr.takeError();
1587
1588 // Import argument types
1589 SmallVector<QualType, 4> ArgTypes;
1590 for (const auto &A : T->param_types()) {
1591 ExpectedType TyOrErr = import(A);
1592 if (!TyOrErr)
1593 return TyOrErr.takeError();
1594 ArgTypes.push_back(*TyOrErr);
1595 }
1596
1597 // Import exception types
1598 SmallVector<QualType, 4> ExceptionTypes;
1599 for (const auto &E : T->exceptions()) {
1600 ExpectedType TyOrErr = import(E);
1601 if (!TyOrErr)
1602 return TyOrErr.takeError();
1603 ExceptionTypes.push_back(*TyOrErr);
1604 }
1605
1606 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
1607 Error Err = Error::success();
1608 FunctionProtoType::ExtProtoInfo ToEPI;
1609 ToEPI.ExtInfo = FromEPI.ExtInfo;
1610 ToEPI.Variadic = FromEPI.Variadic;
1611 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1612 ToEPI.TypeQuals = FromEPI.TypeQuals;
1613 ToEPI.RefQualifier = FromEPI.RefQualifier;
1614 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1616 importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr);
1618 importChecked(Err, FromEPI.ExceptionSpec.SourceDecl);
1620 importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate);
1621 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1622
1623 if (Err)
1624 return std::move(Err);
1625
1626 return Importer.getToContext().getFunctionType(
1627 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1628}
1629
1630ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1631 const UnresolvedUsingType *T) {
1632 Error Err = Error::success();
1633 auto ToQualifier = importChecked(Err, T->getQualifier());
1634 auto *ToD = importChecked(Err, T->getDecl());
1635 if (Err)
1636 return std::move(Err);
1637
1638 if (T->isCanonicalUnqualified())
1639 return Importer.getToContext().getCanonicalUnresolvedUsingType(ToD);
1640 return Importer.getToContext().getUnresolvedUsingType(T->getKeyword(),
1641 ToQualifier, ToD);
1642}
1643
1644ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1645 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1646 if (!ToInnerTypeOrErr)
1647 return ToInnerTypeOrErr.takeError();
1648
1649 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1650}
1651
1653ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1654
1655 ExpectedType Pattern = import(T->getPattern());
1656 if (!Pattern)
1657 return Pattern.takeError();
1658 ExpectedExpr Index = import(T->getIndexExpr());
1659 if (!Index)
1660 return Index.takeError();
1661 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1662}
1663
1664ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1665 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1666 if (!ToDeclOrErr)
1667 return ToDeclOrErr.takeError();
1668
1669 auto ToQualifierOrErr = import(T->getQualifier());
1670 if (!ToQualifierOrErr)
1671 return ToQualifierOrErr.takeError();
1672
1673 ExpectedType ToUnderlyingTypeOrErr =
1674 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1675 if (!ToUnderlyingTypeOrErr)
1676 return ToUnderlyingTypeOrErr.takeError();
1677
1678 return Importer.getToContext().getTypedefType(
1679 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1680}
1681
1682ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1683 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1684 if (!ToExprOrErr)
1685 return ToExprOrErr.takeError();
1686 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1687}
1688
1689ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1690 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1691 if (!ToUnderlyingTypeOrErr)
1692 return ToUnderlyingTypeOrErr.takeError();
1693 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1694 T->getKind());
1695}
1696
1697ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1698 Error Err = Error::success();
1699 auto ToQualifier = importChecked(Err, T->getQualifier());
1700 auto *ToD = importChecked(Err, T->getDecl());
1701 QualType ToT = importChecked(Err, T->desugar());
1702 if (Err)
1703 return std::move(Err);
1704 return Importer.getToContext().getUsingType(T->getKeyword(), ToQualifier, ToD,
1705 ToT);
1706}
1707
1708ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1709 // FIXME: Make sure that the "to" context supports C++0x!
1710 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1711 if (!ToExprOrErr)
1712 return ToExprOrErr.takeError();
1713
1714 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1715 if (!ToUnderlyingTypeOrErr)
1716 return ToUnderlyingTypeOrErr.takeError();
1717
1718 return Importer.getToContext().getDecltypeType(
1719 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1720}
1721
1723ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1724 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1725 if (!ToBaseTypeOrErr)
1726 return ToBaseTypeOrErr.takeError();
1727
1728 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1729 if (!ToUnderlyingTypeOrErr)
1730 return ToUnderlyingTypeOrErr.takeError();
1731
1732 return Importer.getToContext().getUnaryTransformType(
1733 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1734}
1735
1736ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1737 // FIXME: Make sure that the "to" context supports C++11!
1738 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1739 if (!ToDeducedTypeOrErr)
1740 return ToDeducedTypeOrErr.takeError();
1741
1742 Expected<TemplateDecl *> ToTypeConstraint =
1743 import(T->getTypeConstraintConcept());
1744 if (!ToTypeConstraint)
1745 return ToTypeConstraint.takeError();
1746
1747 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1748 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1749 ToTemplateArgs))
1750 return std::move(Err);
1751
1752 return Importer.getToContext().getAutoType(
1753 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1754 *ToTypeConstraint, ToTemplateArgs);
1755}
1756
1757ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1758 const DeducedTemplateSpecializationType *T) {
1759 // FIXME: Make sure that the "to" context supports C++17!
1760 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1761 if (!ToTemplateNameOrErr)
1762 return ToTemplateNameOrErr.takeError();
1763 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1764 if (!ToDeducedTypeOrErr)
1765 return ToDeducedTypeOrErr.takeError();
1766
1767 return Importer.getToContext().getDeducedTemplateSpecializationType(
1768 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1769 *ToTemplateNameOrErr);
1770}
1771
1772ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1773 TagDecl *DeclForType = T->getDecl();
1774 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1775 if (!ToDeclOrErr)
1776 return ToDeclOrErr.takeError();
1777
1778 // If there is a definition of the 'OriginalDecl', it should be imported to
1779 // have all information for the type in the "To" AST. (In some cases no
1780 // other reference may exist to the definition decl and it would not be
1781 // imported otherwise.)
1782 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1783 if (!ToDefDeclOrErr)
1784 return ToDefDeclOrErr.takeError();
1785
1786 if (T->isCanonicalUnqualified())
1787 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1788
1789 auto ToQualifierOrErr = import(T->getQualifier());
1790 if (!ToQualifierOrErr)
1791 return ToQualifierOrErr.takeError();
1792
1793 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1794 *ToDeclOrErr, T->isTagOwned());
1795}
1796
1797ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1798 return VisitTagType(T);
1799}
1800
1801ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1802 return VisitTagType(T);
1803}
1804
1806ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1807 return VisitTagType(T);
1808}
1809
1810ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1811 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1812 if (!ToModifiedTypeOrErr)
1813 return ToModifiedTypeOrErr.takeError();
1814 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1815 if (!ToEquivalentTypeOrErr)
1816 return ToEquivalentTypeOrErr.takeError();
1817
1818 return Importer.getToContext().getAttributedType(
1819 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1820 T->getAttr());
1821}
1822
1824ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1825 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1826 if (!ToWrappedTypeOrErr)
1827 return ToWrappedTypeOrErr.takeError();
1828
1829 Error Err = Error::success();
1830 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1831
1832 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1833 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1834 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1835 if (!ToDeclOrErr)
1836 return ToDeclOrErr.takeError();
1837 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1838 }
1839
1840 return Importer.getToContext().getCountAttributedType(
1841 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1842 ArrayRef(CoupledDecls));
1843}
1844
1845ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1846 const TemplateTypeParmType *T) {
1847 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1848 if (!ToDeclOrErr)
1849 return ToDeclOrErr.takeError();
1850
1851 return Importer.getToContext().getTemplateTypeParmType(
1852 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1853}
1854
1855ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1856 const SubstTemplateTypeParmType *T) {
1857 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1858 if (!ReplacedOrErr)
1859 return ReplacedOrErr.takeError();
1860
1861 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1862 if (!ToReplacementTypeOrErr)
1863 return ToReplacementTypeOrErr.takeError();
1864
1865 return Importer.getToContext().getSubstTemplateTypeParmType(
1866 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1867 T->getFinal());
1868}
1869
1870ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1871 const SubstTemplateTypeParmPackType *T) {
1872 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1873 if (!ReplacedOrErr)
1874 return ReplacedOrErr.takeError();
1875
1876 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1877 if (!ToArgumentPack)
1878 return ToArgumentPack.takeError();
1879
1880 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1881 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1882}
1883
1884ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1885 const SubstBuiltinTemplatePackType *T) {
1886 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1887 if (!ToArgumentPack)
1888 return ToArgumentPack.takeError();
1889 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1890}
1891
1892ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1893 const TemplateSpecializationType *T) {
1894 auto ToTemplateOrErr = import(T->getTemplateName());
1895 if (!ToTemplateOrErr)
1896 return ToTemplateOrErr.takeError();
1897
1898 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1899 if (Error Err =
1900 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1901 return std::move(Err);
1902
1903 ExpectedType ToUnderlyingOrErr =
1904 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1905 if (!ToUnderlyingOrErr)
1906 return ToUnderlyingOrErr.takeError();
1907 return Importer.getToContext().getTemplateSpecializationType(
1908 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1909 *ToUnderlyingOrErr);
1910}
1911
1913ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1914 ExpectedType ToPatternOrErr = import(T->getPattern());
1915 if (!ToPatternOrErr)
1916 return ToPatternOrErr.takeError();
1917
1918 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1919 T->getNumExpansions(),
1920 /*ExpactPack=*/false);
1921}
1922
1924ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1925 auto ToQualifierOrErr = import(T->getQualifier());
1926 if (!ToQualifierOrErr)
1927 return ToQualifierOrErr.takeError();
1928
1929 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1930 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1931 *ToQualifierOrErr, Name);
1932}
1933
1935ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1936 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1937 if (!ToDeclOrErr)
1938 return ToDeclOrErr.takeError();
1939
1940 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1941}
1942
1943ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1944 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1945 if (!ToBaseTypeOrErr)
1946 return ToBaseTypeOrErr.takeError();
1947
1948 SmallVector<QualType, 4> TypeArgs;
1949 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1950 if (ExpectedType TyOrErr = import(TypeArg))
1951 TypeArgs.push_back(*TyOrErr);
1952 else
1953 return TyOrErr.takeError();
1954 }
1955
1956 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1957 for (auto *P : T->quals()) {
1958 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1959 Protocols.push_back(*ProtocolOrErr);
1960 else
1961 return ProtocolOrErr.takeError();
1962
1963 }
1964
1965 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1966 Protocols,
1967 T->isKindOfTypeAsWritten());
1968}
1969
1971ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1972 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1973 if (!ToPointeeTypeOrErr)
1974 return ToPointeeTypeOrErr.takeError();
1975
1976 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1977}
1978
1980ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1981 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1982 if (!ToUnderlyingTypeOrErr)
1983 return ToUnderlyingTypeOrErr.takeError();
1984
1985 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1986 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1987 ToIdentifier);
1988}
1989
1990ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1991 Error Err = Error::success();
1992 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1993 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1994 if (Err)
1995 return std::move(Err);
1996
1997 return Importer.getToContext().getAdjustedType(ToOriginalType,
1998 ToAdjustedType);
1999}
2000
2001ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
2002 return Importer.getToContext().getBitIntType(T->isUnsigned(),
2003 T->getNumBits());
2004}
2005
2006ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
2007 const clang::BTFTagAttributedType *T) {
2008 Error Err = Error::success();
2009 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
2010 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2011 if (Err)
2012 return std::move(Err);
2013
2014 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
2015 ToWrappedType);
2016}
2017
2018ExpectedType clang::ASTNodeImporter::VisitOverflowBehaviorType(
2019 const clang::OverflowBehaviorType *T) {
2020 Error Err = Error::success();
2021 OverflowBehaviorType::OverflowBehaviorKind ToKind = T->getBehaviorKind();
2022 QualType ToUnderlyingType = importChecked(Err, T->getUnderlyingType());
2023 if (Err)
2024 return std::move(Err);
2025
2026 return Importer.getToContext().getOverflowBehaviorType(ToKind,
2028}
2029
2030ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2031 const clang::HLSLAttributedResourceType *T) {
2032 Error Err = Error::success();
2033 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
2034 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2035 QualType ToContainedType = importChecked(Err, T->getContainedType());
2036 if (Err)
2037 return std::move(Err);
2038
2039 return Importer.getToContext().getHLSLAttributedResourceType(
2040 ToWrappedType, ToContainedType, ToAttrs);
2041}
2042
2043ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2044 const clang::HLSLInlineSpirvType *T) {
2045 Error Err = Error::success();
2046
2047 uint32_t ToOpcode = T->getOpcode();
2048 uint32_t ToSize = T->getSize();
2049 uint32_t ToAlignment = T->getAlignment();
2050
2051 llvm::SmallVector<SpirvOperand> ToOperands;
2052
2053 for (auto &Operand : T->getOperands()) {
2054 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2055
2056 switch (Operand.getKind()) {
2057 case SpirvOperandKind::ConstantId:
2058 ToOperands.push_back(SpirvOperand::createConstant(
2059 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2060 break;
2061 case SpirvOperandKind::Literal:
2062 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2063 break;
2064 case SpirvOperandKind::TypeId:
2065 ToOperands.push_back(SpirvOperand::createType(
2066 importChecked(Err, Operand.getResultType())));
2067 break;
2068 default:
2069 llvm_unreachable("Invalid SpirvOperand kind");
2070 }
2071
2072 if (Err)
2073 return std::move(Err);
2074 }
2075
2076 return Importer.getToContext().getHLSLInlineSpirvType(
2077 ToOpcode, ToSize, ToAlignment, ToOperands);
2078}
2079
2080ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2081 const clang::ConstantMatrixType *T) {
2082 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2083 if (!ToElementTypeOrErr)
2084 return ToElementTypeOrErr.takeError();
2085
2086 return Importer.getToContext().getConstantMatrixType(
2087 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2088}
2089
2090ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2091 const clang::DependentAddressSpaceType *T) {
2092 Error Err = Error::success();
2093 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2094 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2095 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2096 if (Err)
2097 return std::move(Err);
2098
2099 return Importer.getToContext().getDependentAddressSpaceType(
2100 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2101}
2102
2103ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2104 const clang::DependentBitIntType *T) {
2105 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2106 if (!ToNumBitsExprOrErr)
2107 return ToNumBitsExprOrErr.takeError();
2108 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2109 *ToNumBitsExprOrErr);
2110}
2111
2112ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2113 const clang::PredefinedSugarType *T) {
2114 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2115}
2116
2117ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2118 const clang::DependentSizedMatrixType *T) {
2119 Error Err = Error::success();
2120 QualType ToElementType = importChecked(Err, T->getElementType());
2121 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2122 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2123 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2124 if (Err)
2125 return std::move(Err);
2126
2127 return Importer.getToContext().getDependentSizedMatrixType(
2128 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2129}
2130
2131ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2132 const clang::DependentVectorType *T) {
2133 Error Err = Error::success();
2134 QualType ToElementType = importChecked(Err, T->getElementType());
2135 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2136 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2137 if (Err)
2138 return std::move(Err);
2139
2140 return Importer.getToContext().getDependentVectorType(
2141 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2142}
2143
2144ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2145 const clang::ObjCTypeParamType *T) {
2146 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2147 if (!ToDeclOrErr)
2148 return ToDeclOrErr.takeError();
2149
2150 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2151 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2152 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2153 if (!ToProtocolOrErr)
2154 return ToProtocolOrErr.takeError();
2155 ToProtocols.push_back(*ToProtocolOrErr);
2156 }
2157
2158 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2159 ToProtocols);
2160}
2161
2162ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2163 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2164 if (!ToElementTypeOrErr)
2165 return ToElementTypeOrErr.takeError();
2166
2167 ASTContext &ToCtx = Importer.getToContext();
2168 if (T->isReadOnly())
2169 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2170 else
2171 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2172}
2173
2174//----------------------------------------------------------------------------
2175// Import Declarations
2176//----------------------------------------------------------------------------
2178 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2179 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2180 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2181 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2182 // FIXME: We could support these constructs by importing a different type of
2183 // this parameter and by importing the original type of the parameter only
2184 // after the FunctionDecl is created. See
2185 // VisitFunctionDecl::UsedDifferentProtoType.
2186 DeclContext *OrigDC = D->getDeclContext();
2187 FunctionDecl *FunDecl;
2188 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2189 FunDecl->hasBody()) {
2190 auto getLeafPointeeType = [](const Type *T) {
2191 while (T->isPointerType() || T->isArrayType()) {
2192 T = T->getPointeeOrArrayElementType();
2193 }
2194 return T;
2195 };
2196 for (const ParmVarDecl *P : FunDecl->parameters()) {
2197 const Type *LeafT =
2198 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2199 auto *RT = dyn_cast<RecordType>(LeafT);
2200 if (RT && RT->getDecl() == D) {
2201 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2202 << D->getDeclKindName();
2203 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2204 }
2205 }
2206 }
2207
2208 // Import the context of this declaration.
2209 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2210 return Err;
2211
2212 // Import the name of this declaration.
2213 if (Error Err = importInto(Name, D->getDeclName()))
2214 return Err;
2215
2216 // Import the location of this declaration.
2217 if (Error Err = importInto(Loc, D->getLocation()))
2218 return Err;
2219
2220 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2221 if (ToD)
2222 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2223 return Err;
2224
2225 return Error::success();
2226}
2227
2229 NamedDecl *&ToD, SourceLocation &Loc) {
2230
2231 // Import the name of this declaration.
2232 if (Error Err = importInto(Name, D->getDeclName()))
2233 return Err;
2234
2235 // Import the location of this declaration.
2236 if (Error Err = importInto(Loc, D->getLocation()))
2237 return Err;
2238
2239 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2240 if (ToD)
2241 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2242 return Err;
2243
2244 return Error::success();
2245}
2246
2248 if (!FromD)
2249 return Error::success();
2250
2251 if (!ToD)
2252 if (Error Err = importInto(ToD, FromD))
2253 return Err;
2254
2255 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2256 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2257 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2258 !ToRecord->getDefinition()) {
2259 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2260 return Err;
2261 }
2262 }
2263 return Error::success();
2264 }
2265
2266 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2267 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2268 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2269 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2270 return Err;
2271 }
2272 }
2273 return Error::success();
2274 }
2275
2276 return Error::success();
2277}
2278
2279Error
2281 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2282 // NOTE: To.Name and To.Loc are already imported.
2283 // We only have to import To.LocInfo.
2284 switch (To.getName().getNameKind()) {
2291 return Error::success();
2292
2294 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2295 To.setCXXOperatorNameRange(*ToRangeOrErr);
2296 else
2297 return ToRangeOrErr.takeError();
2298 return Error::success();
2299 }
2301 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2302 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2303 else
2304 return LocOrErr.takeError();
2305 return Error::success();
2306 }
2310 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2311 To.setNamedTypeInfo(*ToTInfoOrErr);
2312 else
2313 return ToTInfoOrErr.takeError();
2314 return Error::success();
2315 }
2316 }
2317 llvm_unreachable("Unknown name kind.");
2318}
2319
2320Error
2322 if (Importer.isMinimalImport() && !ForceImport) {
2323 auto ToDCOrErr = Importer.ImportContext(FromDC);
2324 return ToDCOrErr.takeError();
2325 }
2326
2327 // We use strict error handling in case of records and enums, but not
2328 // with e.g. namespaces.
2329 //
2330 // FIXME Clients of the ASTImporter should be able to choose an
2331 // appropriate error handling strategy for their needs. For instance,
2332 // they may not want to mark an entire namespace as erroneous merely
2333 // because there is an ODR error with two typedefs. As another example,
2334 // the client may allow EnumConstantDecls with same names but with
2335 // different values in two distinct translation units.
2336 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2337
2338 auto MightNeedReordering = [](const Decl *D) {
2340 };
2341
2342 // Import everything that might need reordering first.
2343 Error ChildErrors = Error::success();
2344 for (auto *From : FromDC->decls()) {
2345 if (!MightNeedReordering(From))
2346 continue;
2347
2348 ExpectedDecl ImportedOrErr = import(From);
2349
2350 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2351 // want to make sure that we are also completing each FieldDecl. There
2352 // are currently cases where this does not happen and this is correctness
2353 // fix since operations such as code generation will expect this to be so.
2354 if (!ImportedOrErr) {
2355 HandleChildErrors.handleChildImportResult(ChildErrors,
2356 ImportedOrErr.takeError());
2357 continue;
2358 }
2359 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2360 Decl *ImportedDecl = *ImportedOrErr;
2361 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2362 if (FieldFrom && FieldTo) {
2363 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2364 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2365 }
2366 }
2367
2368 // We reorder declarations in RecordDecls because they may have another order
2369 // in the "to" context than they have in the "from" context. This may happen
2370 // e.g when we import a class like this:
2371 // struct declToImport {
2372 // int a = c + b;
2373 // int b = 1;
2374 // int c = 2;
2375 // };
2376 // During the import of `a` we import first the dependencies in sequence,
2377 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2378 // first removing the already imported members and then adding them in the
2379 // order as they appear in the "from" context.
2380 //
2381 // Keeping field order is vital because it determines structure layout.
2382 //
2383 // Here and below, we cannot call field_begin() method and its callers on
2384 // ToDC if it has an external storage. Calling field_begin() will
2385 // automatically load all the fields by calling
2386 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2387 // call ASTImporter::Import(). This is because the ExternalASTSource
2388 // interface in LLDB is implemented by the means of the ASTImporter. However,
2389 // calling an import at this point would result in an uncontrolled import, we
2390 // must avoid that.
2391
2392 auto ToDCOrErr = Importer.ImportContext(FromDC);
2393 if (!ToDCOrErr) {
2394 consumeError(std::move(ChildErrors));
2395 return ToDCOrErr.takeError();
2396 }
2397
2398 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2399 DeclContext *ToDC = *ToDCOrErr;
2400 // Remove all declarations, which may be in wrong order in the
2401 // lexical DeclContext and then add them in the proper order.
2402 for (auto *D : FromRD->decls()) {
2403 if (!MightNeedReordering(D))
2404 continue;
2405
2406 assert(D && "DC contains a null decl");
2407 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2408 // Remove only the decls which we successfully imported.
2409 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2410 // Remove the decl from its wrong place in the linked list.
2411 ToDC->removeDecl(ToD);
2412 // Add the decl to the end of the linked list.
2413 // This time it will be at the proper place because the enclosing for
2414 // loop iterates in the original (good) order of the decls.
2415 ToDC->addDeclInternal(ToD);
2416 }
2417 }
2418 }
2419
2420 // Import everything else.
2421 for (auto *From : FromDC->decls()) {
2422 if (MightNeedReordering(From))
2423 continue;
2424
2425 ExpectedDecl ImportedOrErr = import(From);
2426 if (!ImportedOrErr)
2427 HandleChildErrors.handleChildImportResult(ChildErrors,
2428 ImportedOrErr.takeError());
2429 }
2430
2431 return ChildErrors;
2432}
2433
2435 const FieldDecl *To) {
2436 RecordDecl *FromRecordDecl = nullptr;
2437 RecordDecl *ToRecordDecl = nullptr;
2438 // If we have a field that is an ArrayType we need to check if the array
2439 // element is a RecordDecl and if so we need to import the definition.
2440 QualType FromType = From->getType();
2441 QualType ToType = To->getType();
2442 if (FromType->isArrayType()) {
2443 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2444 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2445 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2446 }
2447
2448 if (!FromRecordDecl || !ToRecordDecl) {
2449 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2450 const RecordType *RecordTo = ToType->getAs<RecordType>();
2451
2452 if (RecordFrom && RecordTo) {
2453 FromRecordDecl = RecordFrom->getDecl();
2454 ToRecordDecl = RecordTo->getDecl();
2455 }
2456 }
2457
2458 if (FromRecordDecl && ToRecordDecl) {
2459 if (FromRecordDecl->isCompleteDefinition() &&
2460 !ToRecordDecl->isCompleteDefinition())
2461 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2462 }
2463
2464 return Error::success();
2465}
2466
2468 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2469 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2470 if (!ToDCOrErr)
2471 return ToDCOrErr.takeError();
2472 ToDC = *ToDCOrErr;
2473
2474 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2475 auto ToLexicalDCOrErr = Importer.ImportContext(
2476 FromD->getLexicalDeclContext());
2477 if (!ToLexicalDCOrErr)
2478 return ToLexicalDCOrErr.takeError();
2479 ToLexicalDC = *ToLexicalDCOrErr;
2480 } else
2481 ToLexicalDC = ToDC;
2482
2483 return Error::success();
2484}
2485
2487 const CXXRecordDecl *From, CXXRecordDecl *To) {
2488 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2489 "Import implicit methods to or from non-definition");
2490
2491 for (CXXMethodDecl *FromM : From->methods())
2492 if (FromM->isImplicit()) {
2493 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2494 if (!ToMOrErr)
2495 return ToMOrErr.takeError();
2496 }
2497
2498 return Error::success();
2499}
2500
2502 ASTImporter &Importer) {
2503 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2504 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2506 else
2507 return ToTypedefOrErr.takeError();
2508 }
2509 return Error::success();
2510}
2511
2513 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2514 auto DefinitionCompleter = [To]() {
2515 // There are cases in LLDB when we first import a class without its
2516 // members. The class will have DefinitionData, but no members. Then,
2517 // importDefinition is called from LLDB, which tries to get the members, so
2518 // when we get here, the class already has the DefinitionData set, so we
2519 // must unset the CompleteDefinition here to be able to complete again the
2520 // definition.
2521 To->setCompleteDefinition(false);
2522 To->completeDefinition();
2523 };
2524
2525 if (To->getDefinition() || To->isBeingDefined()) {
2526 if (Kind == IDK_Everything ||
2527 // In case of lambdas, the class already has a definition ptr set, but
2528 // the contained decls are not imported yet. Also, isBeingDefined was
2529 // set in CXXRecordDecl::CreateLambda. We must import the contained
2530 // decls here and finish the definition.
2531 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2532 if (To->isLambda()) {
2533 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2535 ToCaptures.reserve(FromCXXRD->capture_size());
2536 for (const auto &FromCapture : FromCXXRD->captures()) {
2537 if (auto ToCaptureOrErr = import(FromCapture))
2538 ToCaptures.push_back(*ToCaptureOrErr);
2539 else
2540 return ToCaptureOrErr.takeError();
2541 }
2542 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2543 ToCaptures);
2544 }
2545
2546 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2547 // Finish the definition of the lambda, set isBeingDefined to false.
2548 if (To->isLambda())
2549 DefinitionCompleter();
2550 return Result;
2551 }
2552
2553 return Error::success();
2554 }
2555
2556 To->startDefinition();
2557 // Set the definition to complete even if it is really not complete during
2558 // import. Some AST constructs (expressions) require the record layout
2559 // to be calculated (see 'clang::computeDependence') at the time they are
2560 // constructed. Import of such AST node is possible during import of the
2561 // same record, there is no way to have a completely defined record (all
2562 // fields imported) at that time without multiple AST import passes.
2563 if (!Importer.isMinimalImport())
2564 To->setCompleteDefinition(true);
2565 // Complete the definition even if error is returned.
2566 // The RecordDecl may be already part of the AST so it is better to
2567 // have it in complete state even if something is wrong with it.
2568 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2569
2570 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2571 return Err;
2572
2573 // Add base classes.
2574 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2575 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2576 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2577
2578 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2579 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2580
2581 #define FIELD(Name, Width, Merge) \
2582 ToData.Name = FromData.Name;
2583 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2584
2585 // Copy over the data stored in RecordDeclBits
2586 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2587
2589 for (const auto &Base1 : FromCXX->bases()) {
2590 ExpectedType TyOrErr = import(Base1.getType());
2591 if (!TyOrErr)
2592 return TyOrErr.takeError();
2593
2594 SourceLocation EllipsisLoc;
2595 if (Base1.isPackExpansion()) {
2596 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2597 EllipsisLoc = *LocOrErr;
2598 else
2599 return LocOrErr.takeError();
2600 }
2601
2602 // Ensure that we have a definition for the base.
2603 if (Error Err =
2604 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2605 return Err;
2606
2607 auto RangeOrErr = import(Base1.getSourceRange());
2608 if (!RangeOrErr)
2609 return RangeOrErr.takeError();
2610
2611 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2612 if (!TSIOrErr)
2613 return TSIOrErr.takeError();
2614
2615 Bases.push_back(
2616 new (Importer.getToContext()) CXXBaseSpecifier(
2617 *RangeOrErr,
2618 Base1.isVirtual(),
2619 Base1.isBaseOfClass(),
2620 Base1.getAccessSpecifierAsWritten(),
2621 *TSIOrErr,
2622 EllipsisLoc));
2623 }
2624 if (!Bases.empty())
2625 ToCXX->setBases(Bases.data(), Bases.size());
2626 }
2627
2628 if (shouldForceImportDeclContext(Kind)) {
2629 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2630 return Err;
2631 }
2632
2633 return Error::success();
2634}
2635
2637 if (To->getAnyInitializer())
2638 return Error::success();
2639
2640 Expr *FromInit = From->getInit();
2641 if (!FromInit)
2642 return Error::success();
2643
2644 ExpectedExpr ToInitOrErr = import(FromInit);
2645 if (!ToInitOrErr)
2646 return ToInitOrErr.takeError();
2647
2648 To->setInit(*ToInitOrErr);
2649 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2650 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2651 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2652 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2653 // FIXME: Also import the initializer value.
2654 }
2655
2656 // FIXME: Other bits to merge?
2657 return Error::success();
2658}
2659
2661 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2662 if (To->getDefinition() || To->isBeingDefined()) {
2663 if (Kind == IDK_Everything)
2664 return ImportDeclContext(From, /*ForceImport=*/true);
2665 return Error::success();
2666 }
2667
2668 To->startDefinition();
2669
2670 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2671 return Err;
2672
2673 ExpectedType ToTypeOrErr =
2674 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2675 if (!ToTypeOrErr)
2676 return ToTypeOrErr.takeError();
2677
2678 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2679 if (!ToPromotionTypeOrErr)
2680 return ToPromotionTypeOrErr.takeError();
2681
2683 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2684 return Err;
2685
2686 // FIXME: we might need to merge the number of positive or negative bits
2687 // if the enumerator lists don't match.
2688 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2689 From->getNumPositiveBits(),
2690 From->getNumNegativeBits());
2691 return Error::success();
2692}
2693
2697 for (const auto &Arg : FromArgs) {
2698 if (auto ToOrErr = import(Arg))
2699 ToArgs.push_back(*ToOrErr);
2700 else
2701 return ToOrErr.takeError();
2702 }
2703
2704 return Error::success();
2705}
2706
2707// FIXME: Do not forget to remove this and use only 'import'.
2710 return import(From);
2711}
2712
2713template <typename InContainerTy>
2715 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2716 for (const auto &FromLoc : Container) {
2717 if (auto ToLocOrErr = import(FromLoc))
2718 ToTAInfo.addArgument(*ToLocOrErr);
2719 else
2720 return ToLocOrErr.takeError();
2721 }
2722 return Error::success();
2723}
2724
2730
2731bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2732 bool IgnoreTemplateParmDepth) {
2733 // Eliminate a potential failure point where we attempt to re-import
2734 // something we're trying to import while completing ToRecord.
2735 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2736 if (ToOrigin) {
2737 To = ToOrigin;
2738 }
2739
2741 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2742 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2744 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2745 IgnoreTemplateParmDepth);
2746 return Ctx.IsEquivalent(From, To);
2747}
2748
2750 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2751 << D->getDeclKindName();
2752 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2753}
2754
2756 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2757 << D->getDeclKindName();
2758 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2759}
2760
2762 // Import the context of this declaration.
2763 DeclContext *DC, *LexicalDC;
2764 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2765 return std::move(Err);
2766
2767 // Import the location of this declaration.
2768 ExpectedSLoc LocOrErr = import(D->getLocation());
2769 if (!LocOrErr)
2770 return LocOrErr.takeError();
2771
2772 EmptyDecl *ToD;
2773 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2774 return ToD;
2775
2776 ToD->setLexicalDeclContext(LexicalDC);
2777 LexicalDC->addDeclInternal(ToD);
2778 return ToD;
2779}
2780
2782 TranslationUnitDecl *ToD =
2783 Importer.getToContext().getTranslationUnitDecl();
2784
2785 Importer.MapImported(D, ToD);
2786
2787 return ToD;
2788}
2789
2791 DeclContext *DC, *LexicalDC;
2792 DeclarationName Name;
2793 SourceLocation Loc;
2794 NamedDecl *ToND;
2795 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2796 return std::move(Err);
2797 if (ToND)
2798 return ToND;
2799
2800 BindingDecl *ToD;
2801 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2802 Name.getAsIdentifierInfo(), D->getType()))
2803 return ToD;
2804
2805 Error Err = Error::success();
2806 QualType ToType = importChecked(Err, D->getType());
2807 Expr *ToBinding = importChecked(Err, D->getBinding());
2808 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2809 if (Err)
2810 return std::move(Err);
2811
2812 ToD->setBinding(ToType, ToBinding);
2813 ToD->setDecomposedDecl(ToDecomposedDecl);
2814 addDeclToContexts(D, ToD);
2815
2816 return ToD;
2817}
2818
2820 ExpectedSLoc LocOrErr = import(D->getLocation());
2821 if (!LocOrErr)
2822 return LocOrErr.takeError();
2823 auto ColonLocOrErr = import(D->getColonLoc());
2824 if (!ColonLocOrErr)
2825 return ColonLocOrErr.takeError();
2826
2827 // Import the context of this declaration.
2828 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2829 if (!DCOrErr)
2830 return DCOrErr.takeError();
2831 DeclContext *DC = *DCOrErr;
2832
2833 AccessSpecDecl *ToD;
2834 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2835 DC, *LocOrErr, *ColonLocOrErr))
2836 return ToD;
2837
2838 // Lexical DeclContext and Semantic DeclContext
2839 // is always the same for the accessSpec.
2840 ToD->setLexicalDeclContext(DC);
2841 DC->addDeclInternal(ToD);
2842
2843 return ToD;
2844}
2845
2847 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2848 if (!DCOrErr)
2849 return DCOrErr.takeError();
2850 DeclContext *DC = *DCOrErr;
2851 DeclContext *LexicalDC = DC;
2852
2853 Error Err = Error::success();
2854 auto ToLocation = importChecked(Err, D->getLocation());
2855 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2856 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2857 auto ToMessage = importChecked(Err, D->getMessage());
2858 if (Err)
2859 return std::move(Err);
2860
2861 StaticAssertDecl *ToD;
2862 if (GetImportedOrCreateDecl(
2863 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2864 ToRParenLoc, D->isFailed()))
2865 return ToD;
2866
2867 ToD->setLexicalDeclContext(LexicalDC);
2868 LexicalDC->addDeclInternal(ToD);
2869 return ToD;
2870}
2871
2873 // Import the major distinguishing characteristics of this namespace.
2874 DeclContext *DC, *LexicalDC;
2875 DeclarationName Name;
2876 SourceLocation Loc;
2877 NamedDecl *ToD;
2878 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2879 return std::move(Err);
2880 if (ToD)
2881 return ToD;
2882
2883 NamespaceDecl *MergeWithNamespace = nullptr;
2884 if (!Name) {
2885 // This is an anonymous namespace. Adopt an existing anonymous
2886 // namespace if we can.
2887 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2888 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2889 MergeWithNamespace = TU->getAnonymousNamespace();
2890 else
2891 MergeWithNamespace =
2892 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2893 } else {
2894 SmallVector<NamedDecl *, 4> ConflictingDecls;
2895 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2896 for (auto *FoundDecl : FoundDecls) {
2897 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2898 continue;
2899
2900 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2901 MergeWithNamespace = FoundNS;
2902 ConflictingDecls.clear();
2903 break;
2904 }
2905
2906 ConflictingDecls.push_back(FoundDecl);
2907 }
2908
2909 if (!ConflictingDecls.empty()) {
2910 ExpectedName NameOrErr = Importer.HandleNameConflict(
2911 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2912 ConflictingDecls.size());
2913 if (NameOrErr)
2914 Name = NameOrErr.get();
2915 else
2916 return NameOrErr.takeError();
2917 }
2918 }
2919
2920 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2921 if (!BeginLocOrErr)
2922 return BeginLocOrErr.takeError();
2923 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2924 if (!RBraceLocOrErr)
2925 return RBraceLocOrErr.takeError();
2926
2927 // Create the "to" namespace, if needed.
2928 NamespaceDecl *ToNamespace = MergeWithNamespace;
2929 if (!ToNamespace) {
2930 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2931 D->isInline(), *BeginLocOrErr, Loc,
2932 Name.getAsIdentifierInfo(),
2933 /*PrevDecl=*/nullptr, D->isNested()))
2934 return ToNamespace;
2935 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2936 ToNamespace->setLexicalDeclContext(LexicalDC);
2937 LexicalDC->addDeclInternal(ToNamespace);
2938
2939 // If this is an anonymous namespace, register it as the anonymous
2940 // namespace within its context.
2941 if (!Name) {
2942 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2943 TU->setAnonymousNamespace(ToNamespace);
2944 else
2945 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2946 }
2947 }
2948 Importer.MapImported(D, ToNamespace);
2949
2950 if (Error Err = ImportDeclContext(D))
2951 return std::move(Err);
2952
2953 return ToNamespace;
2954}
2955
2957 // Import the major distinguishing characteristics of this namespace.
2958 DeclContext *DC, *LexicalDC;
2959 DeclarationName Name;
2960 SourceLocation Loc;
2961 NamedDecl *LookupD;
2962 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2963 return std::move(Err);
2964 if (LookupD)
2965 return LookupD;
2966
2967 // NOTE: No conflict resolution is done for namespace aliases now.
2968
2969 Error Err = Error::success();
2970 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2971 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2972 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2973 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2974 auto ToNamespace = importChecked(Err, D->getNamespace());
2975 if (Err)
2976 return std::move(Err);
2977
2978 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2979
2980 NamespaceAliasDecl *ToD;
2981 if (GetImportedOrCreateDecl(
2982 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2983 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2984 return ToD;
2985
2986 ToD->setLexicalDeclContext(LexicalDC);
2987 LexicalDC->addDeclInternal(ToD);
2988
2989 return ToD;
2990}
2991
2994 // Import the major distinguishing characteristics of this typedef.
2995 DeclarationName Name;
2996 SourceLocation Loc;
2997 NamedDecl *ToD;
2998 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2999 // is created.
3000 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
3001 return std::move(Err);
3002 if (ToD)
3003 return ToD;
3004
3005 DeclContext *DC = cast_or_null<DeclContext>(
3006 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
3007 DeclContext *LexicalDC =
3008 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
3010
3011 // If this typedef is not in block scope, determine whether we've
3012 // seen a typedef with the same name (that we can merge with) or any
3013 // other entity by that name (which name lookup could conflict with).
3014 // Note: Repeated typedefs are not valid in C99:
3015 // 'typedef int T; typedef int T;' is invalid
3016 // We do not care about this now.
3017 if (DC && !DC->isFunctionOrMethod()) {
3018 SmallVector<NamedDecl *, 4> ConflictingDecls;
3019 unsigned IDNS = Decl::IDNS_Ordinary;
3020 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3021 for (auto *FoundDecl : FoundDecls) {
3022 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3023 continue;
3024 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3025 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3026 continue;
3027
3028 QualType FromUT = D->getUnderlyingType();
3029 QualType FoundUT = FoundTypedef->getUnderlyingType();
3030 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3031 // If the underlying declarations are unnamed records these can be
3032 // imported as different types. We should create a distinct typedef
3033 // node in this case.
3034 // If we found an existing underlying type with a record in a
3035 // different context (than the imported), this is already reason for
3036 // having distinct typedef nodes for these.
3037 // Again this can create situation like
3038 // 'typedef int T; typedef int T;' but this is hard to avoid without
3039 // a rename strategy at import.
3040 if (!FromUT.isNull() && !FoundUT.isNull()) {
3041 RecordDecl *FromR = FromUT->getAsRecordDecl();
3042 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3043 if (FromR && FoundR &&
3044 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3045 continue;
3046 }
3047 // If the "From" context has a complete underlying type but we
3048 // already have a complete underlying type then return with that.
3049 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3050 return Importer.MapImported(D, FoundTypedef);
3051 // FIXME Handle redecl chain. When you do that make consistent changes
3052 // in ASTImporterLookupTable too.
3053 } else {
3054 ConflictingDecls.push_back(FoundDecl);
3055 }
3056 }
3057 }
3058
3059 if (!ConflictingDecls.empty()) {
3060 ExpectedName NameOrErr = Importer.HandleNameConflict(
3061 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3062 if (NameOrErr)
3063 Name = NameOrErr.get();
3064 else
3065 return NameOrErr.takeError();
3066 }
3067 }
3068
3069 Error Err = Error::success();
3071 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3072 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3073 if (Err)
3074 return std::move(Err);
3075
3076 // Create the new typedef node.
3077 // FIXME: ToUnderlyingType is not used.
3078 (void)ToUnderlyingType;
3079 TypedefNameDecl *ToTypedef;
3080 if (IsAlias) {
3081 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3082 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3083 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3084 return ToTypedef;
3085 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3086 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3087 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3088 return ToTypedef;
3089
3090 // Import the DeclContext and set it to the Typedef.
3091 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3092 return std::move(Err);
3093 ToTypedef->setDeclContext(DC);
3094 ToTypedef->setLexicalDeclContext(LexicalDC);
3095 // Add to the lookupTable because we could not do that in MapImported.
3096 Importer.AddToLookupTable(ToTypedef);
3097
3098 ToTypedef->setAccess(D->getAccess());
3099
3100 // Templated declarations should not appear in DeclContext.
3101 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3102 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3103 LexicalDC->addDeclInternal(ToTypedef);
3104
3105 return ToTypedef;
3106}
3107
3111
3115
3118 // Import the major distinguishing characteristics of this typedef.
3119 DeclContext *DC, *LexicalDC;
3120 DeclarationName Name;
3121 SourceLocation Loc;
3122 NamedDecl *FoundD;
3123 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3124 return std::move(Err);
3125 if (FoundD)
3126 return FoundD;
3127
3128 // If this typedef is not in block scope, determine whether we've
3129 // seen a typedef with the same name (that we can merge with) or any
3130 // other entity by that name (which name lookup could conflict with).
3131 if (!DC->isFunctionOrMethod()) {
3132 SmallVector<NamedDecl *, 4> ConflictingDecls;
3133 unsigned IDNS = Decl::IDNS_Ordinary;
3134 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3135 for (auto *FoundDecl : FoundDecls) {
3136 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3137 continue;
3138 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3139 if (IsStructuralMatch(D, FoundAlias))
3140 return Importer.MapImported(D, FoundAlias);
3141 ConflictingDecls.push_back(FoundDecl);
3142 }
3143 }
3144
3145 if (!ConflictingDecls.empty()) {
3146 ExpectedName NameOrErr = Importer.HandleNameConflict(
3147 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3148 if (NameOrErr)
3149 Name = NameOrErr.get();
3150 else
3151 return NameOrErr.takeError();
3152 }
3153 }
3154
3155 Error Err = Error::success();
3156 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3157 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3158 if (Err)
3159 return std::move(Err);
3160
3161 TypeAliasTemplateDecl *ToAlias;
3162 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3163 Name, ToTemplateParameters, ToTemplatedDecl))
3164 return ToAlias;
3165
3166 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3167
3168 ToAlias->setAccess(D->getAccess());
3169 ToAlias->setLexicalDeclContext(LexicalDC);
3170 LexicalDC->addDeclInternal(ToAlias);
3171 if (DC != Importer.getToContext().getTranslationUnitDecl())
3172 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3173 return ToAlias;
3174}
3175
3177 // Import the major distinguishing characteristics of this label.
3178 DeclContext *DC, *LexicalDC;
3179 DeclarationName Name;
3180 SourceLocation Loc;
3181 NamedDecl *ToD;
3182 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3183 return std::move(Err);
3184 if (ToD)
3185 return ToD;
3186
3187 assert(LexicalDC->isFunctionOrMethod());
3188
3189 LabelDecl *ToLabel;
3190 if (D->isGnuLocal()) {
3191 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3192 if (!BeginLocOrErr)
3193 return BeginLocOrErr.takeError();
3194 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3195 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3196 return ToLabel;
3197
3198 } else {
3199 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3200 Name.getAsIdentifierInfo()))
3201 return ToLabel;
3202
3203 }
3204
3205 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3206 if (!ToStmtOrErr)
3207 return ToStmtOrErr.takeError();
3208
3209 ToLabel->setStmt(*ToStmtOrErr);
3210 ToLabel->setLexicalDeclContext(LexicalDC);
3211 LexicalDC->addDeclInternal(ToLabel);
3212 return ToLabel;
3213}
3214
3216 // Import the major distinguishing characteristics of this enum.
3217 DeclContext *DC, *LexicalDC;
3218 DeclarationName Name;
3219 SourceLocation Loc;
3220 NamedDecl *ToD;
3221 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3222 return std::move(Err);
3223 if (ToD)
3224 return ToD;
3225
3226 // Figure out what enum name we're looking for.
3227 unsigned IDNS = Decl::IDNS_Tag;
3228 DeclarationName SearchName = Name;
3229 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3230 if (Error Err = importInto(
3231 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3232 return std::move(Err);
3233 IDNS = Decl::IDNS_Ordinary;
3234 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3235 IDNS |= Decl::IDNS_Ordinary;
3236
3237 // We may already have an enum of the same name; try to find and match it.
3238 EnumDecl *PrevDecl = nullptr;
3239 if (!DC->isFunctionOrMethod()) {
3240 SmallVector<NamedDecl *, 4> ConflictingDecls;
3241 auto FoundDecls =
3242 Importer.findDeclsInToCtx(DC, SearchName);
3243 for (auto *FoundDecl : FoundDecls) {
3244 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3245 continue;
3246
3247 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3248 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3249 FoundDecl = Tag->getDecl();
3250 }
3251
3252 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3253 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3254 continue;
3255 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3256 EnumDecl *FoundDef = FoundEnum->getDefinition();
3257 if (D->isThisDeclarationADefinition() && FoundDef)
3258 return Importer.MapImported(D, FoundDef);
3259 PrevDecl = FoundEnum->getMostRecentDecl();
3260 break;
3261 }
3262 ConflictingDecls.push_back(FoundDecl);
3263 }
3264 }
3265
3266 // In case of unnamed enums, we try to find an existing similar one, if none
3267 // was found, perform the import always.
3268 // Structural in-equivalence is not detected in this way here, but it may
3269 // be found when the parent decl is imported (if the enum is part of a
3270 // class). To make this totally exact a more difficult solution is needed.
3271 if (SearchName && !ConflictingDecls.empty()) {
3272 ExpectedName NameOrErr = Importer.HandleNameConflict(
3273 SearchName, DC, IDNS, ConflictingDecls.data(),
3274 ConflictingDecls.size());
3275 if (NameOrErr)
3276 Name = NameOrErr.get();
3277 else
3278 return NameOrErr.takeError();
3279 }
3280 }
3281
3282 Error Err = Error::success();
3283 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3284 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3285 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3286 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3287 if (Err)
3288 return std::move(Err);
3289
3290 // Create the enum declaration.
3291 EnumDecl *D2;
3292 if (GetImportedOrCreateDecl(
3293 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3294 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3295 D->isScopedUsingClassTag(), D->isFixed()))
3296 return D2;
3297
3298 D2->setQualifierInfo(ToQualifierLoc);
3299 D2->setIntegerType(ToIntegerType);
3300 D2->setBraceRange(ToBraceRange);
3301 D2->setAccess(D->getAccess());
3302 D2->setLexicalDeclContext(LexicalDC);
3303 addDeclToContexts(D, D2);
3304
3306 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3307 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3308 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3309 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3310 else
3311 return ToInstOrErr.takeError();
3312 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3314 else
3315 return POIOrErr.takeError();
3316 }
3317
3318 // Import the definition
3319 if (D->isCompleteDefinition())
3320 if (Error Err = ImportDefinition(D, D2))
3321 return std::move(Err);
3322
3323 return D2;
3324}
3325
3327 bool IsFriendTemplate = false;
3328 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3329 IsFriendTemplate =
3330 DCXX->getDescribedClassTemplate() &&
3331 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3333 }
3334
3335 // Import the major distinguishing characteristics of this record.
3336 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3337 DeclarationName Name;
3338 SourceLocation Loc;
3339 NamedDecl *ToD = nullptr;
3340 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3341 return std::move(Err);
3342 if (ToD)
3343 return ToD;
3344
3345 // Figure out what structure name we're looking for.
3346 unsigned IDNS = Decl::IDNS_Tag;
3347 DeclarationName SearchName = Name;
3348 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3349 if (Error Err = importInto(
3350 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3351 return std::move(Err);
3352 IDNS = Decl::IDNS_Ordinary;
3353 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3355
3356 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3357 : DC->isDependentContext();
3358 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3359
3360 // We may already have a record of the same name; try to find and match it.
3361 RecordDecl *PrevDecl = nullptr;
3362 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3363 SmallVector<NamedDecl *, 4> ConflictingDecls;
3364 auto FoundDecls =
3365 Importer.findDeclsInToCtx(DC, SearchName);
3366 if (!FoundDecls.empty()) {
3367 // We're going to have to compare D against potentially conflicting Decls,
3368 // so complete it.
3371 }
3372
3373 for (auto *FoundDecl : FoundDecls) {
3374 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3375 continue;
3376
3377 Decl *Found = FoundDecl;
3378 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3379 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3380 Found = Tag->getDecl();
3381 }
3382
3383 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3384 // Do not emit false positive diagnostic in case of unnamed
3385 // struct/union and in case of anonymous structs. Would be false
3386 // because there may be several anonymous/unnamed structs in a class.
3387 // E.g. these are both valid:
3388 // struct A { // unnamed structs
3389 // struct { struct A *next; } entry0;
3390 // struct { struct A *next; } entry1;
3391 // };
3392 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3393 if (!SearchName)
3394 if (!IsStructuralMatch(D, FoundRecord, false))
3395 continue;
3396
3397 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3398 continue;
3399
3400 if (IsStructuralMatch(D, FoundRecord)) {
3401 RecordDecl *FoundDef = FoundRecord->getDefinition();
3402 if (D->isThisDeclarationADefinition() && FoundDef) {
3403 // FIXME: Structural equivalence check should check for same
3404 // user-defined methods.
3405 Importer.MapImported(D, FoundDef);
3406 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3407 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3408 assert(FoundCXX && "Record type mismatch");
3409
3410 if (!Importer.isMinimalImport())
3411 // FoundDef may not have every implicit method that D has
3412 // because implicit methods are created only if they are used.
3413 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3414 return std::move(Err);
3415 }
3416 // FIXME: We can return FoundDef here.
3417 }
3418 PrevDecl = FoundRecord->getMostRecentDecl();
3419 break;
3420 }
3421 ConflictingDecls.push_back(FoundDecl);
3422 } // kind is RecordDecl
3423 } // for
3424
3425 if (!ConflictingDecls.empty() && SearchName) {
3426 ExpectedName NameOrErr = Importer.HandleNameConflict(
3427 SearchName, DC, IDNS, ConflictingDecls.data(),
3428 ConflictingDecls.size());
3429 if (NameOrErr)
3430 Name = NameOrErr.get();
3431 else
3432 return NameOrErr.takeError();
3433 }
3434 }
3435
3436 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3437 if (!BeginLocOrErr)
3438 return BeginLocOrErr.takeError();
3439
3440 // Create the record declaration.
3441 RecordDecl *D2 = nullptr;
3442 CXXRecordDecl *D2CXX = nullptr;
3443 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3444 if (DCXX->isLambda()) {
3445 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3446 if (!TInfoOrErr)
3447 return TInfoOrErr.takeError();
3448 if (GetImportedOrCreateSpecialDecl(
3449 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3450 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3451 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3452 return D2CXX;
3453 Decl *ContextDecl = DCXX->getLambdaContextDecl();
3454 ExpectedDecl CDeclOrErr = import(ContextDecl);
3455 if (!CDeclOrErr)
3456 return CDeclOrErr.takeError();
3457 if (ContextDecl != nullptr) {
3458 D2CXX->setLambdaContextDecl(*CDeclOrErr);
3459 }
3460 D2CXX->setLambdaNumbering(DCXX->getLambdaNumbering());
3461 } else {
3462 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3463 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3464 Name.getAsIdentifierInfo(),
3465 cast_or_null<CXXRecordDecl>(PrevDecl)))
3466 return D2CXX;
3467 }
3468
3469 D2 = D2CXX;
3470 D2->setAccess(D->getAccess());
3471 D2->setLexicalDeclContext(LexicalDC);
3472 addDeclToContexts(D, D2);
3473
3474 if (ClassTemplateDecl *FromDescribed =
3475 DCXX->getDescribedClassTemplate()) {
3476 ClassTemplateDecl *ToDescribed;
3477 if (Error Err = importInto(ToDescribed, FromDescribed))
3478 return std::move(Err);
3479 D2CXX->setDescribedClassTemplate(ToDescribed);
3480 } else if (MemberSpecializationInfo *MemberInfo =
3481 DCXX->getMemberSpecializationInfo()) {
3483 MemberInfo->getTemplateSpecializationKind();
3485
3486 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3487 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3488 else
3489 return ToInstOrErr.takeError();
3490
3491 if (ExpectedSLoc POIOrErr =
3492 import(MemberInfo->getPointOfInstantiation()))
3494 *POIOrErr);
3495 else
3496 return POIOrErr.takeError();
3497 }
3498
3499 } else {
3500 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3501 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3502 Name.getAsIdentifierInfo(), PrevDecl))
3503 return D2;
3504 D2->setLexicalDeclContext(LexicalDC);
3505 addDeclToContexts(D, D2);
3506 }
3507
3508 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3509 D2->setBraceRange(*BraceRangeOrErr);
3510 else
3511 return BraceRangeOrErr.takeError();
3512 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3513 D2->setQualifierInfo(*QualifierLocOrErr);
3514 else
3515 return QualifierLocOrErr.takeError();
3516
3517 if (D->isAnonymousStructOrUnion())
3518 D2->setAnonymousStructOrUnion(true);
3519
3520 if (D->isCompleteDefinition())
3521 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3522 return std::move(Err);
3523
3524 return D2;
3525}
3526
3528 // Import the major distinguishing characteristics of this enumerator.
3529 DeclContext *DC, *LexicalDC;
3530 DeclarationName Name;
3531 SourceLocation Loc;
3532 NamedDecl *ToD;
3533 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3534 return std::move(Err);
3535 if (ToD)
3536 return ToD;
3537
3538 // Determine whether there are any other declarations with the same name and
3539 // in the same context.
3540 if (!LexicalDC->isFunctionOrMethod()) {
3541 SmallVector<NamedDecl *, 4> ConflictingDecls;
3542 unsigned IDNS = Decl::IDNS_Ordinary;
3543 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3544 for (auto *FoundDecl : FoundDecls) {
3545 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3546 continue;
3547
3548 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3549 if (IsStructuralMatch(D, FoundEnumConstant))
3550 return Importer.MapImported(D, FoundEnumConstant);
3551 ConflictingDecls.push_back(FoundDecl);
3552 }
3553 }
3554
3555 if (!ConflictingDecls.empty()) {
3556 ExpectedName NameOrErr = Importer.HandleNameConflict(
3557 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3558 if (NameOrErr)
3559 Name = NameOrErr.get();
3560 else
3561 return NameOrErr.takeError();
3562 }
3563 }
3564
3565 ExpectedType TypeOrErr = import(D->getType());
3566 if (!TypeOrErr)
3567 return TypeOrErr.takeError();
3568
3569 ExpectedExpr InitOrErr = import(D->getInitExpr());
3570 if (!InitOrErr)
3571 return InitOrErr.takeError();
3572
3573 EnumConstantDecl *ToEnumerator;
3574 if (GetImportedOrCreateDecl(
3575 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3576 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3577 return ToEnumerator;
3578
3579 ToEnumerator->setAccess(D->getAccess());
3580 ToEnumerator->setLexicalDeclContext(LexicalDC);
3581 LexicalDC->addDeclInternal(ToEnumerator);
3582 return ToEnumerator;
3583}
3584
3585template <typename DeclTy>
3587 DeclTy *ToD) {
3589 FromD->getTemplateParameterLists();
3590 if (FromTPLs.empty())
3591 return Error::success();
3592 SmallVector<TemplateParameterList *, 2> ToTPLists(FromTPLs.size());
3593 for (unsigned int I = 0; I < FromTPLs.size(); ++I)
3594 if (Expected<TemplateParameterList *> ToTPListOrErr = import(FromTPLs[I]))
3595 ToTPLists[I] = *ToTPListOrErr;
3596 else
3597 return ToTPListOrErr.takeError();
3598 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3599 return Error::success();
3600}
3601
3603 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3604 switch (FromFD->getTemplatedKind()) {
3607 return Error::success();
3608
3610 if (Expected<FunctionDecl *> InstFDOrErr =
3611 import(FromFD->getInstantiatedFromDecl()))
3612 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3613 return Error::success();
3616
3617 if (Expected<FunctionDecl *> InstFDOrErr =
3618 import(FromFD->getInstantiatedFromMemberFunction()))
3619 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3620 else
3621 return InstFDOrErr.takeError();
3622
3623 if (ExpectedSLoc POIOrErr = import(
3626 else
3627 return POIOrErr.takeError();
3628
3629 return Error::success();
3630 }
3631
3633 auto FunctionAndArgsOrErr =
3635 if (!FunctionAndArgsOrErr)
3636 return FunctionAndArgsOrErr.takeError();
3637
3639 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3640
3641 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3642 TemplateArgumentListInfo ToTAInfo;
3643 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3644 if (FromTAArgsAsWritten)
3646 *FromTAArgsAsWritten, ToTAInfo))
3647 return Err;
3648
3649 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3650 if (!POIOrErr)
3651 return POIOrErr.takeError();
3652
3653 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3654 return Err;
3655
3656 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3657 ToFD->setFunctionTemplateSpecialization(
3658 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3659 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3660 return Error::success();
3661 }
3662
3664 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3665 UnresolvedSet<8> Candidates;
3666 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3667 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3668 Candidates.addDecl(*ToFTDOrErr);
3669 else
3670 return ToFTDOrErr.takeError();
3671 }
3672
3673 // Import TemplateArgumentListInfo.
3674 TemplateArgumentListInfo ToTAInfo;
3675 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3676 if (FromTAArgsAsWritten)
3677 if (Error Err =
3678 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3679 return Err;
3680
3682 Importer.getToContext(), Candidates,
3683 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3684 return Error::success();
3685 }
3686 }
3687 llvm_unreachable("All cases should be covered!");
3688}
3689
3692 auto FunctionAndArgsOrErr =
3694 if (!FunctionAndArgsOrErr)
3695 return FunctionAndArgsOrErr.takeError();
3696
3698 TemplateArgsTy ToTemplArgs;
3699 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3700 void *InsertPos = nullptr;
3701 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3702 return FoundSpec;
3703}
3704
3706 FunctionDecl *ToFD) {
3707 if (Stmt *FromBody = FromFD->getBody()) {
3708 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3709 ToFD->setBody(*ToBodyOrErr);
3710 else
3711 return ToBodyOrErr.takeError();
3712 }
3713 return Error::success();
3714}
3715
3716// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3717// which is equal to the given DC, or D is equal to DC.
3718static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3719 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3720 if (!DCi)
3721 DCi = D->getDeclContext();
3722 assert(DCi && "Declaration should have a context");
3723 while (DCi != D->getTranslationUnitDecl()) {
3724 if (DCi == DC)
3725 return true;
3726 DCi = DCi->getParent();
3727 }
3728 return false;
3729}
3730
3731// Check if there is a declaration that has 'DC' as parent context and is
3732// referenced from statement 'S' or one of its children. The search is done in
3733// BFS order through children of 'S'.
3734static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3735 SmallVector<const Stmt *> ToProcess;
3736 ToProcess.push_back(S);
3737 while (!ToProcess.empty()) {
3738 const Stmt *CurrentS = ToProcess.pop_back_val();
3739 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3740 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3741 if (const Decl *D = DeclRef->getDecl())
3742 if (isAncestorDeclContextOf(DC, D))
3743 return true;
3744 } else if (const auto *E =
3745 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3746 if (const Decl *D = E->getAssociatedDecl())
3747 if (isAncestorDeclContextOf(DC, D))
3748 return true;
3749 }
3750 }
3751 return false;
3752}
3753
3754namespace {
3755/// Check if a type has any reference to a declaration that is inside the body
3756/// of a function.
3757/// The \c CheckType(QualType) function should be used to determine
3758/// this property.
3759///
3760/// The type visitor visits one type object only (not recursive).
3761/// To find all referenced declarations we must discover all type objects until
3762/// the canonical type is reached (walk over typedef and similar objects). This
3763/// is done by loop over all "sugar" type objects. For every such type we must
3764/// check all declarations that are referenced from it. For this check the
3765/// visitor is used. In the visit functions all referenced declarations except
3766/// the one that follows in the sugar chain (if any) must be checked. For this
3767/// check the same visitor is re-used (it has no state-dependent data).
3768///
3769/// The visit functions have 3 possible return values:
3770/// - True, found a declaration inside \c ParentDC.
3771/// - False, found declarations only outside \c ParentDC and it is not possible
3772/// to find more declarations (the "sugar" chain does not continue).
3773/// - Empty optional value, found no declarations or only outside \c ParentDC,
3774/// but it is possible to find more declarations in the type "sugar" chain.
3775/// The loop over the "sugar" types can be implemented by using type visit
3776/// functions only (call \c CheckType with the desugared type). With the current
3777/// solution no visit function is needed if the type has only a desugared type
3778/// as data.
3779class IsTypeDeclaredInsideVisitor
3780 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3781public:
3782 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3783 : ParentDC(ParentDC) {}
3784
3785 bool CheckType(QualType T) {
3786 // Check the chain of "sugar" types.
3787 // The "sugar" types are typedef or similar types that have the same
3788 // canonical type.
3789 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3790 return *Res;
3791 QualType DsT =
3792 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3793 while (DsT != T) {
3794 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3795 return *Res;
3796 T = DsT;
3797 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3798 }
3799 return false;
3800 }
3801
3802 std::optional<bool> VisitTagType(const TagType *T) {
3803 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3804 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3805 if (checkTemplateArgument(Arg))
3806 return true;
3807 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3808 }
3809
3810 std::optional<bool> VisitPointerType(const PointerType *T) {
3811 return CheckType(T->getPointeeType());
3812 }
3813
3814 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3815 return CheckType(T->getPointeeTypeAsWritten());
3816 }
3817
3818 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3819 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3820 }
3821
3822 std::optional<bool> VisitUsingType(const UsingType *T) {
3823 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3824 }
3825
3826 std::optional<bool>
3827 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3828 for (const auto &Arg : T->template_arguments())
3829 if (checkTemplateArgument(Arg))
3830 return true;
3831 // This type is a "sugar" to a record type, it can have a desugared type.
3832 return {};
3833 }
3834
3835 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3836 return CheckType(T->getBaseType());
3837 }
3838
3839 std::optional<bool>
3840 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3841 // The "associated declaration" can be the same as ParentDC.
3842 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3843 return true;
3844 return {};
3845 }
3846
3847 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3848 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3849 return true;
3850
3851 return CheckType(T->getElementType());
3852 }
3853
3854 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3855 llvm_unreachable(
3856 "Variable array should not occur in deduced return type of a function");
3857 }
3858
3859 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3860 llvm_unreachable("Incomplete array should not occur in deduced return type "
3861 "of a function");
3862 }
3863
3864 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3865 llvm_unreachable("Dependent array should not occur in deduced return type "
3866 "of a function");
3867 }
3868
3869private:
3870 const DeclContext *const ParentDC;
3871
3872 bool checkTemplateArgument(const TemplateArgument &Arg) {
3873 switch (Arg.getKind()) {
3875 return false;
3877 return CheckType(Arg.getIntegralType());
3879 return CheckType(Arg.getAsType());
3881 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3883 // FIXME: The declaration in this case is not allowed to be in a function?
3884 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3886 // FIXME: The type is not allowed to be in the function?
3887 return CheckType(Arg.getNullPtrType());
3889 return CheckType(Arg.getStructuralValueType());
3891 for (const auto &PackArg : Arg.getPackAsArray())
3892 if (checkTemplateArgument(PackArg))
3893 return true;
3894 return false;
3896 // Templates can not be defined locally in functions.
3897 // A template passed as argument can be not in ParentDC.
3898 return false;
3900 // Templates can not be defined locally in functions.
3901 // A template passed as argument can be not in ParentDC.
3902 return false;
3903 }
3904 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3905 };
3906};
3907} // namespace
3908
3909/// This function checks if the given function has a return type that contains
3910/// a reference (in any way) to a declaration inside the same function.
3912 QualType FromTy = D->getType();
3913 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3914 assert(FromFPT && "Must be called on FunctionProtoType");
3915
3916 auto IsCXX11Lambda = [&]() {
3917 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3918 return false;
3919
3920 return isLambdaMethod(D);
3921 };
3922
3923 QualType RetT = FromFPT->getReturnType();
3924 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3925 FunctionDecl *Def = D->getDefinition();
3926 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3927 return Visitor.CheckType(RetT);
3928 }
3929
3930 return false;
3931}
3932
3934ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3935 Expr *ExplicitExpr = ESpec.getExpr();
3936 if (ExplicitExpr)
3937 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3938 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3939}
3940
3942
3944 auto RedeclIt = Redecls.begin();
3945 // Import the first part of the decl chain. I.e. import all previous
3946 // declarations starting from the canonical decl.
3947 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3948 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3949 if (!ToRedeclOrErr)
3950 return ToRedeclOrErr.takeError();
3951 }
3952 assert(*RedeclIt == D);
3953
3954 // Import the major distinguishing characteristics of this function.
3955 DeclContext *DC, *LexicalDC;
3956 DeclarationName Name;
3957 SourceLocation Loc;
3958 NamedDecl *ToD;
3959 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3960 return std::move(Err);
3961 if (ToD)
3962 return ToD;
3963
3964 FunctionDecl *FoundByLookup = nullptr;
3966
3967 // If this is a function template specialization, then try to find the same
3968 // existing specialization in the "to" context. The lookup below will not
3969 // find any specialization, but would find the primary template; thus, we
3970 // have to skip normal lookup in case of specializations.
3971 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3972 if (D->getTemplatedKind() ==
3974 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3975 if (!FoundFunctionOrErr)
3976 return FoundFunctionOrErr.takeError();
3977 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3978 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3979 return Def;
3980 FoundByLookup = FoundFunction;
3981 }
3982 }
3983 // Try to find a function in our own ("to") context with the same name, same
3984 // type, and in the same context as the function we're importing.
3985 else if (!LexicalDC->isFunctionOrMethod()) {
3986 SmallVector<NamedDecl *, 4> ConflictingDecls;
3988 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3989 for (auto *FoundDecl : FoundDecls) {
3990 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3991 continue;
3992
3993 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3994 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3995 continue;
3996
3997 if (IsStructuralMatch(D, FoundFunction)) {
3998 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3999 return Def;
4000 FoundByLookup = FoundFunction;
4001 break;
4002 }
4003 // FIXME: Check for overloading more carefully, e.g., by boosting
4004 // Sema::IsOverload out to the AST library.
4005
4006 // Function overloading is okay in C++.
4007 if (Importer.getToContext().getLangOpts().CPlusPlus)
4008 continue;
4009
4010 // Complain about inconsistent function types.
4011 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
4012 << Name << D->getType() << FoundFunction->getType();
4013 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
4014 << FoundFunction->getType();
4015 ConflictingDecls.push_back(FoundDecl);
4016 }
4017 }
4018
4019 if (!ConflictingDecls.empty()) {
4020 ExpectedName NameOrErr = Importer.HandleNameConflict(
4021 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4022 if (NameOrErr)
4023 Name = NameOrErr.get();
4024 else
4025 return NameOrErr.takeError();
4026 }
4027 }
4028
4029 // We do not allow more than one in-class declaration of a function. This is
4030 // because AST clients like VTableBuilder asserts on this. VTableBuilder
4031 // assumes there is only one in-class declaration. Building a redecl
4032 // chain would result in more than one in-class declaration for
4033 // overrides (even if they are part of the same redecl chain inside the
4034 // derived class.)
4035 if (FoundByLookup) {
4036 if (isa<CXXMethodDecl>(FoundByLookup)) {
4037 if (D->getLexicalDeclContext() == D->getDeclContext()) {
4038 if (!D->doesThisDeclarationHaveABody()) {
4039 if (FunctionTemplateDecl *DescribedD =
4041 // Handle a "templated" function together with its described
4042 // template. This avoids need for a similar check at import of the
4043 // described template.
4044 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4045 "Templated function mapped to non-templated?");
4046 Importer.MapImported(DescribedD,
4047 FoundByLookup->getDescribedFunctionTemplate());
4048 }
4049 return Importer.MapImported(D, FoundByLookup);
4050 } else {
4051 // Let's continue and build up the redecl chain in this case.
4052 // FIXME Merge the functions into one decl.
4053 }
4054 }
4055 }
4056 }
4057
4058 DeclarationNameInfo NameInfo(Name, Loc);
4059 // Import additional name location/type info.
4060 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4061 return std::move(Err);
4062
4063 QualType FromTy = D->getType();
4064 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4065 // Set to true if we do not import the type of the function as is. There are
4066 // cases when the original type would result in an infinite recursion during
4067 // the import. To avoid an infinite recursion when importing, we create the
4068 // FunctionDecl with a simplified function type and update it only after the
4069 // relevant AST nodes are already imported.
4070 // The type is related to TypeSourceInfo (it references the type), so we must
4071 // do the same with TypeSourceInfo.
4072 bool UsedDifferentProtoType = false;
4073 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4074 QualType FromReturnTy = FromFPT->getReturnType();
4075 // Functions with auto return type may define a struct inside their body
4076 // and the return type could refer to that struct.
4077 // E.g.: auto foo() { struct X{}; return X(); }
4078 // To avoid an infinite recursion when importing, create the FunctionDecl
4079 // with a simplified return type.
4080 // Reuse this approach for auto return types declared as typenames from
4081 // template params, tracked in FindFunctionDeclImportCycle.
4083 Importer.FindFunctionDeclImportCycle.isCycle(D)) {
4084 FromReturnTy = Importer.getFromContext().VoidTy;
4085 UsedDifferentProtoType = true;
4086 }
4087 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4088 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4089 // FunctionDecl that we are importing the FunctionProtoType for.
4090 // To avoid an infinite recursion when importing, create the FunctionDecl
4091 // with a simplified function type.
4092 if (FromEPI.ExceptionSpec.SourceDecl ||
4093 FromEPI.ExceptionSpec.SourceTemplate ||
4094 FromEPI.ExceptionSpec.NoexceptExpr) {
4096 FromEPI = DefaultEPI;
4097 UsedDifferentProtoType = true;
4098 }
4099 FromTy = Importer.getFromContext().getFunctionType(
4100 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4101 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4102 FromTy, D->getBeginLoc());
4103 }
4104
4105 Error Err = Error::success();
4106 auto ScopedReturnTypeDeclCycleDetector =
4107 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
4108 auto T = importChecked(Err, FromTy);
4109 auto TInfo = importChecked(Err, FromTSI);
4110 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4111 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4112 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4113 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4114 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4115 TrailingRequiresClause.ConstraintExpr =
4116 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4117 if (Err)
4118 return std::move(Err);
4119
4120 // Import the function parameters.
4122 for (auto *P : D->parameters()) {
4123 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4124 Parameters.push_back(*ToPOrErr);
4125 else
4126 return ToPOrErr.takeError();
4127 }
4128
4129 // Create the imported function.
4130 FunctionDecl *ToFunction = nullptr;
4131 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4132 ExplicitSpecifier ESpec =
4133 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4134 if (Err)
4135 return std::move(Err);
4136 auto ToInheritedConstructor = InheritedConstructor();
4137 if (FromConstructor->isInheritingConstructor()) {
4138 Expected<InheritedConstructor> ImportedInheritedCtor =
4139 import(FromConstructor->getInheritedConstructor());
4140 if (!ImportedInheritedCtor)
4141 return ImportedInheritedCtor.takeError();
4142 ToInheritedConstructor = *ImportedInheritedCtor;
4143 }
4144 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4145 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4146 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4148 ToInheritedConstructor, TrailingRequiresClause))
4149 return ToFunction;
4150 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4151
4152 Error Err = Error::success();
4153 auto ToOperatorDelete = importChecked(
4154 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4155 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4156 if (Err)
4157 return std::move(Err);
4158
4159 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4160 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4161 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4163 TrailingRequiresClause))
4164 return ToFunction;
4165
4166 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4167
4168 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4169 } else if (CXXConversionDecl *FromConversion =
4170 dyn_cast<CXXConversionDecl>(D)) {
4171 ExplicitSpecifier ESpec =
4172 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4173 if (Err)
4174 return std::move(Err);
4175 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4176 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4177 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4178 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4179 SourceLocation(), TrailingRequiresClause))
4180 return ToFunction;
4181 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4182 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4183 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4184 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4185 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4186 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4187 return ToFunction;
4188 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4189 ExplicitSpecifier ESpec =
4190 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4191 CXXConstructorDecl *Ctor =
4192 importChecked(Err, Guide->getCorrespondingConstructor());
4193 const CXXDeductionGuideDecl *SourceDG =
4194 importChecked(Err, Guide->getSourceDeductionGuide());
4195 if (Err)
4196 return std::move(Err);
4197 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4198 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4199 NameInfo, T, TInfo, ToEndLoc, Ctor,
4200 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4201 SourceDG, Guide->getSourceDeductionGuideKind()))
4202 return ToFunction;
4203 } else {
4204 if (GetImportedOrCreateDecl(
4205 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4206 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4208 D->getConstexprKind(), TrailingRequiresClause))
4209 return ToFunction;
4210 }
4211
4212 // Connect the redecl chain.
4213 if (FoundByLookup) {
4214 auto *Recent = const_cast<FunctionDecl *>(
4215 FoundByLookup->getMostRecentDecl());
4216 ToFunction->setPreviousDecl(Recent);
4217 // FIXME Probably we should merge exception specifications. E.g. In the
4218 // "To" context the existing function may have exception specification with
4219 // noexcept-unevaluated, while the newly imported function may have an
4220 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4221 // decl and its redeclarations may be required.
4222 }
4223
4224 StringLiteral *Msg = D->getDeletedMessage();
4225 if (Msg) {
4226 auto Imported = import(Msg);
4227 if (!Imported)
4228 return Imported.takeError();
4229 Msg = *Imported;
4230 }
4231
4232 ToFunction->setQualifierInfo(ToQualifierLoc);
4233 ToFunction->setAccess(D->getAccess());
4234 ToFunction->setLexicalDeclContext(LexicalDC);
4235 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4236 ToFunction->setTrivial(D->isTrivial());
4237 ToFunction->setIsPureVirtual(D->isPureVirtual());
4238 ToFunction->setDefaulted(D->isDefaulted());
4240 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4246 ToFunction->setRangeEnd(ToEndLoc);
4247 ToFunction->setDefaultLoc(ToDefaultLoc);
4248
4249 if (Msg)
4250 ToFunction->setDefaultedOrDeletedInfo(
4252 Importer.getToContext(), {}, Msg));
4253
4254 // Set the parameters.
4255 for (auto *Param : Parameters) {
4256 Param->setOwningFunction(ToFunction);
4257 ToFunction->addDeclInternal(Param);
4258 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4259 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4260 }
4261 ToFunction->setParams(Parameters);
4262
4263 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4264 // params it refers to.
4265 if (TInfo) {
4266 if (auto ProtoLoc =
4267 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4268 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4269 ProtoLoc.setParam(I, Parameters[I]);
4270 }
4271 }
4272
4273 // Import the describing template function, if any.
4274 if (FromFT) {
4275 auto ToFTOrErr = import(FromFT);
4276 if (!ToFTOrErr)
4277 return ToFTOrErr.takeError();
4278 }
4279
4280 // Import Ctor initializers.
4281 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4282 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4283 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4284 // Import first, then allocate memory and copy if there was no error.
4285 if (Error Err = ImportContainerChecked(
4286 FromConstructor->inits(), CtorInitializers))
4287 return std::move(Err);
4288 auto **Memory =
4289 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4290 llvm::copy(CtorInitializers, Memory);
4291 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4292 ToCtor->setCtorInitializers(Memory);
4293 ToCtor->setNumCtorInitializers(NumInitializers);
4294 }
4295 }
4296
4297 // If it is a template, import all related things.
4298 if (Error Err = ImportTemplateInformation(D, ToFunction))
4299 return std::move(Err);
4300
4301 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4303 FromCXXMethod))
4304 return std::move(Err);
4305
4307 Error Err = ImportFunctionDeclBody(D, ToFunction);
4308
4309 if (Err)
4310 return std::move(Err);
4311 }
4312
4313 // Import and set the original type in case we used another type.
4314 if (UsedDifferentProtoType) {
4315 if (ExpectedType TyOrErr = import(D->getType()))
4316 ToFunction->setType(*TyOrErr);
4317 else
4318 return TyOrErr.takeError();
4319 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4320 ToFunction->setTypeSourceInfo(*TSIOrErr);
4321 else
4322 return TSIOrErr.takeError();
4323 }
4324
4325 // FIXME: Other bits to merge?
4326
4327 addDeclToContexts(D, ToFunction);
4328
4329 // Import the rest of the chain. I.e. import all subsequent declarations.
4330 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4331 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4332 if (!ToRedeclOrErr)
4333 return ToRedeclOrErr.takeError();
4334 }
4335
4336 return ToFunction;
4337}
4338
4342
4346
4350
4354
4359
4361 // Import the major distinguishing characteristics of a variable.
4362 DeclContext *DC, *LexicalDC;
4363 DeclarationName Name;
4364 SourceLocation Loc;
4365 NamedDecl *ToD;
4366 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4367 return std::move(Err);
4368 if (ToD)
4369 return ToD;
4370
4371 // Determine whether we've already imported this field.
4372 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4373 for (auto *FoundDecl : FoundDecls) {
4374 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4375 // For anonymous fields, match up by index.
4376 if (!Name &&
4378 ASTImporter::getFieldIndex(FoundField))
4379 continue;
4380
4381 if (Importer.IsStructurallyEquivalent(D->getType(),
4382 FoundField->getType())) {
4383 Importer.MapImported(D, FoundField);
4384 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4385 // initializer of a FieldDecl might not had been instantiated in the
4386 // "To" context. However, the "From" context might instantiated that,
4387 // thus we have to merge that.
4388 // Note: `hasInClassInitializer()` is not the same as non-null
4389 // `getInClassInitializer()` value.
4390 if (Expr *FromInitializer = D->getInClassInitializer()) {
4391 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4392 // Import of the FromInitializer may result in the setting of
4393 // InClassInitializer. If not, set it here.
4394 assert(FoundField->hasInClassInitializer() &&
4395 "Field should have an in-class initializer if it has an "
4396 "expression for it.");
4397 if (!FoundField->getInClassInitializer())
4398 FoundField->setInClassInitializer(*ToInitializerOrErr);
4399 } else {
4400 return ToInitializerOrErr.takeError();
4401 }
4402 }
4403 return FoundField;
4404 }
4405
4406 // FIXME: Why is this case not handled with calling HandleNameConflict?
4407 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4408 << Name << D->getType() << FoundField->getType();
4409 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4410 << FoundField->getType();
4411
4412 return make_error<ASTImportError>(ASTImportError::NameConflict);
4413 }
4414 }
4415
4416 Error Err = Error::success();
4417 auto ToType = importChecked(Err, D->getType());
4418 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4419 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4420 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4421 if (Err)
4422 return std::move(Err);
4423 const Type *ToCapturedVLAType = nullptr;
4424 if (Error Err = Importer.importInto(
4425 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4426 return std::move(Err);
4427
4428 FieldDecl *ToField;
4429 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4430 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4431 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4432 D->getInClassInitStyle()))
4433 return ToField;
4434
4435 ToField->setAccess(D->getAccess());
4436 ToField->setLexicalDeclContext(LexicalDC);
4437 ToField->setImplicit(D->isImplicit());
4438 if (ToCapturedVLAType)
4439 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4440 LexicalDC->addDeclInternal(ToField);
4441 // Import initializer only after the field was created, it may have recursive
4442 // reference to the field.
4443 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4444 if (Err)
4445 return std::move(Err);
4446 if (ToInitializer) {
4447 auto *AlreadyImported = ToField->getInClassInitializer();
4448 if (AlreadyImported)
4449 assert(ToInitializer == AlreadyImported &&
4450 "Duplicate import of in-class initializer.");
4451 else
4452 ToField->setInClassInitializer(ToInitializer);
4453 }
4454
4455 return ToField;
4456}
4457
4459 // Import the major distinguishing characteristics of a variable.
4460 DeclContext *DC, *LexicalDC;
4461 DeclarationName Name;
4462 SourceLocation Loc;
4463 NamedDecl *ToD;
4464 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4465 return std::move(Err);
4466 if (ToD)
4467 return ToD;
4468
4469 // Determine whether we've already imported this field.
4470 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4471 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4472 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4473 // For anonymous indirect fields, match up by index.
4474 if (!Name &&
4476 ASTImporter::getFieldIndex(FoundField))
4477 continue;
4478
4479 if (Importer.IsStructurallyEquivalent(D->getType(),
4480 FoundField->getType(),
4481 !Name.isEmpty())) {
4482 Importer.MapImported(D, FoundField);
4483 return FoundField;
4484 }
4485
4486 // If there are more anonymous fields to check, continue.
4487 if (!Name && I < N-1)
4488 continue;
4489
4490 // FIXME: Why is this case not handled with calling HandleNameConflict?
4491 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4492 << Name << D->getType() << FoundField->getType();
4493 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4494 << FoundField->getType();
4495
4496 return make_error<ASTImportError>(ASTImportError::NameConflict);
4497 }
4498 }
4499
4500 // Import the type.
4501 auto TypeOrErr = import(D->getType());
4502 if (!TypeOrErr)
4503 return TypeOrErr.takeError();
4504
4505 auto **NamedChain =
4506 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4507
4508 unsigned i = 0;
4509 for (auto *PI : D->chain())
4510 if (Expected<NamedDecl *> ToD = import(PI))
4511 NamedChain[i++] = *ToD;
4512 else
4513 return ToD.takeError();
4514
4515 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4516 IndirectFieldDecl *ToIndirectField;
4517 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4518 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4519 // FIXME here we leak `NamedChain` which is allocated before
4520 return ToIndirectField;
4521
4522 ToIndirectField->setAccess(D->getAccess());
4523 ToIndirectField->setLexicalDeclContext(LexicalDC);
4524 LexicalDC->addDeclInternal(ToIndirectField);
4525 return ToIndirectField;
4526}
4527
4528/// Used as return type of getFriendCountAndPosition.
4530 /// Number of similar looking friends.
4531 unsigned int TotalCount;
4532 /// Index of the specific FriendDecl.
4533 unsigned int IndexOfDecl;
4534};
4535
4536static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4537 FriendDecl *FD2) {
4538 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4539 return false;
4540
4541 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4542 return Importer.IsStructurallyEquivalent(
4543 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4544
4545 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4547 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4548 FD2->getASTContext(), NonEquivalentDecls,
4550 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4551 return Ctx.IsEquivalent(FD1, FD2);
4552}
4553
4555 FriendDecl *FD) {
4556 unsigned int FriendCount = 0;
4557 UnsignedOrNone FriendPosition = std::nullopt;
4558 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4559
4560 for (FriendDecl *FoundFriend : RD->friends()) {
4561 if (FoundFriend == FD) {
4562 FriendPosition = FriendCount;
4563 ++FriendCount;
4564 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4565 ++FriendCount;
4566 }
4567 }
4568
4569 assert(FriendPosition && "Friend decl not found in own parent.");
4570
4571 return {FriendCount, *FriendPosition};
4572}
4573
4575 // Import the major distinguishing characteristics of a declaration.
4576 DeclContext *DC, *LexicalDC;
4577 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4578 return std::move(Err);
4579
4580 // Determine whether we've already imported this decl.
4581 // FriendDecl is not a NamedDecl so we cannot use lookup.
4582 // We try to maintain order and count of redundant friend declarations.
4583 const auto *RD = cast<CXXRecordDecl>(DC);
4584 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4585 for (FriendDecl *ImportedFriend : RD->friends())
4586 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4587 ImportedEquivalentFriends.push_back(ImportedFriend);
4588
4589 FriendCountAndPosition CountAndPosition =
4590 getFriendCountAndPosition(Importer, D);
4591
4592 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4593 "Class with non-matching friends is imported, ODR check wrong?");
4594 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4595 return Importer.MapImported(
4596 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4597
4598 // Not found. Create it.
4599 // The declarations will be put into order later by ImportDeclContext.
4601 if (NamedDecl *FriendD = D->getFriendDecl()) {
4602 NamedDecl *ToFriendD;
4603 if (Error Err = importInto(ToFriendD, FriendD))
4604 return std::move(Err);
4605
4606 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4607 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4608 ToFriendD->setObjectOfFriendDecl(false);
4609
4610 ToFU = ToFriendD;
4611 } else { // The friend is a type, not a decl.
4612 if (auto TSIOrErr = import(D->getFriendType()))
4613 ToFU = *TSIOrErr;
4614 else
4615 return TSIOrErr.takeError();
4616 }
4617
4618 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4619 auto **FromTPLists = D->getTrailingObjects();
4620 for (unsigned I = 0; I < D->NumTPLists; I++) {
4621 if (auto ListOrErr = import(FromTPLists[I]))
4622 ToTPLists[I] = *ListOrErr;
4623 else
4624 return ListOrErr.takeError();
4625 }
4626
4627 auto LocationOrErr = import(D->getLocation());
4628 if (!LocationOrErr)
4629 return LocationOrErr.takeError();
4630 auto FriendLocOrErr = import(D->getFriendLoc());
4631 if (!FriendLocOrErr)
4632 return FriendLocOrErr.takeError();
4633 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4634 if (!EllipsisLocOrErr)
4635 return EllipsisLocOrErr.takeError();
4636
4637 FriendDecl *FrD;
4638 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4639 *LocationOrErr, ToFU, *FriendLocOrErr,
4640 *EllipsisLocOrErr, ToTPLists))
4641 return FrD;
4642
4643 FrD->setAccess(D->getAccess());
4644 FrD->setLexicalDeclContext(LexicalDC);
4645 LexicalDC->addDeclInternal(FrD);
4646 return FrD;
4647}
4648
4650 // Import the major distinguishing characteristics of an ivar.
4651 DeclContext *DC, *LexicalDC;
4652 DeclarationName Name;
4653 SourceLocation Loc;
4654 NamedDecl *ToD;
4655 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4656 return std::move(Err);
4657 if (ToD)
4658 return ToD;
4659
4660 // Determine whether we've already imported this ivar
4661 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4662 for (auto *FoundDecl : FoundDecls) {
4663 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4664 if (Importer.IsStructurallyEquivalent(D->getType(),
4665 FoundIvar->getType())) {
4666 Importer.MapImported(D, FoundIvar);
4667 return FoundIvar;
4668 }
4669
4670 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4671 << Name << D->getType() << FoundIvar->getType();
4672 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4673 << FoundIvar->getType();
4674
4675 return make_error<ASTImportError>(ASTImportError::NameConflict);
4676 }
4677 }
4678
4679 Error Err = Error::success();
4680 auto ToType = importChecked(Err, D->getType());
4681 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4682 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4683 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4684 if (Err)
4685 return std::move(Err);
4686
4687 ObjCIvarDecl *ToIvar;
4688 if (GetImportedOrCreateDecl(
4689 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4690 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4691 ToType, ToTypeSourceInfo,
4692 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4693 return ToIvar;
4694
4695 ToIvar->setLexicalDeclContext(LexicalDC);
4696 LexicalDC->addDeclInternal(ToIvar);
4697 return ToIvar;
4698}
4699
4701
4703 auto RedeclIt = Redecls.begin();
4704 // Import the first part of the decl chain. I.e. import all previous
4705 // declarations starting from the canonical decl.
4706 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4707 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4708 if (!RedeclOrErr)
4709 return RedeclOrErr.takeError();
4710 }
4711 assert(*RedeclIt == D);
4712
4713 // Import the major distinguishing characteristics of a variable.
4714 DeclContext *DC, *LexicalDC;
4715 DeclarationName Name;
4716 SourceLocation Loc;
4717 NamedDecl *ToD;
4718 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4719 return std::move(Err);
4720 if (ToD)
4721 return ToD;
4722
4723 // Try to find a variable in our own ("to") context with the same name and
4724 // in the same context as the variable we're importing.
4725 VarDecl *FoundByLookup = nullptr;
4726 if (D->isFileVarDecl()) {
4727 SmallVector<NamedDecl *, 4> ConflictingDecls;
4728 unsigned IDNS = Decl::IDNS_Ordinary;
4729 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4730 for (auto *FoundDecl : FoundDecls) {
4731 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4732 continue;
4733
4734 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4735 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4736 continue;
4737 if (Importer.IsStructurallyEquivalent(D->getType(),
4738 FoundVar->getType())) {
4739
4740 // The VarDecl in the "From" context has a definition, but in the
4741 // "To" context we already have a definition.
4742 VarDecl *FoundDef = FoundVar->getDefinition();
4743 if (D->isThisDeclarationADefinition() && FoundDef)
4744 // FIXME Check for ODR error if the two definitions have
4745 // different initializers?
4746 return Importer.MapImported(D, FoundDef);
4747
4748 // The VarDecl in the "From" context has an initializer, but in the
4749 // "To" context we already have an initializer.
4750 const VarDecl *FoundDInit = nullptr;
4751 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4752 // FIXME Diagnose ODR error if the two initializers are different?
4753 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4754
4755 FoundByLookup = FoundVar;
4756 break;
4757 }
4758
4759 const ArrayType *FoundArray
4760 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4761 const ArrayType *TArray
4762 = Importer.getToContext().getAsArrayType(D->getType());
4763 if (FoundArray && TArray) {
4764 if (isa<IncompleteArrayType>(FoundArray) &&
4765 isa<ConstantArrayType>(TArray)) {
4766 // Import the type.
4767 if (auto TyOrErr = import(D->getType()))
4768 FoundVar->setType(*TyOrErr);
4769 else
4770 return TyOrErr.takeError();
4771
4772 FoundByLookup = FoundVar;
4773 break;
4774 } else if (isa<IncompleteArrayType>(TArray) &&
4775 isa<ConstantArrayType>(FoundArray)) {
4776 FoundByLookup = FoundVar;
4777 break;
4778 }
4779 }
4780
4781 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4782 << Name << D->getType() << FoundVar->getType();
4783 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4784 << FoundVar->getType();
4785 ConflictingDecls.push_back(FoundDecl);
4786 }
4787 }
4788
4789 if (!ConflictingDecls.empty()) {
4790 ExpectedName NameOrErr = Importer.HandleNameConflict(
4791 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4792 if (NameOrErr)
4793 Name = NameOrErr.get();
4794 else
4795 return NameOrErr.takeError();
4796 }
4797 }
4798
4799 Error Err = Error::success();
4800 auto ToType = importChecked(Err, D->getType());
4801 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4802 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4803 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4804 if (Err)
4805 return std::move(Err);
4806
4807 VarDecl *ToVar;
4808 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4809 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4810 if (Error Err =
4811 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4812 return std::move(Err);
4813 DecompositionDecl *ToDecomp;
4814 if (GetImportedOrCreateDecl(
4815 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4816 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4817 return ToDecomp;
4818 ToVar = ToDecomp;
4819 } else {
4820 // Create the imported variable.
4821 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4822 ToInnerLocStart, Loc,
4823 Name.getAsIdentifierInfo(), ToType,
4824 ToTypeSourceInfo, D->getStorageClass()))
4825 return ToVar;
4826 }
4827
4828 ToVar->setTSCSpec(D->getTSCSpec());
4829 ToVar->setQualifierInfo(ToQualifierLoc);
4830 ToVar->setAccess(D->getAccess());
4831 ToVar->setLexicalDeclContext(LexicalDC);
4832 if (D->isInlineSpecified())
4833 ToVar->setInlineSpecified();
4834 if (D->isInline())
4835 ToVar->setImplicitlyInline();
4836
4837 if (FoundByLookup) {
4838 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4839 ToVar->setPreviousDecl(Recent);
4840 }
4841
4842 // Import the described template, if any.
4843 if (D->getDescribedVarTemplate()) {
4844 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4845 if (!ToVTOrErr)
4846 return ToVTOrErr.takeError();
4848 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4850 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4851 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4852 else
4853 return ToInstOrErr.takeError();
4854 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4856 else
4857 return POIOrErr.takeError();
4858 }
4859
4860 if (Error Err = ImportInitializer(D, ToVar))
4861 return std::move(Err);
4862
4863 if (D->isConstexpr())
4864 ToVar->setConstexpr(true);
4865
4866 addDeclToContexts(D, ToVar);
4867
4868 // Import the rest of the chain. I.e. import all subsequent declarations.
4869 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4870 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4871 if (!RedeclOrErr)
4872 return RedeclOrErr.takeError();
4873 }
4874
4875 return ToVar;
4876}
4877
4879 // Parameters are created in the translation unit's context, then moved
4880 // into the function declaration's context afterward.
4881 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4882
4883 Error Err = Error::success();
4884 auto ToDeclName = importChecked(Err, D->getDeclName());
4885 auto ToLocation = importChecked(Err, D->getLocation());
4886 auto ToType = importChecked(Err, D->getType());
4887 if (Err)
4888 return std::move(Err);
4889
4890 // Create the imported parameter.
4891 ImplicitParamDecl *ToParm = nullptr;
4892 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4893 ToLocation, ToDeclName.getAsIdentifierInfo(),
4894 ToType, D->getParameterKind()))
4895 return ToParm;
4896 return ToParm;
4897}
4898
4900 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4901
4902 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4903 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4904 else
4905 return LocOrErr.takeError();
4906
4908 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4909
4910 if (FromParam->hasUninstantiatedDefaultArg()) {
4911 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4912 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4913 else
4914 return ToDefArgOrErr.takeError();
4915 } else if (FromParam->hasUnparsedDefaultArg()) {
4916 ToParam->setUnparsedDefaultArg();
4917 } else if (FromParam->hasDefaultArg()) {
4918 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4919 ToParam->setDefaultArg(*ToDefArgOrErr);
4920 else
4921 return ToDefArgOrErr.takeError();
4922 }
4923
4924 return Error::success();
4925}
4926
4929 Error Err = Error::success();
4930 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4931 ConstructorUsingShadowDecl *ToShadow =
4932 importChecked(Err, From.getShadowDecl());
4933 if (Err)
4934 return std::move(Err);
4935 return InheritedConstructor(ToShadow, ToBaseCtor);
4936}
4937
4939 // Parameters are created in the translation unit's context, then moved
4940 // into the function declaration's context afterward.
4941 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4942
4943 Error Err = Error::success();
4944 auto ToDeclName = importChecked(Err, D->getDeclName());
4945 auto ToLocation = importChecked(Err, D->getLocation());
4946 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4947 auto ToType = importChecked(Err, D->getType());
4948 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4949 if (Err)
4950 return std::move(Err);
4951
4952 ParmVarDecl *ToParm;
4953 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4954 ToInnerLocStart, ToLocation,
4955 ToDeclName.getAsIdentifierInfo(), ToType,
4956 ToTypeSourceInfo, D->getStorageClass(),
4957 /*DefaultArg*/ nullptr))
4958 return ToParm;
4959
4960 // Set the default argument. It should be no problem if it was already done.
4961 // Do not import the default expression before GetImportedOrCreateDecl call
4962 // to avoid possible infinite import loop because circular dependency.
4963 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4964 return std::move(Err);
4965
4966 if (D->isObjCMethodParameter()) {
4969 } else {
4972 }
4973
4974 return ToParm;
4975}
4976
4978 // Import the major distinguishing characteristics of a method.
4979 DeclContext *DC, *LexicalDC;
4980 DeclarationName Name;
4981 SourceLocation Loc;
4982 NamedDecl *ToD;
4983 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4984 return std::move(Err);
4985 if (ToD)
4986 return ToD;
4987
4988 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4989 for (auto *FoundDecl : FoundDecls) {
4990 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4991 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4992 continue;
4993
4994 // Check return types.
4995 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4996 FoundMethod->getReturnType())) {
4997 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4998 << D->isInstanceMethod() << Name << D->getReturnType()
4999 << FoundMethod->getReturnType();
5000 Importer.ToDiag(FoundMethod->getLocation(),
5001 diag::note_odr_objc_method_here)
5002 << D->isInstanceMethod() << Name;
5003
5004 return make_error<ASTImportError>(ASTImportError::NameConflict);
5005 }
5006
5007 // Check the number of parameters.
5008 if (D->param_size() != FoundMethod->param_size()) {
5009 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
5010 << D->isInstanceMethod() << Name
5011 << D->param_size() << FoundMethod->param_size();
5012 Importer.ToDiag(FoundMethod->getLocation(),
5013 diag::note_odr_objc_method_here)
5014 << D->isInstanceMethod() << Name;
5015
5016 return make_error<ASTImportError>(ASTImportError::NameConflict);
5017 }
5018
5019 // Check parameter types.
5021 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
5022 P != PEnd; ++P, ++FoundP) {
5023 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
5024 (*FoundP)->getType())) {
5025 Importer.FromDiag((*P)->getLocation(),
5026 diag::warn_odr_objc_method_param_type_inconsistent)
5027 << D->isInstanceMethod() << Name
5028 << (*P)->getType() << (*FoundP)->getType();
5029 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
5030 << (*FoundP)->getType();
5031
5032 return make_error<ASTImportError>(ASTImportError::NameConflict);
5033 }
5034 }
5035
5036 // Check variadic/non-variadic.
5037 // Check the number of parameters.
5038 if (D->isVariadic() != FoundMethod->isVariadic()) {
5039 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
5040 << D->isInstanceMethod() << Name;
5041 Importer.ToDiag(FoundMethod->getLocation(),
5042 diag::note_odr_objc_method_here)
5043 << D->isInstanceMethod() << Name;
5044
5045 return make_error<ASTImportError>(ASTImportError::NameConflict);
5046 }
5047
5048 // FIXME: Any other bits we need to merge?
5049 return Importer.MapImported(D, FoundMethod);
5050 }
5051 }
5052
5053 Error Err = Error::success();
5054 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5055 auto ToReturnType = importChecked(Err, D->getReturnType());
5056 auto ToReturnTypeSourceInfo =
5058 if (Err)
5059 return std::move(Err);
5060
5061 ObjCMethodDecl *ToMethod;
5062 if (GetImportedOrCreateDecl(
5063 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5064 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5068 return ToMethod;
5069
5070 // FIXME: When we decide to merge method definitions, we'll need to
5071 // deal with implicit parameters.
5072
5073 // Import the parameters
5075 for (auto *FromP : D->parameters()) {
5076 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5077 ToParams.push_back(*ToPOrErr);
5078 else
5079 return ToPOrErr.takeError();
5080 }
5081
5082 // Set the parameters.
5083 for (auto *ToParam : ToParams) {
5084 ToParam->setOwningFunction(ToMethod);
5085 ToMethod->addDeclInternal(ToParam);
5086 }
5087
5089 D->getSelectorLocs(FromSelLocs);
5090 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5091 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5092 return std::move(Err);
5093
5094 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5095
5096 ToMethod->setLexicalDeclContext(LexicalDC);
5097 LexicalDC->addDeclInternal(ToMethod);
5098
5099 // Implicit params are declared when Sema encounters the definition but this
5100 // never happens when the method is imported. Manually declare the implicit
5101 // params now that the MethodDecl knows its class interface.
5102 if (D->getSelfDecl())
5103 ToMethod->createImplicitParams(Importer.getToContext(),
5104 ToMethod->getClassInterface());
5105
5106 return ToMethod;
5107}
5108
5110 // Import the major distinguishing characteristics of a category.
5111 DeclContext *DC, *LexicalDC;
5112 DeclarationName Name;
5113 SourceLocation Loc;
5114 NamedDecl *ToD;
5115 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5116 return std::move(Err);
5117 if (ToD)
5118 return ToD;
5119
5120 Error Err = Error::success();
5121 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5122 auto ToLocation = importChecked(Err, D->getLocation());
5123 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5124 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5125 if (Err)
5126 return std::move(Err);
5127
5129 if (GetImportedOrCreateDecl(
5130 Result, D, Importer.getToContext(), DC, D->getVariance(),
5131 ToVarianceLoc, D->getIndex(),
5132 ToLocation, Name.getAsIdentifierInfo(),
5133 ToColonLoc, ToTypeSourceInfo))
5134 return Result;
5135
5136 // Only import 'ObjCTypeParamType' after the decl is created.
5137 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5138 if (Err)
5139 return std::move(Err);
5140 Result->setTypeForDecl(ToTypeForDecl);
5141 Result->setLexicalDeclContext(LexicalDC);
5142 return Result;
5143}
5144
5146 // Import the major distinguishing characteristics of a category.
5147 DeclContext *DC, *LexicalDC;
5148 DeclarationName Name;
5149 SourceLocation Loc;
5150 NamedDecl *ToD;
5151 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5152 return std::move(Err);
5153 if (ToD)
5154 return ToD;
5155
5156 ObjCInterfaceDecl *ToInterface;
5157 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5158 return std::move(Err);
5159
5160 // Determine if we've already encountered this category.
5161 ObjCCategoryDecl *MergeWithCategory
5162 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5163 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5164 if (!ToCategory) {
5165
5166 Error Err = Error::success();
5167 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5168 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5169 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5170 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5171 if (Err)
5172 return std::move(Err);
5173
5174 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5175 ToAtStartLoc, Loc,
5176 ToCategoryNameLoc,
5177 Name.getAsIdentifierInfo(), ToInterface,
5178 /*TypeParamList=*/nullptr,
5179 ToIvarLBraceLoc,
5180 ToIvarRBraceLoc))
5181 return ToCategory;
5182
5183 ToCategory->setLexicalDeclContext(LexicalDC);
5184 LexicalDC->addDeclInternal(ToCategory);
5185 // Import the type parameter list after MapImported, to avoid
5186 // loops when bringing in their DeclContext.
5187 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5188 ToCategory->setTypeParamList(*PListOrErr);
5189 else
5190 return PListOrErr.takeError();
5191
5192 // Import protocols
5194 SmallVector<SourceLocation, 4> ProtocolLocs;
5196 = D->protocol_loc_begin();
5198 FromProtoEnd = D->protocol_end();
5199 FromProto != FromProtoEnd;
5200 ++FromProto, ++FromProtoLoc) {
5201 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5202 Protocols.push_back(*ToProtoOrErr);
5203 else
5204 return ToProtoOrErr.takeError();
5205
5206 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5207 ProtocolLocs.push_back(*ToProtoLocOrErr);
5208 else
5209 return ToProtoLocOrErr.takeError();
5210 }
5211
5212 // FIXME: If we're merging, make sure that the protocol list is the same.
5213 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5214 ProtocolLocs.data(), Importer.getToContext());
5215
5216 } else {
5217 Importer.MapImported(D, ToCategory);
5218 }
5219
5220 // Import all of the members of this category.
5221 if (Error Err = ImportDeclContext(D))
5222 return std::move(Err);
5223
5224 // If we have an implementation, import it as well.
5225 if (D->getImplementation()) {
5226 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5227 import(D->getImplementation()))
5228 ToCategory->setImplementation(*ToImplOrErr);
5229 else
5230 return ToImplOrErr.takeError();
5231 }
5232
5233 return ToCategory;
5234}
5235
5238 if (To->getDefinition()) {
5240 if (Error Err = ImportDeclContext(From))
5241 return Err;
5242 return Error::success();
5243 }
5244
5245 // Start the protocol definition
5246 To->startDefinition();
5247
5248 // Import protocols
5250 SmallVector<SourceLocation, 4> ProtocolLocs;
5252 From->protocol_loc_begin();
5253 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5254 FromProtoEnd = From->protocol_end();
5255 FromProto != FromProtoEnd;
5256 ++FromProto, ++FromProtoLoc) {
5257 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5258 Protocols.push_back(*ToProtoOrErr);
5259 else
5260 return ToProtoOrErr.takeError();
5261
5262 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5263 ProtocolLocs.push_back(*ToProtoLocOrErr);
5264 else
5265 return ToProtoLocOrErr.takeError();
5266
5267 }
5268
5269 // FIXME: If we're merging, make sure that the protocol list is the same.
5270 To->setProtocolList(Protocols.data(), Protocols.size(),
5271 ProtocolLocs.data(), Importer.getToContext());
5272
5273 if (shouldForceImportDeclContext(Kind)) {
5274 // Import all of the members of this protocol.
5275 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5276 return Err;
5277 }
5278 return Error::success();
5279}
5280
5282 // If this protocol has a definition in the translation unit we're coming
5283 // from, but this particular declaration is not that definition, import the
5284 // definition and map to that.
5286 if (Definition && Definition != D) {
5287 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5288 return Importer.MapImported(D, *ImportedDefOrErr);
5289 else
5290 return ImportedDefOrErr.takeError();
5291 }
5292
5293 // Import the major distinguishing characteristics of a protocol.
5294 DeclContext *DC, *LexicalDC;
5295 DeclarationName Name;
5296 SourceLocation Loc;
5297 NamedDecl *ToD;
5298 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5299 return std::move(Err);
5300 if (ToD)
5301 return ToD;
5302
5303 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5304 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5305 for (auto *FoundDecl : FoundDecls) {
5306 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5307 continue;
5308
5309 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5310 break;
5311 }
5312
5313 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5314 if (!ToProto) {
5315 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5316 if (!ToAtBeginLocOrErr)
5317 return ToAtBeginLocOrErr.takeError();
5318
5319 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5320 Name.getAsIdentifierInfo(), Loc,
5321 *ToAtBeginLocOrErr,
5322 /*PrevDecl=*/nullptr))
5323 return ToProto;
5324 ToProto->setLexicalDeclContext(LexicalDC);
5325 LexicalDC->addDeclInternal(ToProto);
5326 }
5327
5328 Importer.MapImported(D, ToProto);
5329
5331 if (Error Err = ImportDefinition(D, ToProto))
5332 return std::move(Err);
5333
5334 return ToProto;
5335}
5336
5338 DeclContext *DC, *LexicalDC;
5339 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5340 return std::move(Err);
5341
5342 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5343 if (!ExternLocOrErr)
5344 return ExternLocOrErr.takeError();
5345
5346 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5347 if (!LangLocOrErr)
5348 return LangLocOrErr.takeError();
5349
5350 bool HasBraces = D->hasBraces();
5351
5352 LinkageSpecDecl *ToLinkageSpec;
5353 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5354 *ExternLocOrErr, *LangLocOrErr,
5355 D->getLanguage(), HasBraces))
5356 return ToLinkageSpec;
5357
5358 if (HasBraces) {
5359 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5360 if (!RBraceLocOrErr)
5361 return RBraceLocOrErr.takeError();
5362 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5363 }
5364
5365 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5366 LexicalDC->addDeclInternal(ToLinkageSpec);
5367
5368 return ToLinkageSpec;
5369}
5370
5372 BaseUsingDecl *ToSI) {
5373 for (UsingShadowDecl *FromShadow : D->shadows()) {
5374 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5375 ToSI->addShadowDecl(*ToShadowOrErr);
5376 else
5377 // FIXME: We return error here but the definition is already created
5378 // and available with lookups. How to fix this?..
5379 return ToShadowOrErr.takeError();
5380 }
5381 return ToSI;
5382}
5383
5385 DeclContext *DC, *LexicalDC;
5386 DeclarationName Name;
5387 SourceLocation Loc;
5388 NamedDecl *ToD = nullptr;
5389 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5390 return std::move(Err);
5391 if (ToD)
5392 return ToD;
5393
5394 Error Err = Error::success();
5395 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5396 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5397 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5398 if (Err)
5399 return std::move(Err);
5400
5401 DeclarationNameInfo NameInfo(Name, ToLoc);
5402 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5403 return std::move(Err);
5404
5405 UsingDecl *ToUsing;
5406 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5407 ToUsingLoc, ToQualifierLoc, NameInfo,
5408 D->hasTypename()))
5409 return ToUsing;
5410
5411 ToUsing->setLexicalDeclContext(LexicalDC);
5412 LexicalDC->addDeclInternal(ToUsing);
5413
5414 if (NamedDecl *FromPattern =
5415 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5416 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5417 Importer.getToContext().setInstantiatedFromUsingDecl(
5418 ToUsing, *ToPatternOrErr);
5419 else
5420 return ToPatternOrErr.takeError();
5421 }
5422
5423 return ImportUsingShadowDecls(D, ToUsing);
5424}
5425
5427 DeclContext *DC, *LexicalDC;
5428 DeclarationName Name;
5429 SourceLocation Loc;
5430 NamedDecl *ToD = nullptr;
5431 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5432 return std::move(Err);
5433 if (ToD)
5434 return ToD;
5435
5436 Error Err = Error::success();
5437 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5438 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5439 auto ToNameLoc = importChecked(Err, D->getLocation());
5440 auto *ToEnumType = importChecked(Err, D->getEnumType());
5441 if (Err)
5442 return std::move(Err);
5443
5444 UsingEnumDecl *ToUsingEnum;
5445 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5446 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5447 return ToUsingEnum;
5448
5449 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5450 LexicalDC->addDeclInternal(ToUsingEnum);
5451
5452 if (UsingEnumDecl *FromPattern =
5453 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5454 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5455 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5456 *ToPatternOrErr);
5457 else
5458 return ToPatternOrErr.takeError();
5459 }
5460
5461 return ImportUsingShadowDecls(D, ToUsingEnum);
5462}
5463
5465 DeclContext *DC, *LexicalDC;
5466 DeclarationName Name;
5467 SourceLocation Loc;
5468 NamedDecl *ToD = nullptr;
5469 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5470 return std::move(Err);
5471 if (ToD)
5472 return ToD;
5473
5474 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5475 if (!ToIntroducerOrErr)
5476 return ToIntroducerOrErr.takeError();
5477
5478 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5479 if (!ToTargetOrErr)
5480 return ToTargetOrErr.takeError();
5481
5482 UsingShadowDecl *ToShadow;
5483 if (auto *FromConstructorUsingShadow =
5484 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5485 Error Err = Error::success();
5487 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5488 if (Err)
5489 return std::move(Err);
5490 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5491 // is really the "NominatedBaseClassShadowDecl" value if it exists
5492 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5493 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5494 // get the correct values.
5495 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5496 ToShadow, D, Importer.getToContext(), DC, Loc,
5497 cast<UsingDecl>(*ToIntroducerOrErr),
5498 Nominated ? Nominated : *ToTargetOrErr,
5499 FromConstructorUsingShadow->constructsVirtualBase()))
5500 return ToShadow;
5501 } else {
5502 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5503 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5504 return ToShadow;
5505 }
5506
5507 ToShadow->setLexicalDeclContext(LexicalDC);
5508 ToShadow->setAccess(D->getAccess());
5509
5510 if (UsingShadowDecl *FromPattern =
5511 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5512 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5513 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5514 ToShadow, *ToPatternOrErr);
5515 else
5516 // FIXME: We return error here but the definition is already created
5517 // and available with lookups. How to fix this?..
5518 return ToPatternOrErr.takeError();
5519 }
5520
5521 LexicalDC->addDeclInternal(ToShadow);
5522
5523 return ToShadow;
5524}
5525
5527 DeclContext *DC, *LexicalDC;
5528 DeclarationName Name;
5529 SourceLocation Loc;
5530 NamedDecl *ToD = nullptr;
5531 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5532 return std::move(Err);
5533 if (ToD)
5534 return ToD;
5535
5536 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5537 if (!ToComAncestorOrErr)
5538 return ToComAncestorOrErr.takeError();
5539
5540 Error Err = Error::success();
5541 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5542 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5543 auto ToNamespaceKeyLocation =
5545 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5546 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5547 if (Err)
5548 return std::move(Err);
5549
5550 UsingDirectiveDecl *ToUsingDir;
5551 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5552 ToUsingLoc,
5553 ToNamespaceKeyLocation,
5554 ToQualifierLoc,
5555 ToIdentLocation,
5556 ToNominatedNamespace, *ToComAncestorOrErr))
5557 return ToUsingDir;
5558
5559 ToUsingDir->setLexicalDeclContext(LexicalDC);
5560 LexicalDC->addDeclInternal(ToUsingDir);
5561
5562 return ToUsingDir;
5563}
5564
5566 DeclContext *DC, *LexicalDC;
5567 DeclarationName Name;
5568 SourceLocation Loc;
5569 NamedDecl *ToD = nullptr;
5570 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5571 return std::move(Err);
5572 if (ToD)
5573 return ToD;
5574
5575 auto ToInstantiatedFromUsingOrErr =
5576 Importer.Import(D->getInstantiatedFromUsingDecl());
5577 if (!ToInstantiatedFromUsingOrErr)
5578 return ToInstantiatedFromUsingOrErr.takeError();
5579 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5580 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5581 return std::move(Err);
5582
5583 UsingPackDecl *ToUsingPack;
5584 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5585 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5586 Expansions))
5587 return ToUsingPack;
5588
5589 addDeclToContexts(D, ToUsingPack);
5590
5591 return ToUsingPack;
5592}
5593
5596 DeclContext *DC, *LexicalDC;
5597 DeclarationName Name;
5598 SourceLocation Loc;
5599 NamedDecl *ToD = nullptr;
5600 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5601 return std::move(Err);
5602 if (ToD)
5603 return ToD;
5604
5605 Error Err = Error::success();
5606 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5607 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5608 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5609 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5610 if (Err)
5611 return std::move(Err);
5612
5613 DeclarationNameInfo NameInfo(Name, ToLoc);
5614 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5615 return std::move(Err);
5616
5617 UnresolvedUsingValueDecl *ToUsingValue;
5618 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5619 ToUsingLoc, ToQualifierLoc, NameInfo,
5620 ToEllipsisLoc))
5621 return ToUsingValue;
5622
5623 ToUsingValue->setAccess(D->getAccess());
5624 ToUsingValue->setLexicalDeclContext(LexicalDC);
5625 LexicalDC->addDeclInternal(ToUsingValue);
5626
5627 return ToUsingValue;
5628}
5629
5632 DeclContext *DC, *LexicalDC;
5633 DeclarationName Name;
5634 SourceLocation Loc;
5635 NamedDecl *ToD = nullptr;
5636 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5637 return std::move(Err);
5638 if (ToD)
5639 return ToD;
5640
5641 Error Err = Error::success();
5642 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5643 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5644 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5645 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5646 if (Err)
5647 return std::move(Err);
5648
5650 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5651 ToUsingLoc, ToTypenameLoc,
5652 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5653 return ToUsing;
5654
5655 ToUsing->setAccess(D->getAccess());
5656 ToUsing->setLexicalDeclContext(LexicalDC);
5657 LexicalDC->addDeclInternal(ToUsing);
5658
5659 return ToUsing;
5660}
5661
5663 Decl* ToD = nullptr;
5664 switch (D->getBuiltinTemplateKind()) {
5665#define BuiltinTemplate(BTName) \
5666 case BuiltinTemplateKind::BTK##BTName: \
5667 ToD = Importer.getToContext().get##BTName##Decl(); \
5668 break;
5669#include "clang/Basic/BuiltinTemplates.inc"
5670 }
5671 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5672 Importer.MapImported(D, ToD);
5673 return ToD;
5674}
5675
5678 if (To->getDefinition()) {
5679 // Check consistency of superclass.
5680 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5681 if (FromSuper) {
5682 if (auto FromSuperOrErr = import(FromSuper))
5683 FromSuper = *FromSuperOrErr;
5684 else
5685 return FromSuperOrErr.takeError();
5686 }
5687
5688 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5689 if ((bool)FromSuper != (bool)ToSuper ||
5690 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5691 Importer.ToDiag(To->getLocation(),
5692 diag::warn_odr_objc_superclass_inconsistent)
5693 << To->getDeclName();
5694 if (ToSuper)
5695 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5696 << To->getSuperClass()->getDeclName();
5697 else
5698 Importer.ToDiag(To->getLocation(),
5699 diag::note_odr_objc_missing_superclass);
5700 if (From->getSuperClass())
5701 Importer.FromDiag(From->getSuperClassLoc(),
5702 diag::note_odr_objc_superclass)
5703 << From->getSuperClass()->getDeclName();
5704 else
5705 Importer.FromDiag(From->getLocation(),
5706 diag::note_odr_objc_missing_superclass);
5707 }
5708
5710 if (Error Err = ImportDeclContext(From))
5711 return Err;
5712 return Error::success();
5713 }
5714
5715 // Start the definition.
5716 To->startDefinition();
5717
5718 // If this class has a superclass, import it.
5719 if (From->getSuperClass()) {
5720 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5721 To->setSuperClass(*SuperTInfoOrErr);
5722 else
5723 return SuperTInfoOrErr.takeError();
5724 }
5725
5726 // Import protocols
5728 SmallVector<SourceLocation, 4> ProtocolLocs;
5730 From->protocol_loc_begin();
5731
5733 FromProtoEnd = From->protocol_end();
5734 FromProto != FromProtoEnd;
5735 ++FromProto, ++FromProtoLoc) {
5736 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5737 Protocols.push_back(*ToProtoOrErr);
5738 else
5739 return ToProtoOrErr.takeError();
5740
5741 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5742 ProtocolLocs.push_back(*ToProtoLocOrErr);
5743 else
5744 return ToProtoLocOrErr.takeError();
5745
5746 }
5747
5748 // FIXME: If we're merging, make sure that the protocol list is the same.
5749 To->setProtocolList(Protocols.data(), Protocols.size(),
5750 ProtocolLocs.data(), Importer.getToContext());
5751
5752 // Import categories. When the categories themselves are imported, they'll
5753 // hook themselves into this interface.
5754 for (auto *Cat : From->known_categories()) {
5755 auto ToCatOrErr = import(Cat);
5756 if (!ToCatOrErr)
5757 return ToCatOrErr.takeError();
5758 }
5759
5760 // If we have an @implementation, import it as well.
5761 if (From->getImplementation()) {
5762 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5763 import(From->getImplementation()))
5764 To->setImplementation(*ToImplOrErr);
5765 else
5766 return ToImplOrErr.takeError();
5767 }
5768
5769 // Import all of the members of this class.
5770 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5771 return Err;
5772
5773 return Error::success();
5774}
5775
5778 if (!list)
5779 return nullptr;
5780
5782 for (auto *fromTypeParam : *list) {
5783 if (auto toTypeParamOrErr = import(fromTypeParam))
5784 toTypeParams.push_back(*toTypeParamOrErr);
5785 else
5786 return toTypeParamOrErr.takeError();
5787 }
5788
5789 auto LAngleLocOrErr = import(list->getLAngleLoc());
5790 if (!LAngleLocOrErr)
5791 return LAngleLocOrErr.takeError();
5792
5793 auto RAngleLocOrErr = import(list->getRAngleLoc());
5794 if (!RAngleLocOrErr)
5795 return RAngleLocOrErr.takeError();
5796
5797 return ObjCTypeParamList::create(Importer.getToContext(),
5798 *LAngleLocOrErr,
5799 toTypeParams,
5800 *RAngleLocOrErr);
5801}
5802
5804 // If this class has a definition in the translation unit we're coming from,
5805 // but this particular declaration is not that definition, import the
5806 // definition and map to that.
5808 if (Definition && Definition != D) {
5809 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5810 return Importer.MapImported(D, *ImportedDefOrErr);
5811 else
5812 return ImportedDefOrErr.takeError();
5813 }
5814
5815 // Import the major distinguishing characteristics of an @interface.
5816 DeclContext *DC, *LexicalDC;
5817 DeclarationName Name;
5818 SourceLocation Loc;
5819 NamedDecl *ToD;
5820 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5821 return std::move(Err);
5822 if (ToD)
5823 return ToD;
5824
5825 // Look for an existing interface with the same name.
5826 ObjCInterfaceDecl *MergeWithIface = nullptr;
5827 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5828 for (auto *FoundDecl : FoundDecls) {
5829 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5830 continue;
5831
5832 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5833 break;
5834 }
5835
5836 // Create an interface declaration, if one does not already exist.
5837 ObjCInterfaceDecl *ToIface = MergeWithIface;
5838 if (!ToIface) {
5839 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5840 if (!AtBeginLocOrErr)
5841 return AtBeginLocOrErr.takeError();
5842
5843 if (GetImportedOrCreateDecl(
5844 ToIface, D, Importer.getToContext(), DC,
5845 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5846 /*TypeParamList=*/nullptr,
5847 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5848 return ToIface;
5849 ToIface->setLexicalDeclContext(LexicalDC);
5850 LexicalDC->addDeclInternal(ToIface);
5851 }
5852 Importer.MapImported(D, ToIface);
5853 // Import the type parameter list after MapImported, to avoid
5854 // loops when bringing in their DeclContext.
5855 if (auto ToPListOrErr =
5857 ToIface->setTypeParamList(*ToPListOrErr);
5858 else
5859 return ToPListOrErr.takeError();
5860
5862 if (Error Err = ImportDefinition(D, ToIface))
5863 return std::move(Err);
5864
5865 return ToIface;
5866}
5867
5870 ObjCCategoryDecl *Category;
5871 if (Error Err = importInto(Category, D->getCategoryDecl()))
5872 return std::move(Err);
5873
5874 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5875 if (!ToImpl) {
5876 DeclContext *DC, *LexicalDC;
5877 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5878 return std::move(Err);
5879
5880 Error Err = Error::success();
5881 auto ToLocation = importChecked(Err, D->getLocation());
5882 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5883 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5884 if (Err)
5885 return std::move(Err);
5886
5887 if (GetImportedOrCreateDecl(
5888 ToImpl, D, Importer.getToContext(), DC,
5889 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5890 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5891 return ToImpl;
5892
5893 ToImpl->setLexicalDeclContext(LexicalDC);
5894 LexicalDC->addDeclInternal(ToImpl);
5895 Category->setImplementation(ToImpl);
5896 }
5897
5898 Importer.MapImported(D, ToImpl);
5899 if (Error Err = ImportDeclContext(D))
5900 return std::move(Err);
5901
5902 return ToImpl;
5903}
5904
5907 // Find the corresponding interface.
5908 ObjCInterfaceDecl *Iface;
5909 if (Error Err = importInto(Iface, D->getClassInterface()))
5910 return std::move(Err);
5911
5912 // Import the superclass, if any.
5913 ObjCInterfaceDecl *Super;
5914 if (Error Err = importInto(Super, D->getSuperClass()))
5915 return std::move(Err);
5916
5918 if (!Impl) {
5919 // We haven't imported an implementation yet. Create a new @implementation
5920 // now.
5921 DeclContext *DC, *LexicalDC;
5922 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5923 return std::move(Err);
5924
5925 Error Err = Error::success();
5926 auto ToLocation = importChecked(Err, D->getLocation());
5927 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5928 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5929 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5930 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5931 if (Err)
5932 return std::move(Err);
5933
5934 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5935 DC, Iface, Super,
5936 ToLocation,
5937 ToAtStartLoc,
5938 ToSuperClassLoc,
5939 ToIvarLBraceLoc,
5940 ToIvarRBraceLoc))
5941 return Impl;
5942
5943 Impl->setLexicalDeclContext(LexicalDC);
5944
5945 // Associate the implementation with the class it implements.
5946 Iface->setImplementation(Impl);
5947 Importer.MapImported(D, Iface->getImplementation());
5948 } else {
5949 Importer.MapImported(D, Iface->getImplementation());
5950
5951 // Verify that the existing @implementation has the same superclass.
5952 if ((Super && !Impl->getSuperClass()) ||
5953 (!Super && Impl->getSuperClass()) ||
5954 (Super && Impl->getSuperClass() &&
5956 Impl->getSuperClass()))) {
5957 Importer.ToDiag(Impl->getLocation(),
5958 diag::warn_odr_objc_superclass_inconsistent)
5959 << Iface->getDeclName();
5960 // FIXME: It would be nice to have the location of the superclass
5961 // below.
5962 if (Impl->getSuperClass())
5963 Importer.ToDiag(Impl->getLocation(),
5964 diag::note_odr_objc_superclass)
5965 << Impl->getSuperClass()->getDeclName();
5966 else
5967 Importer.ToDiag(Impl->getLocation(),
5968 diag::note_odr_objc_missing_superclass);
5969 if (D->getSuperClass())
5970 Importer.FromDiag(D->getLocation(),
5971 diag::note_odr_objc_superclass)
5972 << D->getSuperClass()->getDeclName();
5973 else
5974 Importer.FromDiag(D->getLocation(),
5975 diag::note_odr_objc_missing_superclass);
5976
5977 return make_error<ASTImportError>(ASTImportError::NameConflict);
5978 }
5979 }
5980
5981 // Import all of the members of this @implementation.
5982 if (Error Err = ImportDeclContext(D))
5983 return std::move(Err);
5984
5985 return Impl;
5986}
5987
5989 // Import the major distinguishing characteristics of an @property.
5990 DeclContext *DC, *LexicalDC;
5991 DeclarationName Name;
5992 SourceLocation Loc;
5993 NamedDecl *ToD;
5994 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5995 return std::move(Err);
5996 if (ToD)
5997 return ToD;
5998
5999 // Check whether we have already imported this property.
6000 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6001 for (auto *FoundDecl : FoundDecls) {
6002 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
6003 // Instance and class properties can share the same name but are different
6004 // declarations.
6005 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
6006 continue;
6007
6008 // Check property types.
6009 if (!Importer.IsStructurallyEquivalent(D->getType(),
6010 FoundProp->getType())) {
6011 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
6012 << Name << D->getType() << FoundProp->getType();
6013 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
6014 << FoundProp->getType();
6015
6016 return make_error<ASTImportError>(ASTImportError::NameConflict);
6017 }
6018
6019 // FIXME: Check property attributes, getters, setters, etc.?
6020
6021 // Consider these properties to be equivalent.
6022 Importer.MapImported(D, FoundProp);
6023 return FoundProp;
6024 }
6025 }
6026
6027 Error Err = Error::success();
6028 auto ToType = importChecked(Err, D->getType());
6029 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6030 auto ToAtLoc = importChecked(Err, D->getAtLoc());
6031 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
6032 if (Err)
6033 return std::move(Err);
6034
6035 // Create the new property.
6036 ObjCPropertyDecl *ToProperty;
6037 if (GetImportedOrCreateDecl(
6038 ToProperty, D, Importer.getToContext(), DC, Loc,
6039 Name.getAsIdentifierInfo(), ToAtLoc,
6040 ToLParenLoc, ToType,
6041 ToTypeSourceInfo, D->getPropertyImplementation()))
6042 return ToProperty;
6043
6044 auto ToGetterName = importChecked(Err, D->getGetterName());
6045 auto ToSetterName = importChecked(Err, D->getSetterName());
6046 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6047 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6048 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6049 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6050 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6051 if (Err)
6052 return std::move(Err);
6053
6054 ToProperty->setLexicalDeclContext(LexicalDC);
6055 LexicalDC->addDeclInternal(ToProperty);
6056
6060 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6061 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6062 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6063 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6064 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6065 return ToProperty;
6066}
6067
6071 if (Error Err = importInto(Property, D->getPropertyDecl()))
6072 return std::move(Err);
6073
6074 DeclContext *DC, *LexicalDC;
6075 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6076 return std::move(Err);
6077
6078 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6079
6080 // Import the ivar (for an @synthesize).
6081 ObjCIvarDecl *Ivar = nullptr;
6082 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6083 return std::move(Err);
6084
6085 ObjCPropertyImplDecl *ToImpl
6086 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6087 Property->getQueryKind());
6088 if (!ToImpl) {
6089
6090 Error Err = Error::success();
6091 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6092 auto ToLocation = importChecked(Err, D->getLocation());
6093 auto ToPropertyIvarDeclLoc =
6095 if (Err)
6096 return std::move(Err);
6097
6098 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6099 ToBeginLoc,
6100 ToLocation, Property,
6101 D->getPropertyImplementation(), Ivar,
6102 ToPropertyIvarDeclLoc))
6103 return ToImpl;
6104
6105 ToImpl->setLexicalDeclContext(LexicalDC);
6106 LexicalDC->addDeclInternal(ToImpl);
6107 } else {
6108 // Check that we have the same kind of property implementation (@synthesize
6109 // vs. @dynamic).
6111 Importer.ToDiag(ToImpl->getLocation(),
6112 diag::warn_odr_objc_property_impl_kind_inconsistent)
6113 << Property->getDeclName()
6114 << (ToImpl->getPropertyImplementation()
6116 Importer.FromDiag(D->getLocation(),
6117 diag::note_odr_objc_property_impl_kind)
6118 << D->getPropertyDecl()->getDeclName()
6120
6121 return make_error<ASTImportError>(ASTImportError::NameConflict);
6122 }
6123
6124 // For @synthesize, check that we have the same
6126 Ivar != ToImpl->getPropertyIvarDecl()) {
6127 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6128 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6129 << Property->getDeclName()
6130 << ToImpl->getPropertyIvarDecl()->getDeclName()
6131 << Ivar->getDeclName();
6132 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6133 diag::note_odr_objc_synthesize_ivar_here)
6135
6136 return make_error<ASTImportError>(ASTImportError::NameConflict);
6137 }
6138
6139 // Merge the existing implementation with the new implementation.
6140 Importer.MapImported(D, ToImpl);
6141 }
6142
6143 return ToImpl;
6144}
6145
6148 Error Err = Error::success();
6149 auto ToType = importChecked(Err, D->getType());
6150 auto ToValue = importChecked(Err, D->getValue());
6151 if (Err)
6152 return std::move(Err);
6153
6155 auto Create = [this](QualType T, const APValue &V) {
6156 return Importer.ToContext.getTemplateParamObjectDecl(T, V);
6157 };
6158 (void)GetImportedOrCreateSpecialDecl(ToD, Create, D, ToType, ToValue);
6159 return ToD;
6160}
6161
6164 // For template arguments, we adopt the translation unit as our declaration
6165 // context. This context will be fixed when (during) the actual template
6166 // declaration is created.
6167
6168 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6169 if (!BeginLocOrErr)
6170 return BeginLocOrErr.takeError();
6171
6172 ExpectedSLoc LocationOrErr = import(D->getLocation());
6173 if (!LocationOrErr)
6174 return LocationOrErr.takeError();
6175
6176 TemplateTypeParmDecl *ToD = nullptr;
6177 if (GetImportedOrCreateDecl(
6178 ToD, D, Importer.getToContext(),
6179 Importer.getToContext().getTranslationUnitDecl(),
6180 *BeginLocOrErr, *LocationOrErr,
6181 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6183 D->hasTypeConstraint()))
6184 return ToD;
6185
6186 // Import the type-constraint
6187 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6188
6189 Error Err = Error::success();
6190 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6191 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6192 if (Err)
6193 return std::move(Err);
6194
6195 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6196 }
6197
6198 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6199 return Err;
6200
6201 return ToD;
6202}
6203
6206
6207 Error Err = Error::success();
6208 auto ToDeclName = importChecked(Err, D->getDeclName());
6209 auto ToLocation = importChecked(Err, D->getLocation());
6210 auto ToType = importChecked(Err, D->getType());
6211 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6212 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6213 if (Err)
6214 return std::move(Err);
6215
6216 NonTypeTemplateParmDecl *ToD = nullptr;
6217 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6218 Importer.getToContext().getTranslationUnitDecl(),
6219 ToInnerLocStart, ToLocation, D->getDepth(),
6220 D->getPosition(),
6221 ToDeclName.getAsIdentifierInfo(), ToType,
6222 D->isParameterPack(), ToTypeSourceInfo))
6223 return ToD;
6224
6225 Err = importTemplateParameterDefaultArgument(D, ToD);
6226 if (Err)
6227 return Err;
6228
6229 return ToD;
6230}
6231
6234 bool IsCanonical = false;
6235 if (auto *CanonD = Importer.getFromContext()
6236 .findCanonicalTemplateTemplateParmDeclInternal(D);
6237 CanonD == D)
6238 IsCanonical = true;
6239
6240 // Import the name of this declaration.
6241 auto NameOrErr = import(D->getDeclName());
6242 if (!NameOrErr)
6243 return NameOrErr.takeError();
6244
6245 // Import the location of this declaration.
6246 ExpectedSLoc LocationOrErr = import(D->getLocation());
6247 if (!LocationOrErr)
6248 return LocationOrErr.takeError();
6249
6250 // Import template parameters.
6251 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6252 if (!TemplateParamsOrErr)
6253 return TemplateParamsOrErr.takeError();
6254
6255 TemplateTemplateParmDecl *ToD = nullptr;
6256 if (GetImportedOrCreateDecl(
6257 ToD, D, Importer.getToContext(),
6258 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6259 D->getDepth(), D->getPosition(), D->isParameterPack(),
6260 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6261 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6262 return ToD;
6263
6264 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6265 return Err;
6266
6267 if (IsCanonical)
6268 return Importer.getToContext()
6269 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6270
6271 return ToD;
6272}
6273
6274// Returns the definition for a (forward) declaration of a TemplateDecl, if
6275// it has any definition in the redecl chain.
6276template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6277 assert(D->getTemplatedDecl() && "Should be called on templates only");
6278 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6279 if (!ToTemplatedDef)
6280 return nullptr;
6281 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6282 return cast_or_null<T>(TemplateWithDef);
6283}
6284
6286
6287 // Import the major distinguishing characteristics of this class template.
6288 DeclContext *DC, *LexicalDC;
6289 DeclarationName Name;
6290 SourceLocation Loc;
6291 NamedDecl *ToD;
6292 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6293 return std::move(Err);
6294 if (ToD)
6295 return ToD;
6296
6297 // Should check if a declaration is friend in a dependent context.
6298 // Such templates are not linked together in a declaration chain.
6299 // The ASTImporter strategy is to map existing forward declarations to
6300 // imported ones only if strictly necessary, otherwise import these as new
6301 // forward declarations. In case of the "dependent friend" declarations, new
6302 // declarations are created, but not linked in a declaration chain.
6303 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6304 return TD->getFriendObjectKind() != Decl::FOK_None &&
6305 TD->getLexicalDeclContext()->isDependentContext();
6306 };
6307 bool DependentFriend = IsDependentFriend(D);
6308
6309 ClassTemplateDecl *FoundByLookup = nullptr;
6310
6311 // We may already have a template of the same name; try to find and match it.
6312 if (!DC->isFunctionOrMethod()) {
6313 SmallVector<NamedDecl *, 4> ConflictingDecls;
6314 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6315 for (auto *FoundDecl : FoundDecls) {
6316 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6318 continue;
6319
6320 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6321 if (FoundTemplate) {
6322 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6323 continue;
6324
6325 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6326 bool IgnoreTemplateParmDepth =
6327 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6329 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6330 IgnoreTemplateParmDepth)) {
6331 if (DependentFriend || IsDependentFriend(FoundTemplate))
6332 continue;
6333
6334 ClassTemplateDecl *TemplateWithDef =
6335 getTemplateDefinition(FoundTemplate);
6336 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6337 return Importer.MapImported(D, TemplateWithDef);
6338 if (!FoundByLookup)
6339 FoundByLookup = FoundTemplate;
6340 // Search in all matches because there may be multiple decl chains,
6341 // see ASTTests test ImportExistingFriendClassTemplateDef.
6342 continue;
6343 }
6344 // When importing a friend, it is possible that multiple declarations
6345 // with same name can co-exist in specific cases (if a template contains
6346 // a friend template and has a specialization). For this case the
6347 // declarations should match, except that the "template depth" is
6348 // different. No linking of previous declaration is needed in this case.
6349 // FIXME: This condition may need refinement.
6350 if (D->getFriendObjectKind() != Decl::FOK_None &&
6351 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6352 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6353 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6354 /*IgnoreTemplateParmDepth=*/true))
6355 continue;
6356
6357 ConflictingDecls.push_back(FoundDecl);
6358 }
6359 }
6360
6361 if (!ConflictingDecls.empty()) {
6362 ExpectedName NameOrErr = Importer.HandleNameConflict(
6363 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6364 ConflictingDecls.size());
6365 if (NameOrErr)
6366 Name = NameOrErr.get();
6367 else
6368 return NameOrErr.takeError();
6369 }
6370 }
6371
6372 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6373
6374 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6375 if (!TemplateParamsOrErr)
6376 return TemplateParamsOrErr.takeError();
6377
6378 // Create the declaration that is being templated.
6379 CXXRecordDecl *ToTemplated;
6380 if (Error Err = importInto(ToTemplated, FromTemplated))
6381 return std::move(Err);
6382
6383 // Create the class template declaration itself.
6385 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6386 *TemplateParamsOrErr, ToTemplated))
6387 return D2;
6388
6389 ToTemplated->setDescribedClassTemplate(D2);
6390
6391 D2->setAccess(D->getAccess());
6392 D2->setLexicalDeclContext(LexicalDC);
6393
6394 addDeclToContexts(D, D2);
6395 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6396
6397 if (FoundByLookup) {
6398 auto *Recent =
6399 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6400
6401 // It is possible that during the import of the class template definition
6402 // we start the import of a fwd friend decl of the very same class template
6403 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6404 // had been created earlier and by that time the lookup could not find
6405 // anything existing, so it has no previous decl. Later, (still during the
6406 // import of the fwd friend decl) we start to import the definition again
6407 // and this time the lookup finds the previous fwd friend class template.
6408 // In this case we must set up the previous decl for the templated decl.
6409 if (!ToTemplated->getPreviousDecl()) {
6410 assert(FoundByLookup->getTemplatedDecl() &&
6411 "Found decl must have its templated decl set");
6412 CXXRecordDecl *PrevTemplated =
6413 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6414 if (ToTemplated != PrevTemplated)
6415 ToTemplated->setPreviousDecl(PrevTemplated);
6416 }
6417
6418 D2->setPreviousDecl(Recent);
6419 }
6420
6421 return D2;
6422}
6423
6426 ClassTemplateDecl *ClassTemplate;
6427 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6428 return std::move(Err);
6429
6430 // Import the context of this declaration.
6431 DeclContext *DC, *LexicalDC;
6432 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6433 return std::move(Err);
6434
6435 // Import template arguments.
6437 if (Error Err =
6438 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6439 return std::move(Err);
6440 // Try to find an existing specialization with these template arguments and
6441 // template parameter list.
6442 void *InsertPos = nullptr;
6443 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6445 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6446
6447 // Import template parameters.
6448 TemplateParameterList *ToTPList = nullptr;
6449
6450 if (PartialSpec) {
6451 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6452 if (!ToTPListOrErr)
6453 return ToTPListOrErr.takeError();
6454 ToTPList = *ToTPListOrErr;
6455 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6456 *ToTPListOrErr,
6457 InsertPos);
6458 } else
6459 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6460
6461 if (PrevDecl) {
6462 if (IsStructuralMatch(D, PrevDecl)) {
6463 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6464 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6465 Importer.MapImported(D, PrevDefinition);
6466 // Import those default field initializers which have been
6467 // instantiated in the "From" context, but not in the "To" context.
6468 for (auto *FromField : D->fields()) {
6469 auto ToOrErr = import(FromField);
6470 if (!ToOrErr)
6471 return ToOrErr.takeError();
6472 }
6473
6474 // Import those methods which have been instantiated in the
6475 // "From" context, but not in the "To" context.
6476 for (CXXMethodDecl *FromM : D->methods()) {
6477 auto ToOrErr = import(FromM);
6478 if (!ToOrErr)
6479 return ToOrErr.takeError();
6480 }
6481
6482 // TODO Import instantiated default arguments.
6483 // TODO Import instantiated exception specifications.
6484 //
6485 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6486 // what else could be fused during an AST merge.
6487 return PrevDefinition;
6488 }
6489 } else { // ODR violation.
6490 // FIXME HandleNameConflict
6491 return make_error<ASTImportError>(ASTImportError::NameConflict);
6492 }
6493 }
6494
6495 // Import the location of this declaration.
6496 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6497 if (!BeginLocOrErr)
6498 return BeginLocOrErr.takeError();
6499 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6500 if (!IdLocOrErr)
6501 return IdLocOrErr.takeError();
6502
6503 // Import TemplateArgumentListInfo.
6504 TemplateArgumentListInfo ToTAInfo;
6505 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6506 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6507 return std::move(Err);
6508 }
6509
6510 // Create the specialization.
6511 ClassTemplateSpecializationDecl *D2 = nullptr;
6512 if (PartialSpec) {
6513 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6514 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6515 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6516 /*CanonInjectedTST=*/CanQualType(),
6517 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6518 return D2;
6519
6520 // Update InsertPos, because preceding import calls may have invalidated
6521 // it by adding new specializations.
6523 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6524 InsertPos))
6525 // Add this partial specialization to the class template.
6526 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6528 import(PartialSpec->getInstantiatedFromMember()))
6529 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6530 else
6531 return ToInstOrErr.takeError();
6532
6533 updateLookupTableForTemplateParameters(*ToTPList);
6534 } else { // Not a partial specialization.
6535 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6536 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6537 TemplateArgs, D->hasStrictPackMatch(),
6538 PrevDecl))
6539 return D2;
6540
6541 // Update InsertPos, because preceding import calls may have invalidated
6542 // it by adding new specializations.
6543 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6544 // Add this specialization to the class template.
6545 ClassTemplate->AddSpecialization(D2, InsertPos);
6546 }
6547
6549
6550 // Set the context of this specialization/instantiation.
6551 D2->setLexicalDeclContext(LexicalDC);
6552
6553 // Add to the DC only if it was an explicit specialization/instantiation.
6555 LexicalDC->addDeclInternal(D2);
6556 }
6557
6558 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6559 D2->setBraceRange(*BraceRangeOrErr);
6560 else
6561 return BraceRangeOrErr.takeError();
6562
6563 if (Error Err = ImportTemplateParameterLists(D, D2))
6564 return std::move(Err);
6565
6566 // Import the qualifier, if any.
6567 if (auto LocOrErr = import(D->getQualifierLoc()))
6568 D2->setQualifierInfo(*LocOrErr);
6569 else
6570 return LocOrErr.takeError();
6571
6572 if (D->getTemplateArgsAsWritten())
6573 D2->setTemplateArgsAsWritten(ToTAInfo);
6574
6575 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6576 D2->setTemplateKeywordLoc(*LocOrErr);
6577 else
6578 return LocOrErr.takeError();
6579
6580 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6581 D2->setExternKeywordLoc(*LocOrErr);
6582 else
6583 return LocOrErr.takeError();
6584
6585 if (D->getPointOfInstantiation().isValid()) {
6586 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6587 D2->setPointOfInstantiation(*POIOrErr);
6588 else
6589 return POIOrErr.takeError();
6590 }
6591
6593
6594 if (auto P = D->getInstantiatedFrom()) {
6595 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6596 if (auto CTDorErr = import(CTD))
6597 D2->setInstantiationOf(*CTDorErr);
6598 } else {
6600 auto CTPSDOrErr = import(CTPSD);
6601 if (!CTPSDOrErr)
6602 return CTPSDOrErr.takeError();
6604 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6605 for (unsigned I = 0; I < DArgs.size(); ++I) {
6606 const TemplateArgument &DArg = DArgs[I];
6607 if (auto ArgOrErr = import(DArg))
6608 D2ArgsVec[I] = *ArgOrErr;
6609 else
6610 return ArgOrErr.takeError();
6611 }
6613 *CTPSDOrErr,
6614 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6615 }
6616 }
6617
6618 if (D->isCompleteDefinition())
6619 if (Error Err = ImportDefinition(D, D2))
6620 return std::move(Err);
6621
6622 return D2;
6623}
6624
6626 // Import the major distinguishing characteristics of this variable template.
6627 DeclContext *DC, *LexicalDC;
6628 DeclarationName Name;
6629 SourceLocation Loc;
6630 NamedDecl *ToD;
6631 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6632 return std::move(Err);
6633 if (ToD)
6634 return ToD;
6635
6636 // We may already have a template of the same name; try to find and match it.
6637 assert(!DC->isFunctionOrMethod() &&
6638 "Variable templates cannot be declared at function scope");
6639
6640 SmallVector<NamedDecl *, 4> ConflictingDecls;
6641 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6642 VarTemplateDecl *FoundByLookup = nullptr;
6643 for (auto *FoundDecl : FoundDecls) {
6644 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6645 continue;
6646
6647 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6648 // Use the templated decl, some linkage flags are set only there.
6649 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6650 D->getTemplatedDecl()))
6651 continue;
6652 if (IsStructuralMatch(D, FoundTemplate)) {
6653 // FIXME Check for ODR error if the two definitions have
6654 // different initializers?
6655 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6656 if (D->getDeclContext()->isRecord()) {
6657 assert(FoundTemplate->getDeclContext()->isRecord() &&
6658 "Member variable template imported as non-member, "
6659 "inconsistent imported AST?");
6660 if (FoundDef)
6661 return Importer.MapImported(D, FoundDef);
6663 return Importer.MapImported(D, FoundTemplate);
6664 } else {
6665 if (FoundDef && D->isThisDeclarationADefinition())
6666 return Importer.MapImported(D, FoundDef);
6667 }
6668 FoundByLookup = FoundTemplate;
6669 break;
6670 }
6671 ConflictingDecls.push_back(FoundDecl);
6672 }
6673 }
6674
6675 if (!ConflictingDecls.empty()) {
6676 ExpectedName NameOrErr = Importer.HandleNameConflict(
6677 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6678 ConflictingDecls.size());
6679 if (NameOrErr)
6680 Name = NameOrErr.get();
6681 else
6682 return NameOrErr.takeError();
6683 }
6684
6685 VarDecl *DTemplated = D->getTemplatedDecl();
6686
6687 // Import the type.
6688 // FIXME: Value not used?
6689 ExpectedType TypeOrErr = import(DTemplated->getType());
6690 if (!TypeOrErr)
6691 return TypeOrErr.takeError();
6692
6693 // Create the declaration that is being templated.
6694 VarDecl *ToTemplated;
6695 if (Error Err = importInto(ToTemplated, DTemplated))
6696 return std::move(Err);
6697
6698 // Create the variable template declaration itself.
6699 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6700 if (!TemplateParamsOrErr)
6701 return TemplateParamsOrErr.takeError();
6702
6703 VarTemplateDecl *ToVarTD;
6704 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6705 Name, *TemplateParamsOrErr, ToTemplated))
6706 return ToVarTD;
6707
6708 ToTemplated->setDescribedVarTemplate(ToVarTD);
6709
6710 ToVarTD->setAccess(D->getAccess());
6711 ToVarTD->setLexicalDeclContext(LexicalDC);
6712 LexicalDC->addDeclInternal(ToVarTD);
6713 if (DC != Importer.getToContext().getTranslationUnitDecl())
6714 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6715
6716 if (FoundByLookup) {
6717 auto *Recent =
6718 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6719 if (!ToTemplated->getPreviousDecl()) {
6720 auto *PrevTemplated =
6721 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6722 if (ToTemplated != PrevTemplated)
6723 ToTemplated->setPreviousDecl(PrevTemplated);
6724 }
6725 ToVarTD->setPreviousDecl(Recent);
6726 }
6727
6728 return ToVarTD;
6729}
6730
6733 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6734 // in an analog way (but specialized for this case).
6735
6737 auto RedeclIt = Redecls.begin();
6738 // Import the first part of the decl chain. I.e. import all previous
6739 // declarations starting from the canonical decl.
6740 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6741 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6742 if (!RedeclOrErr)
6743 return RedeclOrErr.takeError();
6744 }
6745 assert(*RedeclIt == D);
6746
6747 VarTemplateDecl *VarTemplate = nullptr;
6749 return std::move(Err);
6750
6751 // Import the context of this declaration.
6752 DeclContext *DC, *LexicalDC;
6753 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6754 return std::move(Err);
6755
6756 // Import the location of this declaration.
6757 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6758 if (!BeginLocOrErr)
6759 return BeginLocOrErr.takeError();
6760
6761 auto IdLocOrErr = import(D->getLocation());
6762 if (!IdLocOrErr)
6763 return IdLocOrErr.takeError();
6764
6765 // Import template arguments.
6767 if (Error Err =
6768 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6769 return std::move(Err);
6770
6771 // Try to find an existing specialization with these template arguments.
6772 void *InsertPos = nullptr;
6773 VarTemplateSpecializationDecl *FoundSpecialization =
6774 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6775 if (FoundSpecialization) {
6776 if (IsStructuralMatch(D, FoundSpecialization)) {
6777 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6778 if (D->getDeclContext()->isRecord()) {
6779 // In a record, it is allowed only to have one optional declaration and
6780 // one definition of the (static or constexpr) variable template.
6781 assert(
6782 FoundSpecialization->getDeclContext()->isRecord() &&
6783 "Member variable template specialization imported as non-member, "
6784 "inconsistent imported AST?");
6785 if (FoundDef)
6786 return Importer.MapImported(D, FoundDef);
6788 return Importer.MapImported(D, FoundSpecialization);
6789 } else {
6790 // If definition is imported and there is already one, map to it.
6791 // Otherwise create a new variable and link it to the existing.
6792 if (FoundDef && D->isThisDeclarationADefinition())
6793 return Importer.MapImported(D, FoundDef);
6794 }
6795 } else {
6796 return make_error<ASTImportError>(ASTImportError::NameConflict);
6797 }
6798 }
6799
6800 VarTemplateSpecializationDecl *D2 = nullptr;
6801
6802 TemplateArgumentListInfo ToTAInfo;
6803 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6804 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6805 return std::move(Err);
6806 }
6807
6808 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6809 // Create a new specialization.
6810 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6811 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6812 if (!ToTPListOrErr)
6813 return ToTPListOrErr.takeError();
6814
6815 PartVarSpecDecl *ToPartial;
6816 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6817 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6818 VarTemplate, QualType(), nullptr,
6819 D->getStorageClass(), TemplateArgs))
6820 return ToPartial;
6821
6822 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6823 import(FromPartial->getInstantiatedFromMember()))
6824 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6825 else
6826 return ToInstOrErr.takeError();
6827
6828 if (FromPartial->isMemberSpecialization())
6829 ToPartial->setMemberSpecialization();
6830
6831 D2 = ToPartial;
6832
6833 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6834 // to adopt template parameters.
6835 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6836 } else { // Full specialization
6837 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6838 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6839 QualType(), nullptr, D->getStorageClass(),
6840 TemplateArgs))
6841 return D2;
6842 }
6843
6844 // Update InsertPos, because preceding import calls may have invalidated
6845 // it by adding new specializations.
6846 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6847 VarTemplate->AddSpecialization(D2, InsertPos);
6848
6849 QualType T;
6850 if (Error Err = importInto(T, D->getType()))
6851 return std::move(Err);
6852 D2->setType(T);
6853
6854 auto TInfoOrErr = import(D->getTypeSourceInfo());
6855 if (!TInfoOrErr)
6856 return TInfoOrErr.takeError();
6857 D2->setTypeSourceInfo(*TInfoOrErr);
6858
6859 if (D->getPointOfInstantiation().isValid()) {
6860 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6861 D2->setPointOfInstantiation(*POIOrErr);
6862 else
6863 return POIOrErr.takeError();
6864 }
6865
6867
6868 if (D->getTemplateArgsAsWritten())
6869 D2->setTemplateArgsAsWritten(ToTAInfo);
6870
6871 if (auto LocOrErr = import(D->getQualifierLoc()))
6872 D2->setQualifierInfo(*LocOrErr);
6873 else
6874 return LocOrErr.takeError();
6875
6876 if (D->isConstexpr())
6877 D2->setConstexpr(true);
6878
6879 D2->setAccess(D->getAccess());
6880
6881 if (Error Err = ImportInitializer(D, D2))
6882 return std::move(Err);
6883
6884 if (FoundSpecialization)
6885 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6886
6887 addDeclToContexts(D, D2);
6888
6889 // Import the rest of the chain. I.e. import all subsequent declarations.
6890 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6891 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6892 if (!RedeclOrErr)
6893 return RedeclOrErr.takeError();
6894 }
6895
6896 return D2;
6897}
6898
6901 DeclContext *DC, *LexicalDC;
6902 DeclarationName Name;
6903 SourceLocation Loc;
6904 NamedDecl *ToD;
6905
6906 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6907 return std::move(Err);
6908
6909 if (ToD)
6910 return ToD;
6911
6912 const FunctionTemplateDecl *FoundByLookup = nullptr;
6913
6914 // Try to find a function in our own ("to") context with the same name, same
6915 // type, and in the same context as the function we're importing.
6916 // FIXME Split this into a separate function.
6917 if (!LexicalDC->isFunctionOrMethod()) {
6919 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6920 for (auto *FoundDecl : FoundDecls) {
6921 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6922 continue;
6923
6924 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6925 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6926 continue;
6927 if (IsStructuralMatch(D, FoundTemplate)) {
6928 FunctionTemplateDecl *TemplateWithDef =
6929 getTemplateDefinition(FoundTemplate);
6930 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6931 return Importer.MapImported(D, TemplateWithDef);
6932
6933 FoundByLookup = FoundTemplate;
6934 break;
6935 // TODO: handle conflicting names
6936 }
6937 }
6938 }
6939 }
6940
6941 auto ParamsOrErr = import(D->getTemplateParameters());
6942 if (!ParamsOrErr)
6943 return ParamsOrErr.takeError();
6944 TemplateParameterList *Params = *ParamsOrErr;
6945
6946 FunctionDecl *TemplatedFD;
6947 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6948 return std::move(Err);
6949
6950 // At creation of the template the template parameters are "adopted"
6951 // (DeclContext is changed). After this possible change the lookup table
6952 // must be updated.
6953 // At deduction guides the DeclContext of the template parameters may be
6954 // different from what we would expect, it may be the class template, or a
6955 // probably different CXXDeductionGuideDecl. This may come from the fact that
6956 // the template parameter objects may be shared between deduction guides or
6957 // the class template, and at creation of multiple FunctionTemplateDecl
6958 // objects (for deduction guides) the same parameters are re-used. The
6959 // "adoption" happens multiple times with different parent, even recursively
6960 // for TemplateTemplateParmDecl. The same happens at import when the
6961 // FunctionTemplateDecl objects are created, but in different order.
6962 // In this way the DeclContext of these template parameters is not necessarily
6963 // the same as in the "from" context.
6965 OldParamDC.reserve(Params->size());
6966 llvm::transform(*Params, std::back_inserter(OldParamDC),
6967 [](NamedDecl *ND) { return ND->getDeclContext(); });
6968
6969 FunctionTemplateDecl *ToFunc;
6970 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6971 Params, TemplatedFD))
6972 return ToFunc;
6973
6974 // Fail if TemplatedFD is already part of a template.
6975 // The template should have been found by structural equivalence check before,
6976 // or ToFunc should be already imported.
6977 // If not, there is AST incompatibility that can be caused by previous import
6978 // errors. (NameConflict is not exact here.)
6979 if (TemplatedFD->getDescribedTemplate())
6980 return make_error<ASTImportError>(ASTImportError::NameConflict);
6981
6982 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6983
6984 ToFunc->setAccess(D->getAccess());
6985 ToFunc->setLexicalDeclContext(LexicalDC);
6986 addDeclToContexts(D, ToFunc);
6987
6988 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6989 if (LT && !OldParamDC.empty()) {
6990 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6991 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6992 }
6993
6994 if (FoundByLookup) {
6995 auto *Recent =
6996 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6997 if (!TemplatedFD->getPreviousDecl()) {
6998 assert(FoundByLookup->getTemplatedDecl() &&
6999 "Found decl must have its templated decl set");
7000 auto *PrevTemplated =
7001 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
7002 if (TemplatedFD != PrevTemplated)
7003 TemplatedFD->setPreviousDecl(PrevTemplated);
7004 }
7005 ToFunc->setPreviousDecl(Recent);
7006 }
7007
7008 return ToFunc;
7009}
7010
7012 DeclContext *DC, *LexicalDC;
7013 Error Err = ImportDeclContext(D, DC, LexicalDC);
7014 auto LocationOrErr = importChecked(Err, D->getLocation());
7015 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
7016 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
7017 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
7018 if (Err)
7019 return std::move(Err);
7020
7021 ConceptDecl *To;
7022 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
7023 NameDeclOrErr, ToTemplateParameters,
7024 ConstraintExpr))
7025 return To;
7026 To->setLexicalDeclContext(LexicalDC);
7027 LexicalDC->addDeclInternal(To);
7028 return To;
7029}
7030
7033 DeclContext *DC, *LexicalDC;
7034 Error Err = ImportDeclContext(D, DC, LexicalDC);
7035 auto RequiresLoc = importChecked(Err, D->getLocation());
7036 if (Err)
7037 return std::move(Err);
7038
7040 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
7041 return To;
7042 To->setLexicalDeclContext(LexicalDC);
7043 LexicalDC->addDeclInternal(To);
7044 return To;
7045}
7046
7049 DeclContext *DC, *LexicalDC;
7050 Error Err = ImportDeclContext(D, DC, LexicalDC);
7051 auto ToSL = importChecked(Err, D->getLocation());
7052 if (Err)
7053 return std::move(Err);
7054
7056 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
7057 return std::move(Err);
7058
7060 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
7061 return To;
7062 To->setLexicalDeclContext(LexicalDC);
7063 LexicalDC->addDeclInternal(To);
7064 return To;
7065}
7066
7067//----------------------------------------------------------------------------
7068// Import Statements
7069//----------------------------------------------------------------------------
7070
7072 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7073 << S->getStmtClassName();
7074 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7075}
7076
7077
7079 if (Importer.returnWithErrorInTest())
7080 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7082 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7083 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7084 // ToII is nullptr when no symbolic name is given for output operand
7085 // see ParseStmtAsm::ParseAsmOperandsOpt
7086 Names.push_back(ToII);
7087 }
7088
7089 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7090 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7091 // ToII is nullptr when no symbolic name is given for input operand
7092 // see ParseStmtAsm::ParseAsmOperandsOpt
7093 Names.push_back(ToII);
7094 }
7095
7096 SmallVector<Expr *, 4> Clobbers;
7097 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7098 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7099 Clobbers.push_back(*ClobberOrErr);
7100 else
7101 return ClobberOrErr.takeError();
7102
7103 }
7104
7105 SmallVector<Expr *, 4> Constraints;
7106 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7107 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7108 Constraints.push_back(*OutputOrErr);
7109 else
7110 return OutputOrErr.takeError();
7111 }
7112
7113 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7114 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7115 Constraints.push_back(*InputOrErr);
7116 else
7117 return InputOrErr.takeError();
7118 }
7119
7121 S->getNumLabels());
7122 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7123 return std::move(Err);
7124
7125 if (Error Err =
7126 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7127 return std::move(Err);
7128
7129 if (Error Err = ImportArrayChecked(
7130 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7131 return std::move(Err);
7132
7133 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7134 if (!AsmLocOrErr)
7135 return AsmLocOrErr.takeError();
7136 auto AsmStrOrErr = import(S->getAsmStringExpr());
7137 if (!AsmStrOrErr)
7138 return AsmStrOrErr.takeError();
7139 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7140 if (!RParenLocOrErr)
7141 return RParenLocOrErr.takeError();
7142
7143 return new (Importer.getToContext()) GCCAsmStmt(
7144 Importer.getToContext(),
7145 *AsmLocOrErr,
7146 S->isSimple(),
7147 S->isVolatile(),
7148 S->getNumOutputs(),
7149 S->getNumInputs(),
7150 Names.data(),
7151 Constraints.data(),
7152 Exprs.data(),
7153 *AsmStrOrErr,
7154 S->getNumClobbers(),
7155 Clobbers.data(),
7156 S->getNumLabels(),
7157 *RParenLocOrErr);
7158}
7159
7161
7162 Error Err = Error::success();
7163 auto ToDG = importChecked(Err, S->getDeclGroup());
7164 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7165 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7166 if (Err)
7167 return std::move(Err);
7168 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7169}
7170
7172 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7173 if (!ToSemiLocOrErr)
7174 return ToSemiLocOrErr.takeError();
7175 return new (Importer.getToContext()) NullStmt(
7176 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7177}
7178
7180 SmallVector<Stmt *, 8> ToStmts(S->size());
7181
7182 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7183 return std::move(Err);
7184
7185 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7186 if (!ToLBracLocOrErr)
7187 return ToLBracLocOrErr.takeError();
7188
7189 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7190 if (!ToRBracLocOrErr)
7191 return ToRBracLocOrErr.takeError();
7192
7193 FPOptionsOverride FPO =
7195 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7196 *ToLBracLocOrErr, *ToRBracLocOrErr);
7197}
7198
7200
7201 Error Err = Error::success();
7202 auto ToLHS = importChecked(Err, S->getLHS());
7203 auto ToRHS = importChecked(Err, S->getRHS());
7204 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7205 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7206 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7207 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7208 if (Err)
7209 return std::move(Err);
7210
7211 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7212 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7213 ToStmt->setSubStmt(ToSubStmt);
7214
7215 return ToStmt;
7216}
7217
7219
7220 Error Err = Error::success();
7221 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7222 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7223 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7224 if (Err)
7225 return std::move(Err);
7226
7227 return new (Importer.getToContext()) DefaultStmt(
7228 ToDefaultLoc, ToColonLoc, ToSubStmt);
7229}
7230
7232
7233 Error Err = Error::success();
7234 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7235 auto ToLabelDecl = importChecked(Err, S->getDecl());
7236 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7237 if (Err)
7238 return std::move(Err);
7239
7240 return new (Importer.getToContext()) LabelStmt(
7241 ToIdentLoc, ToLabelDecl, ToSubStmt);
7242}
7243
7245 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7246 if (!ToAttrLocOrErr)
7247 return ToAttrLocOrErr.takeError();
7248 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7249 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7250 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7251 return std::move(Err);
7252 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7253 if (!ToSubStmtOrErr)
7254 return ToSubStmtOrErr.takeError();
7255
7257 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7258}
7259
7261
7262 Error Err = Error::success();
7263 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7264 auto ToInit = importChecked(Err, S->getInit());
7265 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7266 auto ToCond = importChecked(Err, S->getCond());
7267 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7268 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7269 auto ToThen = importChecked(Err, S->getThen());
7270 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7271 auto ToElse = importChecked(Err, S->getElse());
7272 if (Err)
7273 return std::move(Err);
7274
7275 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7276 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7277 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7278}
7279
7281
7282 Error Err = Error::success();
7283 auto ToInit = importChecked(Err, S->getInit());
7284 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7285 auto ToCond = importChecked(Err, S->getCond());
7286 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7287 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7288 auto ToBody = importChecked(Err, S->getBody());
7289 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7290 if (Err)
7291 return std::move(Err);
7292
7293 auto *ToStmt =
7294 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7295 ToCond, ToLParenLoc, ToRParenLoc);
7296 ToStmt->setBody(ToBody);
7297 ToStmt->setSwitchLoc(ToSwitchLoc);
7298
7299 // Now we have to re-chain the cases.
7300 SwitchCase *LastChainedSwitchCase = nullptr;
7301 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7302 SC = SC->getNextSwitchCase()) {
7303 Expected<SwitchCase *> ToSCOrErr = import(SC);
7304 if (!ToSCOrErr)
7305 return ToSCOrErr.takeError();
7306 if (LastChainedSwitchCase)
7307 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7308 else
7309 ToStmt->setSwitchCaseList(*ToSCOrErr);
7310 LastChainedSwitchCase = *ToSCOrErr;
7311 }
7312
7313 return ToStmt;
7314}
7315
7317
7318 Error Err = Error::success();
7319 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7320 auto ToCond = importChecked(Err, S->getCond());
7321 auto ToBody = importChecked(Err, S->getBody());
7322 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7323 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7324 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7325 if (Err)
7326 return std::move(Err);
7327
7328 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7329 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7330}
7331
7333
7334 Error Err = Error::success();
7335 auto ToBody = importChecked(Err, S->getBody());
7336 auto ToCond = importChecked(Err, S->getCond());
7337 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7338 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7339 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7340 if (Err)
7341 return std::move(Err);
7342
7343 return new (Importer.getToContext()) DoStmt(
7344 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7345}
7346
7348
7349 Error Err = Error::success();
7350 auto ToInit = importChecked(Err, S->getInit());
7351 auto ToCond = importChecked(Err, S->getCond());
7352 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7353 auto ToInc = importChecked(Err, S->getInc());
7354 auto ToBody = importChecked(Err, S->getBody());
7355 auto ToForLoc = importChecked(Err, S->getForLoc());
7356 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7357 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7358 if (Err)
7359 return std::move(Err);
7360
7361 return new (Importer.getToContext()) ForStmt(
7362 Importer.getToContext(),
7363 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7364 ToRParenLoc);
7365}
7366
7368
7369 Error Err = Error::success();
7370 auto ToLabel = importChecked(Err, S->getLabel());
7371 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7372 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7373 if (Err)
7374 return std::move(Err);
7375
7376 return new (Importer.getToContext()) GotoStmt(
7377 ToLabel, ToGotoLoc, ToLabelLoc);
7378}
7379
7381
7382 Error Err = Error::success();
7383 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7384 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7385 auto ToTarget = importChecked(Err, S->getTarget());
7386 if (Err)
7387 return std::move(Err);
7388
7389 return new (Importer.getToContext()) IndirectGotoStmt(
7390 ToGotoLoc, ToStarLoc, ToTarget);
7391}
7392
7393template <typename StmtClass>
7395 ASTImporter &Importer, StmtClass *S) {
7396 Error Err = Error::success();
7397 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7398 auto ToLabelLoc = S->hasLabelTarget()
7399 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7400 : SourceLocation();
7401 auto ToDecl = S->hasLabelTarget()
7402 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7403 : nullptr;
7404 if (Err)
7405 return std::move(Err);
7406 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7407}
7408
7412
7416
7418
7419 Error Err = Error::success();
7420 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7421 auto ToRetValue = importChecked(Err, S->getRetValue());
7422 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7423 if (Err)
7424 return std::move(Err);
7425
7426 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7427 ToNRVOCandidate);
7428}
7429
7431
7432 Error Err = Error::success();
7433 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7434 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7435 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7436 if (Err)
7437 return std::move(Err);
7438
7439 return new (Importer.getToContext()) CXXCatchStmt (
7440 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7441}
7442
7444 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7445 if (!ToTryLocOrErr)
7446 return ToTryLocOrErr.takeError();
7447
7448 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7449 if (!ToTryBlockOrErr)
7450 return ToTryBlockOrErr.takeError();
7451
7452 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7453 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7454 CXXCatchStmt *FromHandler = S->getHandler(HI);
7455 if (auto ToHandlerOrErr = import(FromHandler))
7456 ToHandlers[HI] = *ToHandlerOrErr;
7457 else
7458 return ToHandlerOrErr.takeError();
7459 }
7460
7461 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7462 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7463}
7464
7466
7467 Error Err = Error::success();
7468 auto ToInit = importChecked(Err, S->getInit());
7469 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7470 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7471 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7472 auto ToCond = importChecked(Err, S->getCond());
7473 auto ToInc = importChecked(Err, S->getInc());
7474 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7475 auto ToBody = importChecked(Err, S->getBody());
7476 auto ToForLoc = importChecked(Err, S->getForLoc());
7477 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7478 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7479 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7480 if (Err)
7481 return std::move(Err);
7482
7483 return new (Importer.getToContext()) CXXForRangeStmt(
7484 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7485 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7486}
7487
7490 Error Err = Error::success();
7491 auto ToElement = importChecked(Err, S->getElement());
7492 auto ToCollection = importChecked(Err, S->getCollection());
7493 auto ToBody = importChecked(Err, S->getBody());
7494 auto ToForLoc = importChecked(Err, S->getForLoc());
7495 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7496 if (Err)
7497 return std::move(Err);
7498
7499 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7500 ToCollection,
7501 ToBody,
7502 ToForLoc,
7503 ToRParenLoc);
7504}
7505
7507
7508 Error Err = Error::success();
7509 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7510 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7511 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7512 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7513 if (Err)
7514 return std::move(Err);
7515
7516 return new (Importer.getToContext()) ObjCAtCatchStmt (
7517 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7518}
7519
7521 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7522 if (!ToAtFinallyLocOrErr)
7523 return ToAtFinallyLocOrErr.takeError();
7524 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7525 if (!ToAtFinallyStmtOrErr)
7526 return ToAtFinallyStmtOrErr.takeError();
7527 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7528 *ToAtFinallyStmtOrErr);
7529}
7530
7532
7533 Error Err = Error::success();
7534 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7535 auto ToTryBody = importChecked(Err, S->getTryBody());
7536 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7537 if (Err)
7538 return std::move(Err);
7539
7540 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7541 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7542 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7543 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7544 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7545 else
7546 return ToCatchStmtOrErr.takeError();
7547 }
7548
7549 return ObjCAtTryStmt::Create(Importer.getToContext(),
7550 ToAtTryLoc, ToTryBody,
7551 ToCatchStmts.begin(), ToCatchStmts.size(),
7552 ToFinallyStmt);
7553}
7554
7557
7558 Error Err = Error::success();
7559 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7560 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7561 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7562 if (Err)
7563 return std::move(Err);
7564
7565 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7566 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7567}
7568
7570 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7571 if (!ToThrowLocOrErr)
7572 return ToThrowLocOrErr.takeError();
7573 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7574 if (!ToThrowExprOrErr)
7575 return ToThrowExprOrErr.takeError();
7576 return new (Importer.getToContext()) ObjCAtThrowStmt(
7577 *ToThrowLocOrErr, *ToThrowExprOrErr);
7578}
7579
7582 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7583 if (!ToAtLocOrErr)
7584 return ToAtLocOrErr.takeError();
7585 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7586 if (!ToSubStmtOrErr)
7587 return ToSubStmtOrErr.takeError();
7588 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7589 *ToSubStmtOrErr);
7590}
7591
7592//----------------------------------------------------------------------------
7593// Import Expressions
7594//----------------------------------------------------------------------------
7596 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7597 << E->getStmtClassName();
7598 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7599}
7600
7602 Error Err = Error::success();
7603 auto ToType = importChecked(Err, E->getType());
7604 auto BLoc = importChecked(Err, E->getBeginLoc());
7605 auto RParenLoc = importChecked(Err, E->getEndLoc());
7606 if (Err)
7607 return std::move(Err);
7608 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7609 if (!ParentContextOrErr)
7610 return ParentContextOrErr.takeError();
7611
7612 return new (Importer.getToContext())
7613 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7614 RParenLoc, *ParentContextOrErr);
7615}
7616
7618
7619 Error Err = Error::success();
7620 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7621 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7622 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7623 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7624 auto ToType = importChecked(Err, E->getType());
7625 if (Err)
7626 return std::move(Err);
7627
7628 return new (Importer.getToContext()) VAArgExpr(
7629 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7630 E->isMicrosoftABI());
7631}
7632
7634
7635 Error Err = Error::success();
7636 auto ToCond = importChecked(Err, E->getCond());
7637 auto ToLHS = importChecked(Err, E->getLHS());
7638 auto ToRHS = importChecked(Err, E->getRHS());
7639 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7640 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7641 auto ToType = importChecked(Err, E->getType());
7642 if (Err)
7643 return std::move(Err);
7644
7646 ExprObjectKind OK = E->getObjectKind();
7647
7648 // The value of CondIsTrue only matters if the value is not
7649 // condition-dependent.
7650 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7651
7652 return new (Importer.getToContext())
7653 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7654 ToRParenLoc, CondIsTrue);
7655}
7656
7658 Error Err = Error::success();
7659 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7660 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7661 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7662 auto ToType = importChecked(Err, E->getType());
7663 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7664 if (Err)
7665 return std::move(Err);
7666
7668 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7669 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7671}
7672
7674 Error Err = Error::success();
7675 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7676 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7677 auto ToType = importChecked(Err, E->getType());
7678 const unsigned NumSubExprs = E->getNumSubExprs();
7679
7681 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7682 ToSubExprs.resize(NumSubExprs);
7683
7684 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7685 return std::move(Err);
7686
7687 return new (Importer.getToContext()) ShuffleVectorExpr(
7688 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7689}
7690
7692 ExpectedType TypeOrErr = import(E->getType());
7693 if (!TypeOrErr)
7694 return TypeOrErr.takeError();
7695
7696 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7697 if (!BeginLocOrErr)
7698 return BeginLocOrErr.takeError();
7699
7700 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7701}
7702
7705 Error Err = Error::success();
7706 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7707 Expr *ToControllingExpr = nullptr;
7708 TypeSourceInfo *ToControllingType = nullptr;
7709 if (E->isExprPredicate())
7710 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7711 else
7712 ToControllingType = importChecked(Err, E->getControllingType());
7713 assert((ToControllingExpr || ToControllingType) &&
7714 "Either the controlling expr or type must be nonnull");
7715 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7716 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7717 if (Err)
7718 return std::move(Err);
7719
7721 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7722 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7723 return std::move(Err);
7724
7725 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7726 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7727 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7728 return std::move(Err);
7729
7730 const ASTContext &ToCtx = Importer.getToContext();
7731 if (E->isResultDependent()) {
7732 if (ToControllingExpr) {
7734 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7735 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7737 }
7739 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7740 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7742 }
7743
7744 if (ToControllingExpr) {
7746 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7747 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7749 }
7751 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7752 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7754}
7755
7757
7758 Error Err = Error::success();
7759 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7760 auto ToType = importChecked(Err, E->getType());
7761 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7762 if (Err)
7763 return std::move(Err);
7764
7765 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7766 E->getIdentKind(), E->isTransparent(),
7767 ToFunctionName);
7768}
7769
7771
7772 Error Err = Error::success();
7773 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7774 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7775 auto ToDecl = importChecked(Err, E->getDecl());
7776 auto ToLocation = importChecked(Err, E->getLocation());
7777 auto ToType = importChecked(Err, E->getType());
7778 if (Err)
7779 return std::move(Err);
7780
7781 NamedDecl *ToFoundD = nullptr;
7782 if (E->getDecl() != E->getFoundDecl()) {
7783 auto FoundDOrErr = import(E->getFoundDecl());
7784 if (!FoundDOrErr)
7785 return FoundDOrErr.takeError();
7786 ToFoundD = *FoundDOrErr;
7787 }
7788
7789 TemplateArgumentListInfo ToTAInfo;
7790 TemplateArgumentListInfo *ToResInfo = nullptr;
7791 if (E->hasExplicitTemplateArgs()) {
7792 if (Error Err =
7794 E->template_arguments(), ToTAInfo))
7795 return std::move(Err);
7796 ToResInfo = &ToTAInfo;
7797 }
7798
7799 auto *ToE = DeclRefExpr::Create(
7800 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7801 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7802 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7803 if (E->hadMultipleCandidates())
7804 ToE->setHadMultipleCandidates(true);
7805 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7806 return ToE;
7807}
7808
7810 ExpectedType TypeOrErr = import(E->getType());
7811 if (!TypeOrErr)
7812 return TypeOrErr.takeError();
7813
7814 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7815}
7816
7818 ExpectedExpr ToInitOrErr = import(E->getInit());
7819 if (!ToInitOrErr)
7820 return ToInitOrErr.takeError();
7821
7822 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7823 if (!ToEqualOrColonLocOrErr)
7824 return ToEqualOrColonLocOrErr.takeError();
7825
7826 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7827 // List elements from the second, the first is Init itself
7828 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7829 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7830 ToIndexExprs[I - 1] = *ToArgOrErr;
7831 else
7832 return ToArgOrErr.takeError();
7833 }
7834
7835 SmallVector<Designator, 4> ToDesignators(E->size());
7836 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7837 return std::move(Err);
7838
7840 Importer.getToContext(), ToDesignators,
7841 ToIndexExprs, *ToEqualOrColonLocOrErr,
7842 E->usesGNUSyntax(), *ToInitOrErr);
7843}
7844
7847 ExpectedType ToTypeOrErr = import(E->getType());
7848 if (!ToTypeOrErr)
7849 return ToTypeOrErr.takeError();
7850
7851 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7852 if (!ToLocationOrErr)
7853 return ToLocationOrErr.takeError();
7854
7855 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7856 *ToTypeOrErr, *ToLocationOrErr);
7857}
7858
7860 ExpectedType ToTypeOrErr = import(E->getType());
7861 if (!ToTypeOrErr)
7862 return ToTypeOrErr.takeError();
7863
7864 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7865 if (!ToLocationOrErr)
7866 return ToLocationOrErr.takeError();
7867
7869 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7870}
7871
7872
7874 ExpectedType ToTypeOrErr = import(E->getType());
7875 if (!ToTypeOrErr)
7876 return ToTypeOrErr.takeError();
7877
7878 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7879 if (!ToLocationOrErr)
7880 return ToLocationOrErr.takeError();
7881
7883 Importer.getToContext(), E->getValue(), E->isExact(),
7884 *ToTypeOrErr, *ToLocationOrErr);
7885}
7886
7888 auto ToTypeOrErr = import(E->getType());
7889 if (!ToTypeOrErr)
7890 return ToTypeOrErr.takeError();
7891
7892 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7893 if (!ToSubExprOrErr)
7894 return ToSubExprOrErr.takeError();
7895
7896 return new (Importer.getToContext()) ImaginaryLiteral(
7897 *ToSubExprOrErr, *ToTypeOrErr);
7898}
7899
7901 auto ToTypeOrErr = import(E->getType());
7902 if (!ToTypeOrErr)
7903 return ToTypeOrErr.takeError();
7904
7905 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7906 if (!ToLocationOrErr)
7907 return ToLocationOrErr.takeError();
7908
7909 return new (Importer.getToContext()) FixedPointLiteral(
7910 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7911 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7912}
7913
7915 ExpectedType ToTypeOrErr = import(E->getType());
7916 if (!ToTypeOrErr)
7917 return ToTypeOrErr.takeError();
7918
7919 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7920 if (!ToLocationOrErr)
7921 return ToLocationOrErr.takeError();
7922
7923 return new (Importer.getToContext()) CharacterLiteral(
7924 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7925}
7926
7928 ExpectedType ToTypeOrErr = import(E->getType());
7929 if (!ToTypeOrErr)
7930 return ToTypeOrErr.takeError();
7931
7933 if (Error Err = ImportArrayChecked(
7934 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7935 return std::move(Err);
7936
7937 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7938 E->getKind(), E->isPascal(), *ToTypeOrErr,
7939 ToLocations);
7940}
7941
7943
7944 Error Err = Error::success();
7945 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7946 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7947 auto ToType = importChecked(Err, E->getType());
7948 auto ToInitializer = importChecked(Err, E->getInitializer());
7949 if (Err)
7950 return std::move(Err);
7951
7952 return new (Importer.getToContext()) CompoundLiteralExpr(
7953 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7954 ToInitializer, E->isFileScope());
7955}
7956
7958
7959 Error Err = Error::success();
7960 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7961 auto ToType = importChecked(Err, E->getType());
7962 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7963 if (Err)
7964 return std::move(Err);
7965
7967 if (Error Err = ImportArrayChecked(
7968 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7969 ToExprs.begin()))
7970 return std::move(Err);
7971
7972 return new (Importer.getToContext()) AtomicExpr(
7973
7974 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7975}
7976
7978 Error Err = Error::success();
7979 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7980 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7981 auto ToLabel = importChecked(Err, E->getLabel());
7982 auto ToType = importChecked(Err, E->getType());
7983 if (Err)
7984 return std::move(Err);
7985
7986 return new (Importer.getToContext()) AddrLabelExpr(
7987 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7988}
7990 Error Err = Error::success();
7991 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7992 auto ToResult = importChecked(Err, E->getAPValueResult());
7993 if (Err)
7994 return std::move(Err);
7995
7996 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7997}
7999 Error Err = Error::success();
8000 auto ToLParen = importChecked(Err, E->getLParen());
8001 auto ToRParen = importChecked(Err, E->getRParen());
8002 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8003 if (Err)
8004 return std::move(Err);
8005
8006 return new (Importer.getToContext())
8007 ParenExpr(ToLParen, ToRParen, ToSubExpr);
8008}
8009
8011 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
8012 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
8013 return std::move(Err);
8014
8015 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
8016 if (!ToLParenLocOrErr)
8017 return ToLParenLocOrErr.takeError();
8018
8019 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
8020 if (!ToRParenLocOrErr)
8021 return ToRParenLocOrErr.takeError();
8022
8023 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
8024 ToExprs, *ToRParenLocOrErr);
8025}
8026
8028 Error Err = Error::success();
8029 auto ToSubStmt = importChecked(Err, E->getSubStmt());
8030 auto ToType = importChecked(Err, E->getType());
8031 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8032 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8033 if (Err)
8034 return std::move(Err);
8035
8036 return new (Importer.getToContext())
8037 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8038 E->getTemplateDepth());
8039}
8040
8042 Error Err = Error::success();
8043 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8044 auto ToType = importChecked(Err, E->getType());
8045 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8046 if (Err)
8047 return std::move(Err);
8048
8049 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8050 E->hasStoredFPFeatures());
8051 UO->setType(ToType);
8052 UO->setSubExpr(ToSubExpr);
8053 UO->setOpcode(E->getOpcode());
8054 UO->setOperatorLoc(ToOperatorLoc);
8055 UO->setCanOverflow(E->canOverflow());
8056 if (E->hasStoredFPFeatures())
8057 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8058
8059 return UO;
8060}
8061
8063
8065 Error Err = Error::success();
8066 auto ToType = importChecked(Err, E->getType());
8067 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8068 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8069 if (Err)
8070 return std::move(Err);
8071
8072 if (E->isArgumentType()) {
8073 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8074 import(E->getArgumentTypeInfo());
8075 if (!ToArgumentTypeInfoOrErr)
8076 return ToArgumentTypeInfoOrErr.takeError();
8077
8078 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8079 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8080 ToRParenLoc);
8081 }
8082
8083 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8084 if (!ToArgumentExprOrErr)
8085 return ToArgumentExprOrErr.takeError();
8086
8087 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8088 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8089}
8090
8092 Error Err = Error::success();
8093 auto ToLHS = importChecked(Err, E->getLHS());
8094 auto ToRHS = importChecked(Err, E->getRHS());
8095 auto ToType = importChecked(Err, E->getType());
8096 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8097 if (Err)
8098 return std::move(Err);
8099
8101 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8102 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8103 E->getFPFeatures());
8104}
8105
8107 Error Err = Error::success();
8108 auto ToCond = importChecked(Err, E->getCond());
8109 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8110 auto ToLHS = importChecked(Err, E->getLHS());
8111 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8112 auto ToRHS = importChecked(Err, E->getRHS());
8113 auto ToType = importChecked(Err, E->getType());
8114 if (Err)
8115 return std::move(Err);
8116
8117 return new (Importer.getToContext()) ConditionalOperator(
8118 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8119 E->getValueKind(), E->getObjectKind());
8120}
8121
8124 Error Err = Error::success();
8125 auto ToCommon = importChecked(Err, E->getCommon());
8126 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8127 auto ToCond = importChecked(Err, E->getCond());
8128 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8129 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8130 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8131 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8132 auto ToType = importChecked(Err, E->getType());
8133 if (Err)
8134 return std::move(Err);
8135
8136 return new (Importer.getToContext()) BinaryConditionalOperator(
8137 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8138 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8139 E->getObjectKind());
8140}
8141
8144 Error Err = Error::success();
8145 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8146 if (Err)
8147 return std::move(Err);
8148
8149 return new (Importer.getToContext())
8150 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8151}
8152
8154 Error Err = Error::success();
8155 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8156 auto ToQueriedTypeSourceInfo =
8158 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8159 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8160 auto ToType = importChecked(Err, E->getType());
8161 if (Err)
8162 return std::move(Err);
8163
8164 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8165 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8166 ToDimensionExpression, ToEndLoc, ToType);
8167}
8168
8170 Error Err = Error::success();
8171 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8172 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8173 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8174 auto ToType = importChecked(Err, E->getType());
8175 if (Err)
8176 return std::move(Err);
8177
8178 return new (Importer.getToContext()) ExpressionTraitExpr(
8179 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8180 ToEndLoc, ToType);
8181}
8182
8184 Error Err = Error::success();
8185 auto ToLocation = importChecked(Err, E->getLocation());
8186 auto ToType = importChecked(Err, E->getType());
8187 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8188 if (Err)
8189 return std::move(Err);
8190
8191 return new (Importer.getToContext()) OpaqueValueExpr(
8192 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8193}
8194
8196 Error Err = Error::success();
8197 auto ToLHS = importChecked(Err, E->getLHS());
8198 auto ToRHS = importChecked(Err, E->getRHS());
8199 auto ToType = importChecked(Err, E->getType());
8200 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8201 if (Err)
8202 return std::move(Err);
8203
8204 return new (Importer.getToContext()) ArraySubscriptExpr(
8205 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8206 ToRBracketLoc);
8207}
8208
8211 Error Err = Error::success();
8212 auto ToLHS = importChecked(Err, E->getLHS());
8213 auto ToRHS = importChecked(Err, E->getRHS());
8214 auto ToType = importChecked(Err, E->getType());
8215 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8216 auto ToComputationResultType =
8218 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8219 if (Err)
8220 return std::move(Err);
8221
8223 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8224 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8225 E->getFPFeatures(),
8226 ToComputationLHSType, ToComputationResultType);
8227}
8228
8231 CXXCastPath Path;
8232 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8233 if (auto SpecOrErr = import(*I))
8234 Path.push_back(*SpecOrErr);
8235 else
8236 return SpecOrErr.takeError();
8237 }
8238 return Path;
8239}
8240
8242 ExpectedType ToTypeOrErr = import(E->getType());
8243 if (!ToTypeOrErr)
8244 return ToTypeOrErr.takeError();
8245
8246 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8247 if (!ToSubExprOrErr)
8248 return ToSubExprOrErr.takeError();
8249
8250 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8251 if (!ToBasePathOrErr)
8252 return ToBasePathOrErr.takeError();
8253
8255 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8256 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8257}
8258
8260 Error Err = Error::success();
8261 auto ToType = importChecked(Err, E->getType());
8262 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8263 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8264 if (Err)
8265 return std::move(Err);
8266
8267 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8268 if (!ToBasePathOrErr)
8269 return ToBasePathOrErr.takeError();
8270 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8271
8272 switch (E->getStmtClass()) {
8273 case Stmt::CStyleCastExprClass: {
8274 auto *CCE = cast<CStyleCastExpr>(E);
8275 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8276 if (!ToLParenLocOrErr)
8277 return ToLParenLocOrErr.takeError();
8278 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8279 if (!ToRParenLocOrErr)
8280 return ToRParenLocOrErr.takeError();
8282 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8283 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8284 *ToLParenLocOrErr, *ToRParenLocOrErr);
8285 }
8286
8287 case Stmt::CXXFunctionalCastExprClass: {
8288 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8289 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8290 if (!ToLParenLocOrErr)
8291 return ToLParenLocOrErr.takeError();
8292 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8293 if (!ToRParenLocOrErr)
8294 return ToRParenLocOrErr.takeError();
8296 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8297 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8298 *ToLParenLocOrErr, *ToRParenLocOrErr);
8299 }
8300
8301 case Stmt::ObjCBridgedCastExprClass: {
8302 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8303 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8304 if (!ToLParenLocOrErr)
8305 return ToLParenLocOrErr.takeError();
8306 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8307 if (!ToBridgeKeywordLocOrErr)
8308 return ToBridgeKeywordLocOrErr.takeError();
8309 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8310 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8311 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8312 }
8313 case Stmt::BuiltinBitCastExprClass: {
8314 auto *BBC = cast<BuiltinBitCastExpr>(E);
8315 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8316 if (!ToKWLocOrErr)
8317 return ToKWLocOrErr.takeError();
8318 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8319 if (!ToRParenLocOrErr)
8320 return ToRParenLocOrErr.takeError();
8321 return new (Importer.getToContext()) BuiltinBitCastExpr(
8322 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8323 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8324 }
8325 default:
8326 llvm_unreachable("Cast expression of unsupported type!");
8327 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8328 }
8329}
8330
8333 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8334 const OffsetOfNode &FromNode = E->getComponent(I);
8335
8336 SourceLocation ToBeginLoc, ToEndLoc;
8337
8338 if (FromNode.getKind() != OffsetOfNode::Base) {
8339 Error Err = Error::success();
8340 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8341 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8342 if (Err)
8343 return std::move(Err);
8344 }
8345
8346 switch (FromNode.getKind()) {
8348 ToNodes.push_back(
8349 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8350 break;
8351 case OffsetOfNode::Base: {
8352 auto ToBSOrErr = import(FromNode.getBase());
8353 if (!ToBSOrErr)
8354 return ToBSOrErr.takeError();
8355 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8356 break;
8357 }
8358 case OffsetOfNode::Field: {
8359 auto ToFieldOrErr = import(FromNode.getField());
8360 if (!ToFieldOrErr)
8361 return ToFieldOrErr.takeError();
8362 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8363 break;
8364 }
8366 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8367 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8368 break;
8369 }
8370 }
8371 }
8372
8374 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8375 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8376 if (!ToIndexExprOrErr)
8377 return ToIndexExprOrErr.takeError();
8378 ToExprs[I] = *ToIndexExprOrErr;
8379 }
8380
8381 Error Err = Error::success();
8382 auto ToType = importChecked(Err, E->getType());
8383 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8384 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8385 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8386 if (Err)
8387 return std::move(Err);
8388
8389 return OffsetOfExpr::Create(
8390 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8391 ToExprs, ToRParenLoc);
8392}
8393
8395 Error Err = Error::success();
8396 auto ToType = importChecked(Err, E->getType());
8397 auto ToOperand = importChecked(Err, E->getOperand());
8398 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8399 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8400 if (Err)
8401 return std::move(Err);
8402
8403 CanThrowResult ToCanThrow;
8404 if (E->isValueDependent())
8405 ToCanThrow = CT_Dependent;
8406 else
8407 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8408
8409 return new (Importer.getToContext()) CXXNoexceptExpr(
8410 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8411}
8412
8414 Error Err = Error::success();
8415 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8416 auto ToType = importChecked(Err, E->getType());
8417 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8418 if (Err)
8419 return std::move(Err);
8420
8421 return new (Importer.getToContext()) CXXThrowExpr(
8422 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8423}
8424
8426 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8427 if (!ToUsedLocOrErr)
8428 return ToUsedLocOrErr.takeError();
8429
8430 auto ToParamOrErr = import(E->getParam());
8431 if (!ToParamOrErr)
8432 return ToParamOrErr.takeError();
8433
8434 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8435 if (!UsedContextOrErr)
8436 return UsedContextOrErr.takeError();
8437
8438 // Import the default arg if it was not imported yet.
8439 // This is needed because it can happen that during the import of the
8440 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8441 // encountered here. The default argument for a ParmVarDecl is set in the
8442 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8443 // see VisitParmVarDecl).
8444 ParmVarDecl *ToParam = *ToParamOrErr;
8445 if (!ToParam->getDefaultArg()) {
8446 std::optional<ParmVarDecl *> FromParam =
8447 Importer.getImportedFromDecl(ToParam);
8448 assert(FromParam && "ParmVarDecl was not imported?");
8449
8450 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8451 return std::move(Err);
8452 }
8453 Expr *RewrittenInit = nullptr;
8454 if (E->hasRewrittenInit()) {
8455 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8456 if (!ExprOrErr)
8457 return ExprOrErr.takeError();
8458 RewrittenInit = ExprOrErr.get();
8459 }
8460 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8461 *ToParamOrErr, RewrittenInit,
8462 *UsedContextOrErr);
8463}
8464
8467 Error Err = Error::success();
8468 auto ToType = importChecked(Err, E->getType());
8469 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8470 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8471 if (Err)
8472 return std::move(Err);
8473
8474 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8475 ToType, ToTypeSourceInfo, ToRParenLoc);
8476}
8477
8480 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8481 if (!ToSubExprOrErr)
8482 return ToSubExprOrErr.takeError();
8483
8484 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8485 if (!ToDtorOrErr)
8486 return ToDtorOrErr.takeError();
8487
8488 ASTContext &ToCtx = Importer.getToContext();
8489 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8490 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8491}
8492
8494
8496 Error Err = Error::success();
8497 auto ToConstructor = importChecked(Err, E->getConstructor());
8498 auto ToType = importChecked(Err, E->getType());
8499 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8500 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8501 if (Err)
8502 return std::move(Err);
8503
8505 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8506 return std::move(Err);
8507
8509 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8510 ToParenOrBraceRange, E->hadMultipleCandidates(),
8513}
8514
8517 DeclContext *DC, *LexicalDC;
8518 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8519 return std::move(Err);
8520
8521 Error Err = Error::success();
8522 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8523 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8524 if (Err)
8525 return std::move(Err);
8526 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8527
8529 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8530 D->getManglingNumber()))
8531 return To;
8532
8533 To->setLexicalDeclContext(LexicalDC);
8534 LexicalDC->addDeclInternal(To);
8535 return To;
8536}
8537
8540 Error Err = Error::success();
8541 auto ToType = importChecked(Err, E->getType());
8542 Expr *ToTemporaryExpr = importChecked(
8543 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8544 auto ToMaterializedDecl =
8546 if (Err)
8547 return std::move(Err);
8548
8549 if (!ToTemporaryExpr)
8550 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8551
8552 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8553 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8554 ToMaterializedDecl);
8555
8556 return ToMTE;
8557}
8558
8560 Error Err = Error::success();
8561 auto *ToPattern = importChecked(Err, E->getPattern());
8562 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8563 if (Err)
8564 return std::move(Err);
8565
8566 return new (Importer.getToContext())
8567 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8568}
8569
8571 Error Err = Error::success();
8572 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8573 auto ToPack = importChecked(Err, E->getPack());
8574 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8575 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8576 if (Err)
8577 return std::move(Err);
8578
8579 UnsignedOrNone Length = std::nullopt;
8580 if (!E->isValueDependent())
8581 Length = E->getPackLength();
8582
8583 SmallVector<TemplateArgument, 8> ToPartialArguments;
8584 if (E->isPartiallySubstituted()) {
8586 ToPartialArguments))
8587 return std::move(Err);
8588 }
8589
8591 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8592 Length, ToPartialArguments);
8593}
8594
8595
8597 Error Err = Error::success();
8598 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8599 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8600 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8601 auto ToArraySize = importChecked(Err, E->getArraySize());
8602 auto ToInitializer = importChecked(Err, E->getInitializer());
8603 auto ToType = importChecked(Err, E->getType());
8604 auto ToAllocatedTypeSourceInfo =
8606 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8607 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8608 if (Err)
8609 return std::move(Err);
8610
8611 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8612 if (Error Err =
8613 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8614 return std::move(Err);
8615
8616 return CXXNewExpr::Create(
8617 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8618 ToOperatorDelete, E->implicitAllocationParameters(),
8619 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8620 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8621 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8622}
8623
8625 Error Err = Error::success();
8626 auto ToType = importChecked(Err, E->getType());
8627 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8628 auto ToArgument = importChecked(Err, E->getArgument());
8629 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8630 if (Err)
8631 return std::move(Err);
8632
8633 return new (Importer.getToContext()) CXXDeleteExpr(
8634 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8635 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8636 ToBeginLoc);
8637}
8638
8640 Error Err = Error::success();
8641 auto ToType = importChecked(Err, E->getType());
8642 auto ToLocation = importChecked(Err, E->getLocation());
8643 auto ToConstructor = importChecked(Err, E->getConstructor());
8644 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8645 if (Err)
8646 return std::move(Err);
8647
8649 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8650 return std::move(Err);
8651
8653 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8654 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8657 ToParenOrBraceRange);
8659 return ToE;
8660}
8661
8663 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8664 if (!ToSubExprOrErr)
8665 return ToSubExprOrErr.takeError();
8666
8668 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8669 return std::move(Err);
8670
8672 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8673 ToObjects);
8674}
8675
8677 Error Err = Error::success();
8678 auto ToCallee = importChecked(Err, E->getCallee());
8679 auto ToType = importChecked(Err, E->getType());
8680 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8681 if (Err)
8682 return std::move(Err);
8683
8685 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8686 return std::move(Err);
8687
8688 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8689 ToType, E->getValueKind(), ToRParenLoc,
8690 E->getFPFeatures());
8691}
8692
8694 ExpectedType ToTypeOrErr = import(E->getType());
8695 if (!ToTypeOrErr)
8696 return ToTypeOrErr.takeError();
8697
8698 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8699 if (!ToLocationOrErr)
8700 return ToLocationOrErr.takeError();
8701
8702 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8703 *ToTypeOrErr, E->isImplicit());
8704}
8705
8707 ExpectedType ToTypeOrErr = import(E->getType());
8708 if (!ToTypeOrErr)
8709 return ToTypeOrErr.takeError();
8710
8711 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8712 if (!ToLocationOrErr)
8713 return ToLocationOrErr.takeError();
8714
8715 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8716 *ToTypeOrErr, *ToLocationOrErr);
8717}
8718
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 ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8725 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8726 auto ToType = importChecked(Err, E->getType());
8727 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8728 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8729 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8730 if (Err)
8731 return std::move(Err);
8732
8733 DeclAccessPair ToFoundDecl =
8735
8736 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8737
8738 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8739 if (E->hasExplicitTemplateArgs()) {
8740 if (Error Err =
8742 E->template_arguments(), ToTAInfo))
8743 return std::move(Err);
8744 ResInfo = &ToTAInfo;
8745 }
8746
8747 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8748 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8749 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8750 ResInfo, ToType, E->getValueKind(),
8751 E->getObjectKind(), E->isNonOdrUse());
8752}
8753
8756 Error Err = Error::success();
8757 auto ToBase = importChecked(Err, E->getBase());
8758 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8759 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8760 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8761 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8762 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8763 if (Err)
8764 return std::move(Err);
8765
8767 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8768 const IdentifierInfo *ToII = Importer.Import(FromII);
8769 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8770 if (!ToDestroyedTypeLocOrErr)
8771 return ToDestroyedTypeLocOrErr.takeError();
8772 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8773 } else {
8774 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8775 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8776 else
8777 return ToTIOrErr.takeError();
8778 }
8779
8780 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8781 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8782 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8783}
8784
8787 Error Err = Error::success();
8788 auto ToType = importChecked(Err, E->getType());
8789 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8790 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8791 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8792 auto ToFirstQualifierFoundInScope =
8794 if (Err)
8795 return std::move(Err);
8796
8797 Expr *ToBase = nullptr;
8798 if (!E->isImplicitAccess()) {
8799 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8800 ToBase = *ToBaseOrErr;
8801 else
8802 return ToBaseOrErr.takeError();
8803 }
8804
8805 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8806
8807 if (E->hasExplicitTemplateArgs()) {
8808 if (Error Err =
8810 E->template_arguments(), ToTAInfo))
8811 return std::move(Err);
8812 ResInfo = &ToTAInfo;
8813 }
8814 auto ToMember = importChecked(Err, E->getMember());
8815 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8816 if (Err)
8817 return std::move(Err);
8818 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8819
8820 // Import additional name location/type info.
8821 if (Error Err =
8822 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8823 return std::move(Err);
8824
8826 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8827 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8828 ToMemberNameInfo, ResInfo);
8829}
8830
8833 Error Err = Error::success();
8834 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8835 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8836 auto ToDeclName = importChecked(Err, E->getDeclName());
8837 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8838 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8839 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8840 if (Err)
8841 return std::move(Err);
8842
8843 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8844 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8845 return std::move(Err);
8846
8847 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8848 TemplateArgumentListInfo *ResInfo = nullptr;
8849 if (E->hasExplicitTemplateArgs()) {
8850 if (Error Err =
8852 return std::move(Err);
8853 ResInfo = &ToTAInfo;
8854 }
8855
8857 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8858 ToNameInfo, ResInfo);
8859}
8860
8863 Error Err = Error::success();
8864 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8865 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8866 auto ToType = importChecked(Err, E->getType());
8867 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8868 if (Err)
8869 return std::move(Err);
8870
8872 if (Error Err =
8873 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8874 return std::move(Err);
8875
8877 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8878 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8879}
8880
8883 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8884 if (!ToNamingClassOrErr)
8885 return ToNamingClassOrErr.takeError();
8886
8887 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8888 if (!ToQualifierLocOrErr)
8889 return ToQualifierLocOrErr.takeError();
8890
8891 Error Err = Error::success();
8892 auto ToName = importChecked(Err, E->getName());
8893 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8894 if (Err)
8895 return std::move(Err);
8896 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8897
8898 // Import additional name location/type info.
8899 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8900 return std::move(Err);
8901
8902 UnresolvedSet<8> ToDecls;
8903 for (auto *D : E->decls())
8904 if (auto ToDOrErr = import(D))
8905 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8906 else
8907 return ToDOrErr.takeError();
8908
8909 if (E->hasExplicitTemplateArgs()) {
8910 TemplateArgumentListInfo ToTAInfo;
8913 ToTAInfo))
8914 return std::move(Err);
8915
8916 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8917 if (!ToTemplateKeywordLocOrErr)
8918 return ToTemplateKeywordLocOrErr.takeError();
8919
8920 const bool KnownDependent =
8921 (E->getDependence() & ExprDependence::TypeValue) ==
8922 ExprDependence::TypeValue;
8924 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8925 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8926 ToDecls.begin(), ToDecls.end(), KnownDependent,
8927 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8928 }
8929
8931 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8932 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8933 /*KnownDependent=*/E->isTypeDependent(),
8934 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8935}
8936
8939 Error Err = Error::success();
8940 auto ToType = importChecked(Err, E->getType());
8941 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8942 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8943 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8944 auto ToName = importChecked(Err, E->getName());
8945 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8946 if (Err)
8947 return std::move(Err);
8948
8949 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8950 // Import additional name location/type info.
8951 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8952 return std::move(Err);
8953
8954 UnresolvedSet<8> ToDecls;
8955 for (Decl *D : E->decls())
8956 if (auto ToDOrErr = import(D))
8957 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8958 else
8959 return ToDOrErr.takeError();
8960
8961 TemplateArgumentListInfo ToTAInfo;
8962 TemplateArgumentListInfo *ResInfo = nullptr;
8963 if (E->hasExplicitTemplateArgs()) {
8964 TemplateArgumentListInfo FromTAInfo;
8965 E->copyTemplateArgumentsInto(FromTAInfo);
8966 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8967 return std::move(Err);
8968 ResInfo = &ToTAInfo;
8969 }
8970
8971 Expr *ToBase = nullptr;
8972 if (!E->isImplicitAccess()) {
8973 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8974 ToBase = *ToBaseOrErr;
8975 else
8976 return ToBaseOrErr.takeError();
8977 }
8978
8980 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8981 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8982 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8983}
8984
8986 Error Err = Error::success();
8987 auto ToCallee = importChecked(Err, E->getCallee());
8988 auto ToType = importChecked(Err, E->getType());
8989 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8990 if (Err)
8991 return std::move(Err);
8992
8993 unsigned NumArgs = E->getNumArgs();
8994 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8995 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8996 return std::move(Err);
8997
8998 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
9000 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
9001 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
9002 OCE->getADLCallKind());
9003 }
9004
9005 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
9006 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
9007 /*MinNumArgs=*/0, E->getADLCallKind());
9008}
9009
9011 CXXRecordDecl *FromClass = E->getLambdaClass();
9012 auto ToClassOrErr = import(FromClass);
9013 if (!ToClassOrErr)
9014 return ToClassOrErr.takeError();
9015 CXXRecordDecl *ToClass = *ToClassOrErr;
9016
9017 auto ToCallOpOrErr = import(E->getCallOperator());
9018 if (!ToCallOpOrErr)
9019 return ToCallOpOrErr.takeError();
9020
9021 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
9022 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
9023 return std::move(Err);
9024
9025 Error Err = Error::success();
9026 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
9027 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
9028 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9029 if (Err)
9030 return std::move(Err);
9031
9032 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
9033 E->getCaptureDefault(), ToCaptureDefaultLoc,
9035 E->hasExplicitResultType(), ToCaptureInits,
9036 ToEndLoc, E->containsUnexpandedParameterPack());
9037}
9038
9039
9041 Error Err = Error::success();
9042 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9043 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9044 auto ToType = importChecked(Err, E->getType());
9045 if (Err)
9046 return std::move(Err);
9047
9048 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9049 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9050 return std::move(Err);
9051
9052 ASTContext &ToCtx = Importer.getToContext();
9053 InitListExpr *To = new (ToCtx)
9054 InitListExpr(ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc, E->isExplicit());
9055 To->setType(ToType);
9056
9057 if (E->hasArrayFiller()) {
9058 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9059 To->setArrayFiller(*ToFillerOrErr);
9060 else
9061 return ToFillerOrErr.takeError();
9062 }
9063
9064 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9065 if (auto ToFDOrErr = import(FromFD))
9066 To->setInitializedFieldInUnion(*ToFDOrErr);
9067 else
9068 return ToFDOrErr.takeError();
9069 }
9070
9071 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9072 if (auto ToSyntFormOrErr = import(SyntForm))
9073 To->setSyntacticForm(*ToSyntFormOrErr);
9074 else
9075 return ToSyntFormOrErr.takeError();
9076 }
9077
9078 // Copy InitListExprBitfields, which are not handled in the ctor of
9079 // InitListExpr.
9081
9082 return To;
9083}
9084
9087 ExpectedType ToTypeOrErr = import(E->getType());
9088 if (!ToTypeOrErr)
9089 return ToTypeOrErr.takeError();
9090
9091 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9092 if (!ToSubExprOrErr)
9093 return ToSubExprOrErr.takeError();
9094
9095 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9096 *ToTypeOrErr, *ToSubExprOrErr);
9097}
9098
9101 Error Err = Error::success();
9102 auto ToLocation = importChecked(Err, E->getLocation());
9103 auto ToType = importChecked(Err, E->getType());
9104 auto ToConstructor = importChecked(Err, E->getConstructor());
9105 if (Err)
9106 return std::move(Err);
9107
9108 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9109 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9110 E->inheritedFromVBase());
9111}
9112
9114 Error Err = Error::success();
9115 auto ToType = importChecked(Err, E->getType());
9116 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9117 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9118 if (Err)
9119 return std::move(Err);
9120
9121 return new (Importer.getToContext()) ArrayInitLoopExpr(
9122 ToType, ToCommonExpr, ToSubExpr);
9123}
9124
9126 ExpectedType ToTypeOrErr = import(E->getType());
9127 if (!ToTypeOrErr)
9128 return ToTypeOrErr.takeError();
9129 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9130}
9131
9133 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9134 if (!ToBeginLocOrErr)
9135 return ToBeginLocOrErr.takeError();
9136
9137 auto ToFieldOrErr = import(E->getField());
9138 if (!ToFieldOrErr)
9139 return ToFieldOrErr.takeError();
9140
9141 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9142 if (!UsedContextOrErr)
9143 return UsedContextOrErr.takeError();
9144
9145 FieldDecl *ToField = *ToFieldOrErr;
9146 assert(ToField->hasInClassInitializer() &&
9147 "Field should have in-class initializer if there is a default init "
9148 "expression that uses it.");
9149 if (!ToField->getInClassInitializer()) {
9150 // The in-class initializer may be not yet set in "To" AST even if the
9151 // field is already there. This must be set here to make construction of
9152 // CXXDefaultInitExpr work.
9153 auto ToInClassInitializerOrErr =
9154 import(E->getField()->getInClassInitializer());
9155 if (!ToInClassInitializerOrErr)
9156 return ToInClassInitializerOrErr.takeError();
9157 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9158 }
9159
9160 Expr *RewrittenInit = nullptr;
9161 if (E->hasRewrittenInit()) {
9162 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9163 if (!ExprOrErr)
9164 return ExprOrErr.takeError();
9165 RewrittenInit = ExprOrErr.get();
9166 }
9167
9168 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9169 ToField, *UsedContextOrErr, RewrittenInit);
9170}
9171
9173 Error Err = Error::success();
9174 auto ToType = importChecked(Err, E->getType());
9175 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9176 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9177 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9178 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9179 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9180 if (Err)
9181 return std::move(Err);
9182
9184 CastKind CK = E->getCastKind();
9185 auto ToBasePathOrErr = ImportCastPath(E);
9186 if (!ToBasePathOrErr)
9187 return ToBasePathOrErr.takeError();
9188
9189 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9191 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9192 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9193 ToAngleBrackets);
9194 } else if (isa<CXXDynamicCastExpr>(E)) {
9196 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9197 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9198 } else if (isa<CXXReinterpretCastExpr>(E)) {
9200 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9201 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9202 } else if (isa<CXXConstCastExpr>(E)) {
9204 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9205 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9206 } else {
9207 llvm_unreachable("Unknown cast type");
9208 return make_error<ASTImportError>();
9209 }
9210}
9211
9214 Error Err = Error::success();
9215 auto ToType = importChecked(Err, E->getType());
9216 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9217 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9218 auto ToReplacement = importChecked(Err, E->getReplacement());
9219 if (Err)
9220 return std::move(Err);
9221
9222 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9223 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9225 E->getFinal());
9226}
9227
9229 Error Err = Error::success();
9230 auto ToType = importChecked(Err, E->getType());
9231 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9232 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9233 if (Err)
9234 return std::move(Err);
9235
9237 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9238 return std::move(Err);
9239
9240 if (E->isStoredAsBoolean()) {
9241 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9242 // Value is always false.
9243 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9244 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9245 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9246 }
9247 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9248 E->getTrait(), ToArgs, ToEndLoc,
9249 E->getAPValue());
9250}
9251
9253 ExpectedType ToTypeOrErr = import(E->getType());
9254 if (!ToTypeOrErr)
9255 return ToTypeOrErr.takeError();
9256
9257 auto ToSourceRangeOrErr = import(E->getSourceRange());
9258 if (!ToSourceRangeOrErr)
9259 return ToSourceRangeOrErr.takeError();
9260
9261 if (E->isTypeOperand()) {
9262 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9263 return new (Importer.getToContext()) CXXTypeidExpr(
9264 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9265 else
9266 return ToTSIOrErr.takeError();
9267 }
9268
9269 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9270 if (!ToExprOperandOrErr)
9271 return ToExprOperandOrErr.takeError();
9272
9273 return new (Importer.getToContext()) CXXTypeidExpr(
9274 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9275}
9276
9278 Error Err = Error::success();
9279
9280 QualType ToType = importChecked(Err, E->getType());
9281 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9282 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9283 Expr *ToLHS = importChecked(Err, E->getLHS());
9284 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9285 Expr *ToRHS = importChecked(Err, E->getRHS());
9286 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9287
9288 if (Err)
9289 return std::move(Err);
9290
9291 return new (Importer.getToContext())
9292 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9293 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9294}
9295
9297 Error Err = Error::success();
9298 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9299 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9300 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9301
9302 auto Body = importChecked(Err, E->getBody());
9303 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9304 if (Err)
9305 return std::move(Err);
9306 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9307 if (Error Err =
9308 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9309 return std::move(Err);
9311 E->getRequirements().size());
9312 if (Error Err =
9313 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9314 return std::move(Err);
9315 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9316 LParenLoc, LocalParameters, RParenLoc,
9317 Requirements, RBraceLoc);
9318}
9319
9322 Error Err = Error::success();
9323 auto CL = importChecked(Err, E->getConceptReference());
9324 auto CSD = importChecked(Err, E->getSpecializationDecl());
9325 if (Err)
9326 return std::move(Err);
9327 if (E->isValueDependent())
9329 Importer.getToContext(), CL,
9330 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9331 ConstraintSatisfaction Satisfaction;
9332 if (Error Err =
9334 return std::move(Err);
9336 Importer.getToContext(), CL,
9337 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9338}
9339
9342 Error Err = Error::success();
9343 auto ToType = importChecked(Err, E->getType());
9344 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9345 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9346 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9347 if (Err)
9348 return std::move(Err);
9349
9350 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9351 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9352 E->getIndex(), E->getFinal());
9353}
9354
9357 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9358 return std::move(Err);
9359 auto ToSyntOrErr = import(E->getSyntacticForm());
9360 if (!ToSyntOrErr)
9361 return ToSyntOrErr.takeError();
9362 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9363 ToSemantics, E->getResultExprIndex());
9364}
9365
9368 Error Err = Error::success();
9369 auto ToType = importChecked(Err, E->getType());
9370 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9371 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9372 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9373 if (Err)
9374 return std::move(Err);
9375
9376 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9377 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9378 return std::move(Err);
9379 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9380 E->getUserSpecifiedInitExprs().size(),
9381 ToInitLoc, ToBeginLoc, ToEndLoc);
9382}
9383
9385 CXXMethodDecl *FromMethod) {
9386 Error ImportErrors = Error::success();
9387 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9388 if (auto ImportedOrErr = import(FromOverriddenMethod))
9390 (*ImportedOrErr)->getCanonicalDecl()));
9391 else
9392 ImportErrors =
9393 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9394 }
9395 return ImportErrors;
9396}
9397
9399 ASTContext &FromContext, FileManager &FromFileManager,
9400 bool MinimalImport,
9401 std::shared_ptr<ASTImporterSharedState> SharedState)
9402 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9403 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9404 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9405
9406 // Create a default state without the lookup table: LLDB case.
9407 if (!SharedState) {
9408 this->SharedState = std::make_shared<ASTImporterSharedState>();
9409 }
9410
9411 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9412 ToContext.getTranslationUnitDecl();
9413}
9414
9415ASTImporter::~ASTImporter() = default;
9416
9418 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9419 "Try to get field index for non-field.");
9420
9421 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9422 if (!Owner)
9423 return std::nullopt;
9424
9425 unsigned Index = 0;
9426 for (const auto *D : Owner->decls()) {
9427 if (D == F)
9428 return Index;
9429
9431 ++Index;
9432 }
9433
9434 llvm_unreachable("Field was not found in its parent context.");
9435
9436 return std::nullopt;
9437}
9438
9439ASTImporter::FoundDeclsTy
9440ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9441 // We search in the redecl context because of transparent contexts.
9442 // E.g. a simple C language enum is a transparent context:
9443 // enum E { A, B };
9444 // Now if we had a global variable in the TU
9445 // int A;
9446 // then the enum constant 'A' and the variable 'A' violates ODR.
9447 // We can diagnose this only if we search in the redecl context.
9448 DeclContext *ReDC = DC->getRedeclContext();
9449 if (SharedState->getLookupTable()) {
9450 if (ReDC->isNamespace()) {
9451 // Namespaces can be reopened.
9452 // Lookup table does not handle this, we must search here in all linked
9453 // namespaces.
9454 FoundDeclsTy Result;
9455 SmallVector<Decl *, 2> NSChain =
9457 dyn_cast<NamespaceDecl>(ReDC));
9458 for (auto *D : NSChain) {
9460 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9461 Name);
9463 }
9464 return Result;
9465 } else {
9467 SharedState->getLookupTable()->lookup(ReDC, Name);
9468 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9469 }
9470 } else {
9471 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9472 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9473 // We must search by the slow case of localUncachedLookup because that is
9474 // working even if there is no LookupPtr for the DC. We could use
9475 // DC::buildLookup() to create the LookupPtr, but that would load external
9476 // decls again, we must avoid that case.
9477 // Also, even if we had the LookupPtr, we must find Decls which are not
9478 // in the LookupPtr, so we need the slow case.
9479 // These cases are handled in ASTImporterLookupTable, but we cannot use
9480 // that with LLDB since that traverses through the AST which initiates the
9481 // load of external decls again via DC::decls(). And again, we must avoid
9482 // loading external decls during the import.
9483 if (Result.empty())
9484 ReDC->localUncachedLookup(Name, Result);
9485 return Result;
9486 }
9487}
9488
9489void ASTImporter::AddToLookupTable(Decl *ToD) {
9490 SharedState->addDeclToLookup(ToD);
9491}
9492
9494 // Import the decl using ASTNodeImporter.
9495 ASTNodeImporter Importer(*this);
9496 return Importer.Visit(FromD);
9497}
9498
9500 MapImported(FromD, ToD);
9501}
9502
9505 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9506 if (Expected<Expr *> R = Import(CLE))
9508 }
9509
9510 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9511 // ASTNodeImporter.
9512 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9513}
9514
9516 if (!FromT)
9517 return FromT;
9518
9519 // Check whether we've already imported this type.
9520 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9521 ImportedTypes.find(FromT);
9522 if (Pos != ImportedTypes.end())
9523 return Pos->second;
9524
9525 // Import the type.
9526 ASTNodeImporter Importer(*this);
9527 ExpectedType ToTOrErr = Importer.Visit(FromT);
9528 if (!ToTOrErr)
9529 return ToTOrErr.takeError();
9530
9531 // Record the imported type.
9532 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9533
9534 return ToTOrErr->getTypePtr();
9535}
9536
9538 if (FromT.isNull())
9539 return QualType{};
9540
9541 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9542 if (!ToTyOrErr)
9543 return ToTyOrErr.takeError();
9544
9545 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9546}
9547
9549 if (!FromTSI)
9550 return FromTSI;
9551
9552 // FIXME: For now we just create a "trivial" type source info based
9553 // on the type and a single location. Implement a real version of this.
9554 ExpectedType TOrErr = Import(FromTSI->getType());
9555 if (!TOrErr)
9556 return TOrErr.takeError();
9557 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9558 if (!BeginLocOrErr)
9559 return BeginLocOrErr.takeError();
9560
9561 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9562}
9563
9564namespace {
9565// To use this object, it should be created before the new attribute is created,
9566// and destructed after it is created. The construction already performs the
9567// import of the data.
9568template <typename T> struct AttrArgImporter {
9569 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9570 AttrArgImporter(AttrArgImporter<T> &&) = default;
9571 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9572 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9573
9574 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9575 : To(I.importChecked(Err, From)) {}
9576
9577 const T &value() { return To; }
9578
9579private:
9580 T To;
9581};
9582
9583// To use this object, it should be created before the new attribute is created,
9584// and destructed after it is created. The construction already performs the
9585// import of the data. The array data is accessible in a pointer form, this form
9586// is used by the attribute classes. This object should be created once for the
9587// array data to be imported (the array size is not imported, just copied).
9588template <typename T> struct AttrArgArrayImporter {
9589 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9590 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9591 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9592 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9593
9594 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9595 const llvm::iterator_range<T *> &From,
9596 unsigned ArraySize) {
9597 if (Err)
9598 return;
9599 To.reserve(ArraySize);
9600 Err = I.ImportContainerChecked(From, To);
9601 }
9602
9603 T *value() { return To.data(); }
9604
9605private:
9606 llvm::SmallVector<T, 2> To;
9607};
9608
9609class AttrImporter {
9610 Error Err{Error::success()};
9611 Attr *ToAttr = nullptr;
9612 ASTImporter &Importer;
9613 ASTNodeImporter NImporter;
9614
9615public:
9616 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9617
9618 // Useful for accessing the imported attribute.
9619 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9620 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9621
9622 // Create an "importer" for an attribute parameter.
9623 // Result of the 'value()' of that object is to be passed to the function
9624 // 'importAttr', in the order that is expected by the attribute class.
9625 template <class T> AttrArgImporter<T> importArg(const T &From) {
9626 return AttrArgImporter<T>(NImporter, Err, From);
9627 }
9628
9629 // Create an "importer" for an attribute parameter that has array type.
9630 // Result of the 'value()' of that object is to be passed to the function
9631 // 'importAttr', then the size of the array as next argument.
9632 template <typename T>
9633 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9634 unsigned ArraySize) {
9635 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9636 }
9637
9638 // Create an attribute object with the specified arguments.
9639 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9640 // should be values that are passed to the 'Create' function of the attribute.
9641 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9642 // used here.) As much data is copied or imported from the old attribute
9643 // as possible. The passed arguments should be already imported.
9644 // If an import error happens, the internal error is set to it, and any
9645 // further import attempt is ignored.
9646 template <typename T, typename... Arg>
9647 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9648 static_assert(std::is_base_of<Attr, T>::value,
9649 "T should be subclass of Attr.");
9650 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9651
9652 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9653 const IdentifierInfo *ToScopeName =
9654 Importer.Import(FromAttr->getScopeName());
9655 SourceRange ToAttrRange =
9656 NImporter.importChecked(Err, FromAttr->getRange());
9657 SourceLocation ToScopeLoc =
9658 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9659
9660 if (Err)
9661 return;
9662
9663 AttributeCommonInfo ToI(
9664 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9665 FromAttr->getParsedKind(), FromAttr->getForm());
9666 // The "SemanticSpelling" is not needed to be passed to the constructor.
9667 // That value is recalculated from the SpellingListIndex if needed.
9668 ToAttr = T::Create(Importer.getToContext(),
9669 std::forward<Arg>(ImportedArg)..., ToI);
9670
9671 ToAttr->setImplicit(FromAttr->isImplicit());
9672 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9673 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9674 ToInheritableAttr->setInherited(FromAttr->isInherited());
9675 }
9676
9677 // Create a clone of the 'FromAttr' and import its source range only.
9678 // This causes objects with invalid references to be created if the 'FromAttr'
9679 // contains other data that should be imported.
9680 void cloneAttr(const Attr *FromAttr) {
9681 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9682
9683 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9684 if (Err)
9685 return;
9686
9687 ToAttr = FromAttr->clone(Importer.getToContext());
9688 ToAttr->setRange(ToRange);
9689 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9690 }
9691
9692 // Get the result of the previous import attempt (can be used only once).
9693 llvm::Expected<Attr *> getResult() && {
9694 if (Err)
9695 return std::move(Err);
9696 assert(ToAttr && "Attribute should be created.");
9697 return ToAttr;
9698 }
9699};
9700} // namespace
9701
9703 AttrImporter AI(*this);
9704
9705 // FIXME: Is there some kind of AttrVisitor to use here?
9706 switch (FromAttr->getKind()) {
9707 case attr::Aligned: {
9708 auto *From = cast<AlignedAttr>(FromAttr);
9709 if (From->isAlignmentExpr())
9710 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9711 else
9712 AI.importAttr(From, false,
9713 AI.importArg(From->getAlignmentType()).value());
9714 break;
9715 }
9716
9717 case attr::AlignValue: {
9718 auto *From = cast<AlignValueAttr>(FromAttr);
9719 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9720 break;
9721 }
9722
9723 case attr::Format: {
9724 const auto *From = cast<FormatAttr>(FromAttr);
9725 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9726 From->getFirstArg());
9727 break;
9728 }
9729
9730 case attr::EnableIf: {
9731 const auto *From = cast<EnableIfAttr>(FromAttr);
9732 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9733 From->getMessage());
9734 break;
9735 }
9736
9737 case attr::AssertCapability: {
9738 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9739 AI.importAttr(From,
9740 AI.importArrayArg(From->args(), From->args_size()).value(),
9741 From->args_size());
9742 break;
9743 }
9744 case attr::AcquireCapability: {
9745 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9746 AI.importAttr(From,
9747 AI.importArrayArg(From->args(), From->args_size()).value(),
9748 From->args_size());
9749 break;
9750 }
9751 case attr::TryAcquireCapability: {
9752 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9753 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9754 AI.importArrayArg(From->args(), From->args_size()).value(),
9755 From->args_size());
9756 break;
9757 }
9758 case attr::ReleaseCapability: {
9759 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9760 AI.importAttr(From,
9761 AI.importArrayArg(From->args(), From->args_size()).value(),
9762 From->args_size());
9763 break;
9764 }
9765 case attr::RequiresCapability: {
9766 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9767 AI.importAttr(From,
9768 AI.importArrayArg(From->args(), From->args_size()).value(),
9769 From->args_size());
9770 break;
9771 }
9772 case attr::GuardedBy: {
9773 const auto *From = cast<GuardedByAttr>(FromAttr);
9774 AI.importAttr(From,
9775 AI.importArrayArg(From->args(), From->args_size()).value(),
9776 From->args_size());
9777 break;
9778 }
9779 case attr::PtGuardedBy: {
9780 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9781 AI.importAttr(From,
9782 AI.importArrayArg(From->args(), From->args_size()).value(),
9783 From->args_size());
9784 break;
9785 }
9786 case attr::AcquiredAfter: {
9787 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9788 AI.importAttr(From,
9789 AI.importArrayArg(From->args(), From->args_size()).value(),
9790 From->args_size());
9791 break;
9792 }
9793 case attr::AcquiredBefore: {
9794 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9795 AI.importAttr(From,
9796 AI.importArrayArg(From->args(), From->args_size()).value(),
9797 From->args_size());
9798 break;
9799 }
9800 case attr::LockReturned: {
9801 const auto *From = cast<LockReturnedAttr>(FromAttr);
9802 AI.importAttr(From, AI.importArg(From->getArg()).value());
9803 break;
9804 }
9805 case attr::LocksExcluded: {
9806 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9807 AI.importAttr(From,
9808 AI.importArrayArg(From->args(), From->args_size()).value(),
9809 From->args_size());
9810 break;
9811 }
9812 default: {
9813 // The default branch works for attributes that have no arguments to import.
9814 // FIXME: Handle every attribute type that has arguments of type to import
9815 // (most often Expr* or Decl* or type) in the switch above.
9816 AI.cloneAttr(FromAttr);
9817 break;
9818 }
9819 }
9820
9821 return std::move(AI).getResult();
9822}
9823
9825 return ImportedDecls.lookup(FromD);
9826}
9827
9829 auto FromDPos = ImportedFromDecls.find(ToD);
9830 if (FromDPos == ImportedFromDecls.end())
9831 return nullptr;
9832 return FromDPos->second->getTranslationUnitDecl();
9833}
9834
9836 if (!FromD)
9837 return nullptr;
9838
9839 // Push FromD to the stack, and remove that when we return.
9840 ImportPath.push(FromD);
9841 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9842
9843 // Check whether there was a previous failed import.
9844 // If yes return the existing error.
9845 if (auto Error = getImportDeclErrorIfAny(FromD))
9846 return make_error<ASTImportError>(*Error);
9847
9848 // Check whether we've already imported this declaration.
9849 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9850 if (ToD) {
9851 // Already imported (possibly from another TU) and with an error.
9852 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9853 setImportDeclError(FromD, *Error);
9854 return make_error<ASTImportError>(*Error);
9855 }
9856
9857 // If FromD has some updated flags after last import, apply it.
9858 updateFlags(FromD, ToD);
9859 // If we encounter a cycle during an import then we save the relevant part
9860 // of the import path associated to the Decl.
9861 if (ImportPath.hasCycleAtBack())
9862 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9863 return ToD;
9864 }
9865
9866 // Import the declaration.
9867 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9868 if (!ToDOrErr) {
9869 // Failed to import.
9870
9871 auto Pos = ImportedDecls.find(FromD);
9872 bool ToDWasCreated = Pos != ImportedDecls.end();
9873 // Capture the mapped decl before erasing: the iterator is invalidated by
9874 // the erase below under backward-shift deletion, but it is still needed
9875 // further down to record the import error.
9876 Decl *CreatedToD = ToDWasCreated ? Pos->second : nullptr;
9877 if (ToDWasCreated) {
9878 // Import failed after the object was created.
9879 // Remove all references to it.
9880 auto *ToD = CreatedToD;
9881 ImportedDecls.erase(Pos);
9882
9883 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9884 // (e.g. with namespaces) that several decls from the 'from' context are
9885 // mapped to the same decl in the 'to' context. If we removed entries
9886 // from the LookupTable here then we may end up removing them multiple
9887 // times.
9888
9889 // The Lookuptable contains decls only which are in the 'to' context.
9890 // Remove from the Lookuptable only if it is *imported* into the 'to'
9891 // context (and do not remove it if it was added during the initial
9892 // traverse of the 'to' context).
9893 auto PosF = ImportedFromDecls.find(ToD);
9894 if (PosF != ImportedFromDecls.end()) {
9895 // In the case of TypedefNameDecl we create the Decl first and only
9896 // then we import and set its DeclContext. So, the DC might not be set
9897 // when we reach here.
9898 if (ToD->getDeclContext())
9899 SharedState->removeDeclFromLookup(ToD);
9900 ImportedFromDecls.erase(PosF);
9901 }
9902
9903 // FIXME: AST may contain remaining references to the failed object.
9904 // However, the ImportDeclErrors in the shared state contains all the
9905 // failed objects together with their error.
9906 }
9907
9908 // Error encountered for the first time.
9909 // After takeError the error is not usable any more in ToDOrErr.
9910 // Get a copy of the error object (any more simple solution for this?).
9911 ASTImportError ErrOut;
9912 handleAllErrors(ToDOrErr.takeError(),
9913 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9914 setImportDeclError(FromD, ErrOut);
9915 // Set the error for the mapped to Decl, which is in the "to" context.
9916 if (ToDWasCreated)
9917 SharedState->setImportDeclError(CreatedToD, ErrOut);
9918
9919 // Set the error for all nodes which have been created before we
9920 // recognized the error.
9921 for (const auto &Path : SavedImportPaths[FromD]) {
9922 // The import path contains import-dependency nodes first.
9923 // Save the node that was imported as dependency of the current node.
9924 Decl *PrevFromDi = FromD;
9925 for (Decl *FromDi : Path) {
9926 // Begin and end of the path equals 'FromD', skip it.
9927 if (FromDi == FromD)
9928 continue;
9929 // We should not set import error on a node and all following nodes in
9930 // the path if child import errors are ignored.
9931 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9932 PrevFromDi))
9933 break;
9934 PrevFromDi = FromDi;
9935 setImportDeclError(FromDi, ErrOut);
9936 //FIXME Should we remove these Decls from ImportedDecls?
9937 // Set the error for the mapped to Decl, which is in the "to" context.
9938 auto Ii = ImportedDecls.find(FromDi);
9939 if (Ii != ImportedDecls.end())
9940 SharedState->setImportDeclError(Ii->second, ErrOut);
9941 // FIXME Should we remove these Decls from the LookupTable,
9942 // and from ImportedFromDecls?
9943 }
9944 }
9945 SavedImportPaths.erase(FromD);
9946
9947 // Do not return ToDOrErr, error was taken out of it.
9948 return make_error<ASTImportError>(ErrOut);
9949 }
9950
9951 ToD = *ToDOrErr;
9952
9953 // FIXME: Handle the "already imported with error" case. We can get here
9954 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9955 // previously failed create was requested).
9956 // Later GetImportedOrCreateDecl can be updated to return the error.
9957 if (!ToD) {
9958 auto Err = getImportDeclErrorIfAny(FromD);
9959 assert(Err);
9960 return make_error<ASTImportError>(*Err);
9961 }
9962
9963 // We could import from the current TU without error. But previously we
9964 // already had imported a Decl as `ToD` from another TU (with another
9965 // ASTImporter object) and with an error.
9966 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9967 setImportDeclError(FromD, *Error);
9968 return make_error<ASTImportError>(*Error);
9969 }
9970 // Make sure that ImportImpl registered the imported decl.
9971 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9972
9973 if (FromD->hasAttrs())
9974 for (const Attr *FromAttr : FromD->getAttrs()) {
9975 auto ToAttrOrErr = Import(FromAttr);
9976 if (ToAttrOrErr)
9977 ToD->addAttr(*ToAttrOrErr);
9978 else
9979 return ToAttrOrErr.takeError();
9980 }
9981
9982 // Notify subclasses.
9983 Imported(FromD, ToD);
9984
9985 updateFlags(FromD, ToD);
9986 SavedImportPaths.erase(FromD);
9987 return ToDOrErr;
9988}
9989
9992 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9993}
9994
9996 if (!FromDC)
9997 return FromDC;
9998
9999 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
10000 if (!ToDCOrErr)
10001 return ToDCOrErr.takeError();
10002 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
10003
10004 // When we're using a record/enum/Objective-C class/protocol as a context, we
10005 // need it to have a definition.
10006 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
10007 auto *FromRecord = cast<RecordDecl>(FromDC);
10008 if (ToRecord->isCompleteDefinition())
10009 return ToDC;
10010
10011 // If FromRecord is not defined we need to force it to be.
10012 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
10013 // it will start the definition but we never finish it.
10014 // If there are base classes they won't be imported and we will
10015 // be missing anything that we inherit from those bases.
10016 if (FromRecord->getASTContext().getExternalSource() &&
10017 !FromRecord->isCompleteDefinition())
10018 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
10019
10020 if (FromRecord->isCompleteDefinition())
10021 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10022 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
10023 return std::move(Err);
10024 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
10025 auto *FromEnum = cast<EnumDecl>(FromDC);
10026 if (ToEnum->isCompleteDefinition()) {
10027 // Do nothing.
10028 } else if (FromEnum->isCompleteDefinition()) {
10029 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10030 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
10031 return std::move(Err);
10032 } else {
10033 CompleteDecl(ToEnum);
10034 }
10035 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
10036 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
10037 if (ToClass->getDefinition()) {
10038 // Do nothing.
10039 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
10040 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10041 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10042 return std::move(Err);
10043 } else {
10044 CompleteDecl(ToClass);
10045 }
10046 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10047 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10048 if (ToProto->getDefinition()) {
10049 // Do nothing.
10050 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10051 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10052 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10053 return std::move(Err);
10054 } else {
10055 CompleteDecl(ToProto);
10056 }
10057 }
10058
10059 return ToDC;
10060}
10061
10063 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10064 return cast_or_null<Expr>(*ToSOrErr);
10065 else
10066 return ToSOrErr.takeError();
10067}
10068
10070 if (!FromS)
10071 return nullptr;
10072
10073 // Check whether we've already imported this statement.
10074 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10075 if (Pos != ImportedStmts.end())
10076 return Pos->second;
10077
10078 // Import the statement.
10079 ASTNodeImporter Importer(*this);
10080 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10081 if (!ToSOrErr)
10082 return ToSOrErr;
10083
10084 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10085 auto *FromE = cast<Expr>(FromS);
10086 // Copy ExprBitfields, which may not be handled in Expr subclasses
10087 // constructors.
10088 ToE->setValueKind(FromE->getValueKind());
10089 ToE->setObjectKind(FromE->getObjectKind());
10090 ToE->setDependence(FromE->getDependence());
10091 }
10092
10093 // Record the imported statement object.
10094 ImportedStmts[FromS] = *ToSOrErr;
10095 return ToSOrErr;
10096}
10097
10099 switch (FromNNS.getKind()) {
10102 return FromNNS;
10104 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10105 auto NSOrErr = Import(Namespace);
10106 if (!NSOrErr)
10107 return NSOrErr.takeError();
10108 auto PrefixOrErr = Import(Prefix);
10109 if (!PrefixOrErr)
10110 return PrefixOrErr.takeError();
10111 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10112 *PrefixOrErr);
10113 }
10115 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10116 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10117 else
10118 return RDOrErr.takeError();
10120 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10121 return NestedNameSpecifier(*TyOrErr);
10122 } else {
10123 return TyOrErr.takeError();
10124 }
10125 }
10126 llvm_unreachable("Invalid nested name specifier kind");
10127}
10128
10131 // Copied from NestedNameSpecifier mostly.
10133 NestedNameSpecifierLoc NNS = FromNNS;
10134
10135 // Push each of the nested-name-specifiers's onto a stack for
10136 // serialization in reverse order.
10137 while (NNS) {
10138 NestedNames.push_back(NNS);
10139 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10140 }
10141
10143
10144 while (!NestedNames.empty()) {
10145 NNS = NestedNames.pop_back_val();
10146 NestedNameSpecifier Spec = std::nullopt;
10147 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10148 return std::move(Err);
10149
10150 NestedNameSpecifier::Kind Kind = Spec.getKind();
10151
10152 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10154 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10155 return std::move(Err);
10156
10158 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10159 return std::move(Err);
10160 }
10161
10162 switch (Kind) {
10164 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10165 ToLocalBeginLoc, ToLocalEndLoc);
10166 break;
10167
10169 SourceLocation ToTLoc;
10170 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10171 return std::move(Err);
10173 QualType(Spec.getAsType(), 0), ToTLoc);
10174 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10175 break;
10176 }
10177
10179 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10180 break;
10181
10183 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10184 if (!ToSourceRangeOrErr)
10185 return ToSourceRangeOrErr.takeError();
10186
10187 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10188 ToSourceRangeOrErr->getBegin(),
10189 ToSourceRangeOrErr->getEnd());
10190 break;
10191 }
10193 llvm_unreachable("unexpected null nested name specifier");
10194 }
10195 }
10196
10197 return Builder.getWithLocInContext(getToContext());
10198}
10199
10201 switch (From.getKind()) {
10203 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10204 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10205 else
10206 return ToTemplateOrErr.takeError();
10207
10210 UnresolvedSet<2> ToTemplates;
10211 for (auto *I : *FromStorage) {
10212 if (auto ToOrErr = Import(I))
10213 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10214 else
10215 return ToOrErr.takeError();
10216 }
10217 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10218 ToTemplates.end());
10219 }
10220
10223 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10224 if (!DeclNameOrErr)
10225 return DeclNameOrErr.takeError();
10226 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10227 }
10228
10231 auto QualifierOrErr = Import(QTN->getQualifier());
10232 if (!QualifierOrErr)
10233 return QualifierOrErr.takeError();
10234 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10235 if (!TNOrErr)
10236 return TNOrErr.takeError();
10237 return ToContext.getQualifiedTemplateName(
10238 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10239 }
10240
10243 auto QualifierOrErr = Import(DTN->getQualifier());
10244 if (!QualifierOrErr)
10245 return QualifierOrErr.takeError();
10246 return ToContext.getDependentTemplateName(
10247 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10248 }
10249
10253 auto ReplacementOrErr = Import(Subst->getReplacement());
10254 if (!ReplacementOrErr)
10255 return ReplacementOrErr.takeError();
10256
10257 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10258 if (!AssociatedDeclOrErr)
10259 return AssociatedDeclOrErr.takeError();
10260
10261 return ToContext.getSubstTemplateTemplateParm(
10262 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10263 Subst->getPackIndex(), Subst->getFinal());
10264 }
10265
10269 ASTNodeImporter Importer(*this);
10270 auto ArgPackOrErr =
10271 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10272 if (!ArgPackOrErr)
10273 return ArgPackOrErr.takeError();
10274
10275 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10276 if (!AssociatedDeclOrErr)
10277 return AssociatedDeclOrErr.takeError();
10278
10279 return ToContext.getSubstTemplateTemplateParmPack(
10280 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10281 SubstPack->getFinal());
10282 }
10284 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10285 if (!UsingOrError)
10286 return UsingOrError.takeError();
10287 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10288 }
10290 llvm_unreachable("Unexpected DeducedTemplate");
10291 }
10292
10293 llvm_unreachable("Invalid template name kind");
10294}
10295
10297 if (FromLoc.isInvalid())
10298 return SourceLocation{};
10299
10300 SourceManager &FromSM = FromContext.getSourceManager();
10301 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10302
10303 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10304 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10305 if (!ToFileIDOrErr)
10306 return ToFileIDOrErr.takeError();
10307 SourceManager &ToSM = ToContext.getSourceManager();
10308 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10309}
10310
10312 SourceLocation ToBegin, ToEnd;
10313 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10314 return std::move(Err);
10315 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10316 return std::move(Err);
10317
10318 return SourceRange(ToBegin, ToEnd);
10319}
10320
10322 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10323 if (Pos != ImportedFileIDs.end())
10324 return Pos->second;
10325
10326 SourceManager &FromSM = FromContext.getSourceManager();
10327 SourceManager &ToSM = ToContext.getSourceManager();
10328 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10329
10330 // Map the FromID to the "to" source manager.
10331 FileID ToID;
10332 if (FromSLoc.isExpansion()) {
10333 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10334 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10335 if (!ToSpLoc)
10336 return ToSpLoc.takeError();
10337 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10338 if (!ToExLocS)
10339 return ToExLocS.takeError();
10340 unsigned ExLength = FromSM.getFileIDSize(FromID);
10341 SourceLocation MLoc;
10342 if (FromEx.isMacroArgExpansion()) {
10343 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10344 } else {
10345 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10346 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10347 FromEx.isExpansionTokenRange());
10348 else
10349 return ToExLocE.takeError();
10350 }
10351 ToID = ToSM.getFileID(MLoc);
10352 } else {
10353 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10354
10355 if (!IsBuiltin && !Cache->BufferOverridden) {
10356 // Include location of this file.
10357 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10358 if (!ToIncludeLoc)
10359 return ToIncludeLoc.takeError();
10360
10361 // Every FileID that is not the main FileID needs to have a valid include
10362 // location so that the include chain points to the main FileID. When
10363 // importing the main FileID (which has no include location), we need to
10364 // create a fake include location in the main file to keep this property
10365 // intact.
10366 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10367 if (FromID == FromSM.getMainFileID())
10368 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10369
10370 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10371 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10372 // the disk again
10373 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10374 // than mmap the files several times.
10375 auto Entry =
10376 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10377 // FIXME: The filename may be a virtual name that does probably not
10378 // point to a valid file and we get no Entry here. In this case try with
10379 // the memory buffer below.
10380 if (Entry)
10381 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10382 FromSLoc.getFile().getFileCharacteristic());
10383 }
10384 }
10385
10386 if (ToID.isInvalid() || IsBuiltin) {
10387 // FIXME: We want to re-use the existing MemoryBuffer!
10388 std::optional<llvm::MemoryBufferRef> FromBuf =
10389 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10390 FromSM.getFileManager(), SourceLocation{});
10391 if (!FromBuf)
10392 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10393
10394 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10395 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10396 FromBuf->getBufferIdentifier());
10397 ToID = ToSM.createFileID(std::move(ToBuf),
10398 FromSLoc.getFile().getFileCharacteristic());
10399 }
10400 }
10401
10402 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10403
10404 ImportedFileIDs[FromID] = ToID;
10405 return ToID;
10406}
10407
10409 ExpectedExpr ToExprOrErr = Import(From->getInit());
10410 if (!ToExprOrErr)
10411 return ToExprOrErr.takeError();
10412
10413 auto LParenLocOrErr = Import(From->getLParenLoc());
10414 if (!LParenLocOrErr)
10415 return LParenLocOrErr.takeError();
10416
10417 auto RParenLocOrErr = Import(From->getRParenLoc());
10418 if (!RParenLocOrErr)
10419 return RParenLocOrErr.takeError();
10420
10421 if (From->isBaseInitializer()) {
10422 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10423 if (!ToTInfoOrErr)
10424 return ToTInfoOrErr.takeError();
10425
10426 SourceLocation EllipsisLoc;
10427 if (From->isPackExpansion())
10428 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10429 return std::move(Err);
10430
10431 return new (ToContext) CXXCtorInitializer(
10432 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10433 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10434 } else if (From->isMemberInitializer()) {
10435 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10436 if (!ToFieldOrErr)
10437 return ToFieldOrErr.takeError();
10438
10439 auto MemberLocOrErr = Import(From->getMemberLocation());
10440 if (!MemberLocOrErr)
10441 return MemberLocOrErr.takeError();
10442
10443 return new (ToContext) CXXCtorInitializer(
10444 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10445 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10446 } else if (From->isIndirectMemberInitializer()) {
10447 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10448 if (!ToIFieldOrErr)
10449 return ToIFieldOrErr.takeError();
10450
10451 auto MemberLocOrErr = Import(From->getMemberLocation());
10452 if (!MemberLocOrErr)
10453 return MemberLocOrErr.takeError();
10454
10455 return new (ToContext) CXXCtorInitializer(
10456 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10457 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10458 } else if (From->isDelegatingInitializer()) {
10459 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10460 if (!ToTInfoOrErr)
10461 return ToTInfoOrErr.takeError();
10462
10463 return new (ToContext)
10464 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10465 *ToExprOrErr, *RParenLocOrErr);
10466 } else {
10467 // FIXME: assert?
10468 return make_error<ASTImportError>();
10469 }
10470}
10471
10474 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10475 if (Pos != ImportedCXXBaseSpecifiers.end())
10476 return Pos->second;
10477
10478 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10479 if (!ToSourceRange)
10480 return ToSourceRange.takeError();
10482 if (!ToTSI)
10483 return ToTSI.takeError();
10484 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10485 if (!ToEllipsisLoc)
10486 return ToEllipsisLoc.takeError();
10487 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10488 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10489 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10490 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10491 return Imported;
10492}
10493
10495 ASTNodeImporter Importer(*this);
10496 return Importer.ImportAPValue(FromValue);
10497}
10498
10500 ExpectedDecl ToOrErr = Import(From);
10501 if (!ToOrErr)
10502 return ToOrErr.takeError();
10503 Decl *To = *ToOrErr;
10504
10505 auto *FromDC = cast<DeclContext>(From);
10506 ASTNodeImporter Importer(*this);
10507
10508 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10509 if (!ToRecord->getDefinition()) {
10510 return Importer.ImportDefinition(
10511 cast<RecordDecl>(FromDC), ToRecord,
10513 }
10514 }
10515
10516 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10517 if (!ToEnum->getDefinition()) {
10518 return Importer.ImportDefinition(
10520 }
10521 }
10522
10523 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10524 if (!ToIFace->getDefinition()) {
10525 return Importer.ImportDefinition(
10526 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10528 }
10529 }
10530
10531 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10532 if (!ToProto->getDefinition()) {
10533 return Importer.ImportDefinition(
10534 cast<ObjCProtocolDecl>(FromDC), ToProto,
10536 }
10537 }
10538
10539 return Importer.ImportDeclContext(FromDC, true);
10540}
10541
10543 if (!FromName)
10544 return DeclarationName{};
10545
10546 switch (FromName.getNameKind()) {
10548 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10549
10553 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10554 return DeclarationName(*ToSelOrErr);
10555 else
10556 return ToSelOrErr.takeError();
10557
10559 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10560 return ToContext.DeclarationNames.getCXXConstructorName(
10561 ToContext.getCanonicalType(*ToTyOrErr));
10562 else
10563 return ToTyOrErr.takeError();
10564 }
10565
10567 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10568 return ToContext.DeclarationNames.getCXXDestructorName(
10569 ToContext.getCanonicalType(*ToTyOrErr));
10570 else
10571 return ToTyOrErr.takeError();
10572 }
10573
10575 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10576 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10577 cast<TemplateDecl>(*ToTemplateOrErr));
10578 else
10579 return ToTemplateOrErr.takeError();
10580 }
10581
10583 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10584 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10585 ToContext.getCanonicalType(*ToTyOrErr));
10586 else
10587 return ToTyOrErr.takeError();
10588 }
10589
10591 return ToContext.DeclarationNames.getCXXOperatorName(
10592 FromName.getCXXOverloadedOperator());
10593
10595 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10596 Import(FromName.getCXXLiteralIdentifier()));
10597
10599 // FIXME: STATICS!
10601 }
10602
10603 llvm_unreachable("Invalid DeclarationName Kind!");
10604}
10605
10607 if (!FromId)
10608 return nullptr;
10609
10610 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10611
10612 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10613 ToId->setBuiltinID(FromId->getBuiltinID());
10614
10615 return ToId;
10616}
10617
10620 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10621 return Import(FromII);
10622 return FromIO.getOperator();
10623}
10624
10626 if (FromSel.isNull())
10627 return Selector{};
10628
10630 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10631 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10632 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10633 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10634}
10635
10639 llvm::Error Err = llvm::Error::success();
10640 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10641 for (unsigned Idx = 0; Idx < Size; Idx++) {
10642 APValue Tmp = importChecked(Err, From[Idx]);
10643 To[Idx] = Tmp;
10644 }
10645 };
10646 switch (FromValue.getKind()) {
10647 case APValue::None:
10649 case APValue::Int:
10650 case APValue::Float:
10654 Result = FromValue;
10655 break;
10656 case APValue::Vector: {
10657 Result.MakeVector();
10659 Result.setVectorUninit(FromValue.getVectorLength());
10660 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10661 Elts.data(), FromValue.getVectorLength());
10662 break;
10663 }
10664 case APValue::Matrix:
10665 // Matrix values cannot currently arise in APValue import contexts.
10666 llvm_unreachable("Matrix APValue import not yet supported");
10667 case APValue::Array:
10668 Result.MakeArray(FromValue.getArrayInitializedElts(),
10669 FromValue.getArraySize());
10670 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10671 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10672 FromValue.getArrayInitializedElts());
10673 break;
10674 case APValue::Struct:
10675 Result.MakeStruct(FromValue.getStructNumBases(),
10676 FromValue.getStructNumFields());
10677 ImportLoop(
10678 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10679 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10680 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10681 break;
10682 case APValue::Union: {
10683 Result.MakeUnion();
10684 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10685 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10686 if (Err)
10687 return std::move(Err);
10688 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10689 break;
10690 }
10692 Result.MakeAddrLabelDiff();
10693 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10694 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10695 if (Err)
10696 return std::move(Err);
10697 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10698 cast<AddrLabelExpr>(ImpRHS));
10699 break;
10700 }
10702 const Decl *ImpMemPtrDecl =
10703 importChecked(Err, FromValue.getMemberPointerDecl());
10704 if (Err)
10705 return std::move(Err);
10707 Result.setMemberPointerUninit(
10708 cast<const ValueDecl>(ImpMemPtrDecl),
10710 FromValue.getMemberPointerPath().size());
10711 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10712 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10713 Idx++) {
10714 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10715 if (Err)
10716 return std::move(Err);
10717 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10718 }
10719 break;
10720 }
10721 case APValue::LValue:
10723 QualType FromElemTy;
10724 if (FromValue.getLValueBase()) {
10725 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10726 "in C++20 dynamic allocation are transient so they shouldn't "
10727 "appear in the AST");
10728 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10729 if (const auto *E =
10730 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10731 FromElemTy = E->getType();
10732 const Expr *ImpExpr = importChecked(Err, E);
10733 if (Err)
10734 return std::move(Err);
10735 Base = APValue::LValueBase(ImpExpr,
10736 FromValue.getLValueBase().getCallIndex(),
10737 FromValue.getLValueBase().getVersion());
10738 } else {
10739 FromElemTy =
10740 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10741 const Decl *ImpDecl = importChecked(
10742 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10743 if (Err)
10744 return std::move(Err);
10746 FromValue.getLValueBase().getCallIndex(),
10747 FromValue.getLValueBase().getVersion());
10748 }
10749 } else {
10750 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10751 const Type *ImpTypeInfo = importChecked(
10752 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10753 QualType ImpType =
10754 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10755 if (Err)
10756 return std::move(Err);
10758 ImpType);
10759 }
10760 }
10761 CharUnits Offset = FromValue.getLValueOffset();
10762 unsigned PathLength = FromValue.getLValuePath().size();
10763 Result.MakeLValue();
10764 if (FromValue.hasLValuePath()) {
10765 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10766 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10767 FromValue.isNullPointer());
10769 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10770 if (FromElemTy->isRecordType()) {
10771 const Decl *FromDecl =
10772 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10773 const Decl *ImpDecl = importChecked(Err, FromDecl);
10774 if (Err)
10775 return std::move(Err);
10776 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10777 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10778 else
10779 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10781 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10782 } else {
10783 FromElemTy =
10784 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10785 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10786 FromPath[LoopIdx].getAsArrayIndex());
10787 }
10788 }
10789 } else
10790 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10791 FromValue.isNullPointer());
10792 }
10793 if (Err)
10794 return std::move(Err);
10795 return Result;
10796}
10797
10799 DeclContext *DC,
10800 unsigned IDNS,
10801 NamedDecl **Decls,
10802 unsigned NumDecls) {
10803 if (ODRHandling == ODRHandlingType::Conservative)
10804 // Report error at any name conflict.
10805 return make_error<ASTImportError>(ASTImportError::NameConflict);
10806 else
10807 // Allow to create the new Decl with the same name.
10808 return Name;
10809}
10810
10812 if (LastDiagFromFrom)
10813 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10814 FromContext.getDiagnostics());
10815 LastDiagFromFrom = false;
10816 return ToContext.getDiagnostics().Report(Loc, DiagID);
10817}
10818
10820 if (!LastDiagFromFrom)
10821 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10822 ToContext.getDiagnostics());
10823 LastDiagFromFrom = true;
10824 return FromContext.getDiagnostics().Report(Loc, DiagID);
10825}
10826
10828 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10829 if (!ID->getDefinition())
10830 ID->startDefinition();
10831 }
10832 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10833 if (!PD->getDefinition())
10834 PD->startDefinition();
10835 }
10836 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10837 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10838 TD->startDefinition();
10839 TD->setCompleteDefinition(true);
10840 }
10841 }
10842 else {
10843 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10844 }
10845}
10846
10848 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10849 assert((Inserted || Pos->second == To) &&
10850 "Try to import an already imported Decl");
10851 if (!Inserted)
10852 return Pos->second;
10853 // This mapping should be maintained only in this function. Therefore do not
10854 // check for additional consistency.
10855 ImportedFromDecls[To] = From;
10856 // In the case of TypedefNameDecl we create the Decl first and only then we
10857 // import and set its DeclContext. So, the DC is still not set when we reach
10858 // here from GetImportedOrCreateDecl.
10859 if (To->getDeclContext())
10860 AddToLookupTable(To);
10861 return To;
10862}
10863
10864std::optional<ASTImportError>
10866 auto Pos = ImportDeclErrors.find(FromD);
10867 if (Pos != ImportDeclErrors.end())
10868 return Pos->second;
10869 else
10870 return std::nullopt;
10871}
10872
10874 auto InsertRes = ImportDeclErrors.insert({From, Error});
10875 (void)InsertRes;
10876 // Either we set the error for the first time, or we already had set one and
10877 // now we want to set the same error.
10878 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10879}
10880
10882 bool Complain) {
10883 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10884 ImportedTypes.find(From.getTypePtr());
10885 if (Pos != ImportedTypes.end()) {
10886 if (ExpectedType ToFromOrErr = Import(From)) {
10887 if (ToContext.hasSameType(*ToFromOrErr, To))
10888 return true;
10889 } else {
10890 llvm::consumeError(ToFromOrErr.takeError());
10891 }
10892 }
10893
10895 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10896 getStructuralEquivalenceKind(*this), false, Complain);
10897 return Ctx.IsEquivalent(From, To);
10898}
Defines the clang::ASTContext interface.
#define V(N, I)
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.
Result
Implement __builtin_bit_cast and related operations.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the Objective-C statement AST node classes.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
llvm::APInt getValue() const
unsigned getVersion() const
Definition APValue.cpp:113
QualType getTypeInfoType() const
Definition APValue.cpp:117
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition APValue.cpp:55
unsigned getCallIndex() const
Definition APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition APValue.h:208
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition APValue.h:216
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
const LValueBase getLValueBase() const
Definition APValue.cpp:1015
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1035
const FieldDecl * getUnionField() const
Definition APValue.h:679
unsigned getStructNumFields() const
Definition APValue.h:658
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition APValue.h:205
ValueKind getKind() const
Definition APValue.h:479
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:1020
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1105
unsigned getArrayInitializedElts() const
Definition APValue.h:645
unsigned getStructNumBases() const
Definition APValue.h:654
bool hasLValuePath() const
Definition APValue.cpp:1030
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1098
APValue & getUnionValue()
Definition APValue.h:683
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:699
CharUnits & getLValueOffset()
Definition APValue.cpp:1025
unsigned getVectorLength() const
Definition APValue.h:590
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1112
unsigned getArraySize() const
Definition APValue.h:649
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:129
bool isNullPointer() const
Definition APValue.cpp:1051
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:695
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:228
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
Definition ASTContext.h:960
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
ExpectedDecl VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D)
SourceLocation getColonLoc() const
Definition Expr.h:4384
SourceLocation getQuestionLoc() const
Definition Expr.h:4383
Represents an access specifier followed by colon ':'.
Definition DeclCXX.h:86
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition DeclCXX.h:108
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition Expr.h:4553
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4568
SourceLocation getLabelLoc() const
Definition Expr.h:4570
LabelDecl * getLabel() const
Definition Expr.h:4576
QualType getAdjustedType() const
Definition TypeBase.h:3567
QualType getOriginalType() const
Definition TypeBase.h:3566
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:2724
SourceLocation getRBracketLoc() const
Definition Expr.h:2772
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2753
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:3000
uint64_t getValue() const
Definition ExprCXX.h:3048
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3038
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3040
Expr * getDimensionExpression() const
Definition ExprCXX.h:3050
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3046
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3037
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3784
ArraySizeModifier getSizeModifier() const
Definition TypeBase.h:3798
QualType getElementType() const
Definition TypeBase.h:3796
unsigned getIndexTypeCVRQualifiers() const
Definition TypeBase.h:3806
bool isVolatile() const
Definition Stmt.h:3323
outputs_range outputs()
Definition Stmt.h:3430
SourceLocation getAsmLoc() const
Definition Stmt.h:3317
inputs_range inputs()
Definition Stmt.h:3401
unsigned getNumClobbers() const
Definition Stmt.h:3378
unsigned getNumOutputs() const
Definition Stmt.h:3346
unsigned getNumInputs() const
Definition Stmt.h:3368
bool isSimple() const
Definition Stmt.h:3320
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:6928
Expr ** getSubExprs()
Definition Expr.h:7003
SourceLocation getRParenLoc() const
Definition Expr.h:7057
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5276
AtomicOp getOp() const
Definition Expr.h:6991
SourceLocation getBuiltinLoc() const
Definition Expr.h:7056
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:2213
Stmt * getSubStmt()
Definition Stmt.h:2249
SourceLocation getAttrLoc() const
Definition Stmt.h:2244
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2245
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition Stmt.cpp:441
Represents a C++ declaration that introduces decls from somewhere else.
Definition DeclCXX.h:3501
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3501
shadow_range shadows() const
Definition DeclCXX.h:3567
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4456
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4510
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4494
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4498
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4503
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4491
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
Expr * getLHS() const
Definition Expr.h:4091
SourceLocation getOperatorLoc() const
Definition Expr.h:4083
Expr * getRHS() const
Definition Expr.h:4093
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5102
Opcode getOpcode() const
Definition Expr.h:4086
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4261
A binding in a decomposition declaration.
Definition DeclCXX.h:4190
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4223
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4216
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:4228
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4234
bool isUnsigned() const
Definition TypeBase.h:8307
unsigned getNumBits() const
Definition TypeBase.h:8309
QualType getPointeeType() const
Definition TypeBase.h:3616
decl_range dependent_decls() const
Definition TypeBase.h:3470
QualType desugar() const
Definition TypeBase.h:3460
BreakStmt - This represents a break.
Definition Stmt.h:3145
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5472
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:3226
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:2109
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:1497
CXXTemporary * getTemporary()
Definition ExprCXX.h:1515
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition ExprCXX.cpp:1125
const Expr * getSubExpr() const
Definition ExprCXX.h:1519
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:727
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition ExprCXX.h:739
bool getValue() const
Definition ExprCXX.h:744
SourceLocation getLocation() const
Definition ExprCXX.h:750
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:899
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1733
void setIsImmediateEscalating(bool Set)
Definition ExprCXX.h:1714
bool isElidable() const
Whether this construction is elidable.
Definition ExprCXX.h:1621
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition ExprCXX.h:1626
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:1187
arg_range arguments()
Definition ExprCXX.h:1676
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1645
bool isImmediateEscalating() const
Definition ExprCXX.h:1710
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition ExprCXX.h:1654
SourceLocation getLocation() const
Definition ExprCXX.h:1617
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1615
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1634
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1692
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1663
Represents a C++ constructor within a class.
Definition DeclCXX.h:2620
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2952
Represents a C++ base or member initializer.
Definition DeclCXX.h:2385
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2525
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2485
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2587
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2584
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2495
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2583
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2490
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2519
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2463
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2457
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2469
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2545
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2539
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2511
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1983
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2066
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition ExprCXX.h:1348
const ParmVarDecl * getParam() const
Definition ExprCXX.h:1316
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1344
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1046
bool hasRewrittenInit() const
Definition ExprCXX.h:1319
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1381
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:1100
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1438
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition ExprCXX.h:1426
bool hasRewrittenInit() const
Definition ExprCXX.h:1410
FieldDecl * getField()
Get the field whose initializer will be used.
Definition ExprCXX.h:1415
SourceLocation getBeginLoc() const
Definition ExprCXX.h:1445
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2630
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2669
bool isArrayForm() const
Definition ExprCXX.h:2656
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2680
bool isGlobalDelete() const
Definition ExprCXX.h:2655
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2665
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2657
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:1557
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:2882
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3157
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:813
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:925
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1796
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1792
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1808
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1806
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:183
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:699
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2132
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2800
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2823
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2241
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:379
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:410
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:417
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:413
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2359
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:298
SourceRange getDirectInitRange() const
Definition ExprCXX.h:2613
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2576
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:2473
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2531
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2566
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2465
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2498
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2442
SourceRange getSourceRange() const
Definition ExprCXX.h:2614
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2520
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2560
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2463
bool isGlobalNew() const
Definition ExprCXX.h:2525
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2537
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:772
SourceLocation getLocation() const
Definition ExprCXX.h:786
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL, bool IsReversed=false)
Definition ExprCXX.cpp:629
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:2010
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5193
SourceLocation getInitLoc() const LLVM_READONLY
Definition ExprCXX.h:5195
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5181
ArrayRef< Expr * > getUserSpecifiedInitExprs() const
Definition ExprCXX.h:5187
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5191
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2749
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2843
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2813
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2827
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2834
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2802
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2858
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2831
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2816
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:2850
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition DeclCXX.h:539
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition DeclCXX.cpp:2030
method_range methods() const
Definition DeclCXX.h:650
CXXRecordDecl * getDefinition() const
Definition DeclCXX.h:548
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition DeclCXX.cpp:141
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition DeclCXX.cpp:2060
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2043
void setLambdaContextDecl(Decl *ContextDecl)
Set the context declaration for a lambda class.
Definition DeclCXX.cpp:1840
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2056
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers for a lambda class.
Definition DeclCXX.cpp:1845
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition DeclCXX.cpp:2037
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2071
CXXRecordDecl * getPreviousDecl()
Definition DeclCXX.h:530
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:877
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:290
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:308
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition ExprCXX.h:326
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2200
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2219
SourceLocation getRParenLoc() const
Definition ExprCXX.h:2223
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:787
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:804
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1903
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:1153
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:1932
Represents a C++ temporary.
Definition ExprCXX.h:1463
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition ExprCXX.cpp:1120
Represents the this expression in C++.
Definition ExprCXX.h:1158
bool isImplicit() const
Definition ExprCXX.h:1181
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition ExprCXX.cpp:1592
SourceLocation getLocation() const
Definition ExprCXX.h:1175
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1212
const Expr * getSubExpr() const
Definition ExprCXX.h:1232
SourceLocation getThrowLoc() const
Definition ExprCXX.h:1235
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition ExprCXX.h:1242
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:852
bool isTypeOperand() const
Definition ExprCXX.h:888
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition ExprCXX.h:895
Expr * getExprOperand() const
Definition ExprCXX.h:899
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:906
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:1495
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:2946
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1522
ADLCallKind getADLCallKind() const
Definition Expr.h:3097
Expr * getCallee()
Definition Expr.h:3093
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3245
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3137
arg_range arguments()
Definition Expr.h:3198
SourceLocation getRParenLoc() const
Definition Expr.h:3277
CaseStmt - Represent a case statement.
Definition Stmt.h:1930
Stmt * getSubStmt()
Definition Stmt.h:2043
Expr * getLHS()
Definition Stmt.h:2013
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:1999
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition Stmt.cpp:1306
SourceLocation getCaseLoc() const
Definition Stmt.h:1995
Expr * getRHS()
Definition Stmt.h:2025
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3679
path_iterator path_begin()
Definition Expr.h:3749
CastKind getCastKind() const
Definition Expr.h:3723
path_iterator path_end()
Definition Expr.h:3750
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3799
Expr * getSubExpr()
Definition Expr.h:3729
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1624
unsigned getValue() const
Definition Expr.h:1632
CharacterLiteralKind getKind() const
Definition Expr.h:1625
How to handle import errors that occur when import of a child declaration of a DeclContext fails.
bool ignoreChildErrorOnParent(Decl *FromChildD) const
Determine if import failure of a child does not cause import failure of its parent.
ChildErrorHandlingStrategy(const Decl *FromD)
void handleChildImportResult(Error &ResultErr, Error &&ChildErr)
Process the import result of a child (of the current declaration).
ChildErrorHandlingStrategy(const DeclContext *FromDC)
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4851
SourceLocation getBuiltinLoc() const
Definition Expr.h:4898
Expr * getLHS() const
Definition Expr.h:4893
bool isConditionDependent() const
Definition Expr.h:4881
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4874
Expr * getRHS() const
Definition Expr.h:4895
SourceLocation getRParenLoc() const
Definition Expr.h:4901
Expr * getCond() const
Definition Expr.h:4891
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
QualType getElementType() const
Definition TypeBase.h:3347
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4303
QualType getComputationLHSType() const
Definition Expr.h:4337
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition Expr.cpp:5124
QualType getComputationResultType() const
Definition Expr.h:4340
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3608
SourceLocation getLParenLoc() const
Definition Expr.h:3643
bool isFileScope() const
Definition Expr.h:3640
const Expr * getInitializer() const
Definition Expr.h:3636
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3646
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
unsigned size() const
Definition Stmt.h:1795
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1800
body_range body()
Definition Stmt.h:1813
SourceLocation getLBracLoc() const
Definition Stmt.h:1867
bool hasStoredFPFeatures() const
Definition Stmt.h:1797
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition Stmt.cpp:399
SourceLocation getRBracLoc() const
Definition Stmt.h:1868
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
A reference to a concept and its template args, as it appears in the code.
Definition ASTConcept.h:130
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ASTConcept.h:170
NamedDecl * getFoundDecl() const
Definition ASTConcept.h:197
const DeclarationNameInfo & getConceptNameInfo() const
Definition ASTConcept.h:174
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:203
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
TemplateDecl * getNamedConcept() const
Definition ASTConcept.h:201
SourceLocation getTemplateKWLoc() const
Definition ASTConcept.h:180
Represents the specialization of a concept - evaluates to a prvalue of type bool.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
ConceptReference * getConceptReference() const
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
ConditionalOperator - The ?
Definition Expr.h:4394
Expr * getLHS() const
Definition Expr.h:4428
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4417
Expr * getRHS() const
Definition Expr.h:4429
const Expr * getSizeExpr() const
Return a pointer to the size expression.
Definition TypeBase.h:3918
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition TypeBase.h:3878
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1085
APValue getAPValueResult() const
Definition Expr.cpp:418
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:355
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition TypeBase.h:4468
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition TypeBase.h:4465
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:3682
ContinueStmt - This represents a continue.
Definition Stmt.h:3129
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4722
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4790
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4826
static ConvertVectorExpr * Create(const ASTContext &C, Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5681
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4823
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4815
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4812
bool isCountInBytes() const
Definition TypeBase.h:3525
Expr * getCountExpr() const
Definition TypeBase.h:3524
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:1395
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1462
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h:2590
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2211
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:2202
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:2701
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:2386
bool isFunctionOrMethod() const
Definition DeclBase.h:2174
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition DeclGroup.h:64
iterator begin()
Definition DeclGroup.h:95
bool isNull() const
Definition DeclGroup.h:75
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1273
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1384
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1428
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1477
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1400
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition Expr.cpp:493
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1408
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1366
ValueDecl * getDecl()
Definition Expr.h:1341
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1454
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1471
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1460
SourceLocation getLocation() const
Definition Expr.h:1349
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1416
bool isImmediateEscalating() const
Definition Expr.h:1481
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1641
SourceLocation getEndLoc() const
Definition Stmt.h:1664
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1659
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1667
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:443
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:1239
bool hasAttrs() const
Definition DeclBase.h:526
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:547
void addAttr(Attr *A)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:601
@ FOK_None
Not a friend object.
Definition DeclBase.h:1230
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:1193
void setAccess(AccessSpecifier AS)
Definition DeclBase.h:510
SourceLocation getLocation() const
Definition DeclBase.h:447
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:602
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition DeclBase.h:616
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:576
DeclContext * getDeclContext()
Definition DeclBase.h:456
AccessSpecifier getAccess() const
Definition DeclBase.h:515
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:440
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:439
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:532
AttrVec & getAttrs()
Definition DeclBase.h:532
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:931
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:386
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:991
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:2015
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:4254
SourceLocation getDefaultLoc() const
Definition Stmt.h:2095
Stmt * getSubStmt()
Definition Stmt.h:2091
QualType getPointeeType() const
Definition TypeBase.h:4135
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4136
Expr * getNumBitsExpr() const
Definition Type.cpp:474
bool isUnsigned() const
Definition Type.cpp:470
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:549
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
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4179
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4549
IdentifierOrOverloadedOperator getName() const
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
bool hasTemplateKeyword() const
Was this template name was preceeded by the template keyword?
Expr * getSizeExpr() const
Definition TypeBase.h:4300
VectorKind getVectorKind() const
Definition TypeBase.h:4303
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4302
QualType getElementType() const
Definition TypeBase.h:4301
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:4793
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:4834
A little helper class used to produce diagnostics.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2842
Stmt * getBody()
Definition Stmt.h:2867
Expr * getCond()
Definition Stmt.h:2860
SourceLocation getWhileLoc() const
Definition Stmt.h:2873
SourceLocation getDoLoc() const
Definition Stmt.h:2871
SourceLocation getRParenLoc() const
Definition Stmt.h:2875
Symbolic representation of a dynamic allocation.
Definition APValue.h:65
Represents an empty-declaration.
Definition Decl.h:5197
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3441
llvm::APSInt getInitVal() const
Definition Decl.h:3461
const Expr * getInitExpr() const
Definition Decl.h:3459
Represents an enum.
Definition Decl.h:4029
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4301
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4247
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4239
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4250
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4211
EnumDecl * getMostRecentDecl()
Definition Decl.h:4134
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4256
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5068
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4202
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5128
EnumDecl * getDefinition() const
Definition Decl.h:4141
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4228
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4194
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3931
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3953
Store information needed for an explicit specifier.
Definition DeclCXX.h:1931
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1939
const Expr * getExpr() const
Definition DeclCXX.h:1940
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h: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:1471
This represents one expression.
Definition Expr.h:112
void setType(QualType t)
Definition Expr.h:145
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:447
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:241
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:454
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:223
QualType getType() const
Definition Expr.h:144
ExprDependence getDependence() const
Definition Expr.h:164
An expression trait intrinsic.
Definition ExprCXX.h:3073
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3105
Expr * getQueriedExpression() const
Definition ExprCXX.h:3112
ExpressionTrait getTrait() const
Definition ExprCXX.h:3108
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3106
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:3178
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3278
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4699
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3358
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3352
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4709
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3294
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3402
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4809
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:53
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1584
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1578
SourceLocation getLocation() const
Definition Expr.h:1710
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1081
llvm::APFloat getValue() const
Definition Expr.h:1669
bool isExact() const
Definition Expr.h:1702
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2898
Stmt * getInit()
Definition Stmt.h:2913
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getRParenLoc() const
Definition Stmt.h:2958
Stmt * getBody()
Definition Stmt.h:2942
Expr * getInc()
Definition Stmt.h:2941
SourceLocation getForLoc() const
Definition Stmt.h:2954
Expr * getCond()
Definition Stmt.h:2940
SourceLocation getLParenLoc() const
Definition Stmt.h:2956
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:54
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition DeclFriend.h:58
SourceLocation getFriendLoc() const
Retrieves the location of the 'friend' keyword.
Definition DeclFriend.h:144
SourceLocation getEllipsisLoc() const
Retrieves the location of the '...', if present.
Definition DeclFriend.h:149
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:139
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:125
const Expr * getSubExpr() const
Definition Expr.h:1065
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3114
Represents a function declaration or definition.
Definition Decl.h:2018
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3253
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2494
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4172
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4167
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3272
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3134
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2719
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3525
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2776
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:2927
SourceLocation getDefaultLoc() const
Definition Decl.h:2416
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2792
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2407
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2395
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2466
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4146
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4297
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2420
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2344
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4363
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2034
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2037
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2906
void setTrivial(bool IT)
Definition Decl.h:2396
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2725
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4118
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4185
bool isDeletedAsWritten() const
Definition Decl.h:2562
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:4352
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2371
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:2367
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3529
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2300
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3533
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3537
void setRangeEnd(SourceLocation E)
Definition Decl.h:2236
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2403
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4191
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4391
void setDefaulted(bool D=true)
Definition Decl.h:2404
void setBody(Stmt *B)
Definition Decl.cpp:3265
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2362
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3143
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2412
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4139
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2229
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3173
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:2917
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5369
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5658
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5823
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5809
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:4921
QualType getReturnType() const
Definition TypeBase.h:4905
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3456
unsigned getNumLabels() const
Definition Stmt.h:3606
labels_range labels()
Definition Stmt.h:3629
SourceLocation getRParenLoc() const
Definition Stmt.h:3478
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3571
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3558
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3584
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3547
const Expr * getAsmStringExpr() const
Definition Stmt.h:3483
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3663
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4926
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4943
Represents a C11 generic selection.
Definition Expr.h:6182
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6459
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6479
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6440
SourceLocation getGenericLoc() const
Definition Expr.h:6537
SourceLocation getRParenLoc() const
Definition Expr.h:6541
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6429
SourceLocation getDefaultLoc() const
Definition Expr.h:6540
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:4723
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6436
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6447
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6484
GotoStmt - This represents a direct goto.
Definition Stmt.h:2979
SourceLocation getLabelLoc() const
Definition Stmt.h:2997
SourceLocation getGotoLoc() const
Definition Stmt.h:2995
LabelDecl * getLabel() const
Definition Stmt.h:2992
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:2269
Stmt * getThen()
Definition Stmt.h:2358
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition Stmt.cpp:1044
SourceLocation getIfLoc() const
Definition Stmt.h:2435
IfStatementKind getStatementKind() const
Definition Stmt.h:2470
SourceLocation getElseLoc() const
Definition Stmt.h:2438
Stmt * getInit()
Definition Stmt.h:2419
SourceLocation getLParenLoc() const
Definition Stmt.h:2487
Expr * getCond()
Definition Stmt.h:2346
Stmt * getElse()
Definition Stmt.h:2367
SourceLocation getRParenLoc() const
Definition Stmt.h:2489
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1734
const Expr * getSubExpr() const
Definition Expr.h:1746
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3856
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2078
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1798
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:5071
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3485
unsigned getChainingSize() const
Definition Decl.h:3510
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3506
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3018
SourceLocation getGotoLoc() const
Definition Stmt.h:3034
SourceLocation getStarLoc() const
Definition Stmt.h:3036
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2591
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2604
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2603
Describes an C or C++ initializer list.
Definition Expr.h:5302
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5415
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:5429
unsigned getNumInits() const
Definition Expr.h:5335
SourceLocation getLBraceLoc() const
Definition Expr.h:5460
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2445
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:5405
bool isExplicit() const
Definition Expr.h:5445
SourceLocation getRBraceLoc() const
Definition Expr.h:5462
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5435
ArrayRef< Expr * > inits() const
Definition Expr.h:5355
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:980
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1539
ElaboratedTypeKeyword getKeyword() const
Definition TypeBase.h:6046
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:2156
LabelDecl * getDecl() const
Definition Stmt.h:2174
Stmt * getSubStmt()
Definition Stmt.h:2178
SourceLocation getIdentLoc() const
Definition Stmt.h:2171
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:1271
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:1972
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:1319
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2190
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition ExprCXX.h:2175
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition ExprCXX.h:2123
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2053
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition ExprCXX.cpp:1411
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition ExprCXX.h:2178
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition ExprCXX.h:2030
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2087
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition ExprCXX.h:2025
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1407
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition DeclCXX.h:3313
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3359
Represents a linkage specification.
Definition DeclCXX.h:3020
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3062
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3043
SourceLocation getExternLoc() const
Definition DeclCXX.h:3059
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3060
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3054
Represents the results of name lookup.
Definition Lookup.h:147
iterator end() const
Definition Lookup.h:359
iterator begin() const
Definition Lookup.h:358
QualType getUnderlyingType() const
Definition TypeBase.h:6264
const IdentifierInfo * getMacroIdentifier() const
Definition TypeBase.h:6263
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
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition TypeBase.h:4413
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3367
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3539
SourceLocation getOperatorLoc() const
Definition Expr.h:3549
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3484
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3469
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3450
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3511
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3591
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition Expr.cpp:1755
Expr * getBase() const
Definition Expr.h:3444
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3500
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3492
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3544
bool isArrow() const
Definition Expr.h:3551
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3454
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:3747
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
Definition Type.cpp:5618
QualType getPointeeType() const
Definition TypeBase.h:3733
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:3206
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3267
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3289
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3292
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3295
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3276
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:1713
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1727
SourceLocation getSemiLoc() const
Definition Stmt.h:1724
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:1674
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2329
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:2391
ObjCCategoryImplDecl * getImplementation() const
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2372
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2377
protocol_iterator protocol_end() const
Definition DeclObjC.h:2411
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2414
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2464
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2466
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2421
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2407
void setImplementation(ObjCCategoryImplDecl *ImplD)
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2400
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2460
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2545
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2572
ObjCCategoryDecl * getCategoryDecl() const
SourceLocation getAtStartLoc() const
Definition DeclObjC.h:1096
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
SourceLocation getForLoc() const
Definition StmtObjC.h:52
SourceLocation getRParenLoc() const
Definition StmtObjC.h:54
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2486
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2597
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2744
SourceLocation getSuperClassLoc() const
Definition DeclObjC.h:2737
const ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.h:2735
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2742
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:1485
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition DeclObjC.h:1893
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition DeclObjC.h:1303
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:1392
void setImplementation(ObjCImplementationDecl *ImplD)
known_categories_range known_categories() const
Definition DeclObjC.h:1687
void setSuperClass(TypeSourceInfo *superClass)
Definition DeclObjC.h:1588
protocol_iterator protocol_end() const
Definition DeclObjC.h:1374
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition DeclObjC.cpp:369
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition DeclObjC.h:1523
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition DeclObjC.cpp:340
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:1356
ObjCImplementationDecl * getImplementation() const
protocol_iterator protocol_begin() const
Definition DeclObjC.h:1363
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:1385
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition DeclObjC.cpp:613
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition DeclObjC.h:1915
ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.cpp:349
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition DeclObjC.h:1542
TypeSourceInfo * getSuperClassTInfo() const
Definition DeclObjC.h:1573
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
Definition Type.cpp:988
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1952
AccessControl getAccessControl() const
Definition DeclObjC.h:2000
bool getSynthesize() const
Definition DeclObjC.h:2007
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
ImplicitParamDecl * getSelfDecl() const
Definition DeclObjC.h:418
ArrayRef< ParmVarDecl * > parameters() const
Definition DeclObjC.h:373
unsigned param_size() const
Definition DeclObjC.h:347
bool isPropertyAccessor() const
Definition DeclObjC.h:436
param_const_iterator param_end() const
Definition DeclObjC.h:358
param_const_iterator param_begin() const
Definition DeclObjC.h:354
bool isVariadic() const
Definition DeclObjC.h:431
SourceLocation getEndLoc() const LLVM_READONLY
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition DeclObjC.h:343
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs={})
Sets the method's parameters and selector source locations.
Definition DeclObjC.cpp:941
bool isSynthesizedAccessorStub() const
Definition DeclObjC.h:444
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type.
Definition DeclObjC.h:256
bool isInstanceMethod() const
Definition DeclObjC.h:426
bool isDefined() const
Definition DeclObjC.h:452
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
QualType getReturnType() const
Definition DeclObjC.h:329
ParmVarDecl *const * param_iterator
Definition DeclObjC.h:350
ObjCImplementationControl getImplementationControl() const
Definition DeclObjC.h:500
ObjCInterfaceDecl * getClassInterface()
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition DeclObjC.cpp:935
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition TypeBase.h:8075
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:3556
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition DeclObjC.h:644
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition DeclObjC.h:623
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition DeclObjC.h:633
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:662
SourceLocation getRAngleLoc() const
Definition DeclObjC.h:711
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
SourceLocation getLAngleLoc() const
Definition DeclObjC.h:710
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2530
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2589
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2563
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2577
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1658
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2570
unsigned getNumExpressions() const
Definition Expr.h:2601
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2567
unsigned getNumComponents() const
Definition Expr.h:2585
Helper class for OffsetOfExpr.
Definition Expr.h:2424
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2482
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2488
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1693
@ Array
An index into an array.
Definition Expr.h:2429
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2433
@ Field
A field.
Definition Expr.h:2431
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2436
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2510
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2478
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2511
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2498
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1181
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1231
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1203
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3284
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3266
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3239
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3245
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3258
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3254
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3231
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:3242
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3274
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:2185
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2210
const Expr * getSubExpr() const
Definition Expr.h:2202
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2214
ArrayRef< Expr * > exprs() const
Definition Expr.h:6127
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4974
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6110
SourceLocation getLParenLoc() const
Definition Expr.h:6129
SourceLocation getRParenLoc() const
Definition Expr.h:6130
QualType getInnerType() const
Definition TypeBase.h:3373
Represents a parameter to a function.
Definition Decl.h:1808
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1889
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1868
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1876
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:2996
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1904
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1949
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1937
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3021
bool isObjCMethodParameter() const
Definition Decl.h:1851
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1872
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1841
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1941
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1836
bool hasInheritedDefaultArg() const
Definition Decl.h:1953
void setKNRPromoted(bool promoted)
Definition Decl.h:1892
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1900
Expr * getDefaultArg()
Definition Decl.cpp:2984
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3026
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3032
unsigned getFunctionScopeDepth() const
Definition Decl.h:1858
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1957
QualType getElementType() const
Definition TypeBase.h:8274
bool isReadOnly() const
Definition TypeBase.h:8293
QualType getPointeeType() const
Definition TypeBase.h:3400
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2008
SourceLocation getBeginLoc() const
Definition Expr.h:2073
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:638
bool isTransparent() const
Definition Expr.h:2047
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2043
StringLiteral * getFunctionName()
Definition Expr.h:2052
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2698
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6804
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6846
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5196
ArrayRef< Expr * > semantics()
Definition Expr.h:6876
unsigned getNumSemanticExprs() const
Definition Expr.h:6861
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6841
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:8445
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Definition TypeBase.h:1324
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8477
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:4343
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5220
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4399
field_range fields() const
Definition Decl.h:4546
RecordDecl * getMostRecentDecl()
Definition Decl.h:4369
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5265
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4527
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4395
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:5348
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3651
Represents the body of a requires-expression.
Definition DeclCXX.h:2101
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:3170
SourceLocation getReturnLoc() const
Definition Stmt.h:3219
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3206
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition Stmt.cpp:1290
Expr * getRetValue()
Definition Stmt.h:3197
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4646
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4682
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4679
SourceLocation getRParenLoc() const
Definition Expr.h:4666
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4669
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h: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:1716
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:5020
SourceLocation getBeginLoc() const
Definition Expr.h:5065
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5061
SourceLocation getEndLoc() const
Definition Expr.h:5066
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5040
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4141
bool isFailed() const
Definition DeclCXX.h:4170
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4172
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4598
CompoundStmt * getSubStmt()
Definition Expr.h:4615
unsigned getTemplateDepth() const
Definition Expr.h:4627
SourceLocation getRParenLoc() const
Definition Expr.h:4624
SourceLocation getLParenLoc() const
Definition Expr.h:4622
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:86
child_iterator child_begin()
Definition Stmt.h:1601
StmtClass getStmtClass() const
Definition Stmt.h:1503
child_iterator child_end()
Definition Stmt.h:1602
const char * getStmtClassName() const
Definition Stmt.cpp:86
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1802
bool isPascal() const
Definition Expr.h:1925
tokloc_iterator tokloc_begin() const
Definition Expr.h:1968
tokloc_iterator tokloc_end() const
Definition Expr.h:1972
StringLiteralKind getKind() const
Definition Expr.h:1915
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
Definition Expr.cpp:1193
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1878
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1943
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h: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:1804
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:1905
SourceLocation getColonLoc() const
Definition Stmt.h:1909
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1903
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2519
SourceLocation getSwitchLoc() const
Definition Stmt.h:2654
SourceLocation getLParenLoc() const
Definition Stmt.h:2656
SourceLocation getRParenLoc() const
Definition Stmt.h:2658
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition Stmt.cpp:1167
Expr * getCond()
Definition Stmt.h:2582
Stmt * getBody()
Definition Stmt.h:2594
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2599
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2650
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3735
SourceRange getBraceRange() const
Definition Decl.h:3812
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3856
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4903
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3831
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3836
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:3989
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3972
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4880
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4875
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4917
TagKind getTagKind() const
Definition Decl.h:3935
void setBraceRange(SourceRange R)
Definition Decl.h:3813
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3839
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.
A template parameter object.
const APValue & getValue() const
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:3706
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3724
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:3565
Symbolic representation of typeid(T) for some type T.
Definition APValue.h:44
const Type * getType() const
Definition APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition TypeLoc.cpp:193
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition TypeBase.h:6294
Expr * getUnderlyingExpr() const
Definition TypeBase.h:6291
A container of type source information.
Definition TypeBase.h:8416
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:8427
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2900
bool getBoolValue() const
Definition ExprCXX.h:2951
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2971
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:1919
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2976
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2962
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2943
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2975
const APValue & getAPValue() const
Definition ExprCXX.h:2956
bool isStoredAsBoolean() const
Definition ExprCXX.h:2947
An operation on a type.
Definition TypeVisitor.h:64
The base class of the type hierarchy.
Definition TypeBase.h:1875
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isArrayType() const
Definition TypeBase.h:8781
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9228
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2527
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition TypeBase.h:2471
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9275
bool isRecordType() const
Definition TypeBase.h:8809
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3685
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3580
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3630
QualType getUnderlyingType() const
Definition Decl.h:3635
TypedefNameDecl * getDecl() const
Definition TypeBase.h:6214
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6209
bool typeMatchesDecl() const
Definition TypeBase.h:6222
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2628
SourceLocation getRParenLoc() const
Definition Expr.h:2704
SourceLocation getOperatorLoc() const
Definition Expr.h:2701
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2674
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2660
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2292
Expr * getSubExpr() const
Definition Expr.h:2288
Opcode getOpcode() const
Definition Expr.h:2283
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2384
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2387
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5138
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2301
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h: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:437
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:1659
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:1652
void addDecl(NamedDecl *D)
A set of unresolved declarations.
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6111
UnresolvedUsingTypenameDecl * getDecl() const
Definition TypeBase.h:6117
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4042
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4072
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4076
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4069
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4093
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3945
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3976
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3986
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3993
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4003
Represents a C++ using-declaration.
Definition DeclCXX.h:3596
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3645
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3630
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3637
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3623
Represents C++ using-directive.
Definition DeclCXX.h:3101
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3172
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3342
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3168
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3176
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3179
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3146
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3797
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3821
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3833
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3817
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3878
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3907
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3911
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3404
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3468
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3472
UsingShadowDecl * getDecl() const
Definition TypeBase.h:6157
QualType desugar() const
Definition TypeBase.h:6159
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6153
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4960
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:4984
SourceLocation getBuiltinLoc() const
Definition Expr.h:4987
SourceLocation getRParenLoc() const
Definition Expr.h:4990
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4981
const Expr * getSubExpr() const
Definition Expr.h:4976
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
void setType(QualType newType)
Definition Decl.h:724
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:924
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2768
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1582
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2893
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:2239
bool isInlineSpecified() const
Definition Decl.h:1567
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2345
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2550
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2536
void setInlineSpecified()
Definition Decl.h:1571
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2730
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1355
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1171
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1564
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1175
const Expr * getInit() const
Definition Decl.h:1381
void setConstexpr(bool IC)
Definition Decl.h:1585
void setInit(Expr *I)
Definition Decl.cpp:2456
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2773
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1166
void setImplicitlyInline()
Definition Decl.h:1576
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:1371
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2856
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateDecl * getMostRecentDecl()
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
void setPointOfInstantiation(SourceLocation Loc)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
VarTemplateSpecializationDecl * getMostRecentDecl()
Expr * getSizeExpr() const
Definition TypeBase.h:4042
unsigned getNumElements() const
Definition TypeBase.h:4252
VectorKind getVectorKind() const
Definition TypeBase.h:4257
QualType getElementType() const
Definition TypeBase.h:4251
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2707
Expr * getCond()
Definition Stmt.h:2759
SourceLocation getWhileLoc() const
Definition Stmt.h:2812
SourceLocation getRParenLoc() const
Definition Stmt.h:2817
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1247
SourceLocation getLParenLoc() const
Definition Stmt.h:2815
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition Stmt.cpp:1229
Stmt * getBody()
Definition Stmt.h:2771
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:150
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
OptionalUnsigned< unsigned > UnsignedOrNone
llvm::Expected< QualType > ExpectedType
@ Template
We are parsing a template declaration.
Definition Parser.h:81
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
@ VarTemplate
The name was classified as a variable template name.
Definition Sema.h:585
std::pair< SourceLocation, StringRef > ConstraintSubstitutionDiagnostic
Unsatisfied constraint expressions if the template arguments could be substituted into them,...
Definition ASTConcept.h:40
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:133
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:152
llvm::Expected< Expr * > ExpectedExpr
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition DeclBase.h:1301
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:189
U cast(CodeGen::Address addr)
Definition Address.h:327
bool isLambdaMethod(const DeclContext *DC)
Definition ASTLambda.h:39
llvm::Expected< Stmt * > ExpectedStmt
static void updateFlags(const Decl *From, Decl *To)
unsigned int uint32_t
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
const UnsatisfiedConstraintRecord * end() const
Definition ASTConcept.h:100
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
const UnsatisfiedConstraintRecord * begin() const
Definition ASTConcept.h:96
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
const Expr * ConstraintExpr
Definition Decl.h:88
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
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:885
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:903
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:896
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5438
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5442
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5428
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5431
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5434
Extra information about a function prototype.
Definition TypeBase.h:5454
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