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);
561
564
583
584 // Importing statements
604 // FIXME: MSAsmStmt
605 // FIXME: SEHExceptStmt
606 // FIXME: SEHFinallyStmt
607 // FIXME: SEHTryStmt
608 // FIXME: SEHLeaveStmt
609 // FIXME: CapturedStmt
613 // FIXME: MSDependentExistsStmt
621
622 // Importing expressions
705
706 // Helper for chaining together multiple imports. If an error is detected,
707 // subsequent imports will return default constructed nodes, so that failure
708 // can be detected with a single conditional branch after a sequence of
709 // imports.
710 template <typename T> T importChecked(Error &Err, const T &From) {
711 // Don't attempt to import nodes if we hit an error earlier.
712 if (Err)
713 return T{};
714 Expected<T> MaybeVal = import(From);
715 if (!MaybeVal) {
716 Err = MaybeVal.takeError();
717 return T{};
718 }
719 return *MaybeVal;
720 }
721
722 template<typename IIter, typename OIter>
723 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
724 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
725 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
726 Expected<ItemT> ToOrErr = import(*Ibegin);
727 if (!ToOrErr)
728 return ToOrErr.takeError();
729 *Obegin = *ToOrErr;
730 }
731 return Error::success();
732 }
733
734 // Import every item from a container structure into an output container.
735 // If error occurs, stops at first error and returns the error.
736 // The output container should have space for all needed elements (it is not
737 // expanded, new items are put into from the beginning).
738 template<typename InContainerTy, typename OutContainerTy>
740 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
741 return ImportArrayChecked(
742 InContainer.begin(), InContainer.end(), OutContainer.begin());
743 }
744
745 template<typename InContainerTy, typename OIter>
746 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
747 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
748 }
749
751 CXXMethodDecl *FromMethod);
752
754 FunctionDecl *FromFD);
755
756 // Returns true if the given function has a placeholder return type and
757 // that type is declared inside the body of the function.
758 // E.g. auto f() { struct X{}; return X(); }
760 };
761
762template <typename InContainerTy>
764 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
765 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
766 auto ToLAngleLocOrErr = import(FromLAngleLoc);
767 if (!ToLAngleLocOrErr)
768 return ToLAngleLocOrErr.takeError();
769 auto ToRAngleLocOrErr = import(FromRAngleLoc);
770 if (!ToRAngleLocOrErr)
771 return ToRAngleLocOrErr.takeError();
772
773 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
774 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
775 return Err;
776 Result = std::move(ToTAInfo);
777 return Error::success();
778}
779
780template <>
786
787template <>
795
798 FunctionDecl *FromFD) {
799 assert(FromFD->getTemplatedKind() ==
801
803
804 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
805 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
806 return std::move(Err);
807
808 // Import template arguments.
809 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
810 std::get<1>(Result)))
811 return std::move(Err);
812
813 return Result;
814}
815
816template <>
818ASTNodeImporter::import(TemplateParameterList *From) {
820 if (Error Err = ImportContainerChecked(*From, To))
821 return std::move(Err);
822
823 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
824 if (!ToRequiresClause)
825 return ToRequiresClause.takeError();
826
827 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
828 if (!ToTemplateLocOrErr)
829 return ToTemplateLocOrErr.takeError();
830 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
831 if (!ToLAngleLocOrErr)
832 return ToLAngleLocOrErr.takeError();
833 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
834 if (!ToRAngleLocOrErr)
835 return ToRAngleLocOrErr.takeError();
836
838 Importer.getToContext(),
839 *ToTemplateLocOrErr,
840 *ToLAngleLocOrErr,
841 To,
842 *ToRAngleLocOrErr,
843 *ToRequiresClause);
844}
845
846template <>
848ASTNodeImporter::import(const TemplateArgument &From) {
849 switch (From.getKind()) {
851 return TemplateArgument();
852
854 ExpectedType ToTypeOrErr = import(From.getAsType());
855 if (!ToTypeOrErr)
856 return ToTypeOrErr.takeError();
857 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
858 From.getIsDefaulted());
859 }
860
862 ExpectedType ToTypeOrErr = import(From.getIntegralType());
863 if (!ToTypeOrErr)
864 return ToTypeOrErr.takeError();
865 return TemplateArgument(From, *ToTypeOrErr);
866 }
867
869 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
870 if (!ToOrErr)
871 return ToOrErr.takeError();
872 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
873 if (!ToTypeOrErr)
874 return ToTypeOrErr.takeError();
875 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
876 *ToTypeOrErr, From.getIsDefaulted());
877 }
878
880 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
881 if (!ToTypeOrErr)
882 return ToTypeOrErr.takeError();
883 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
884 From.getIsDefaulted());
885 }
886
888 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
889 if (!ToTypeOrErr)
890 return ToTypeOrErr.takeError();
891 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
892 if (!ToValueOrErr)
893 return ToValueOrErr.takeError();
894 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
895 *ToValueOrErr);
896 }
897
899 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
900 if (!ToTemplateOrErr)
901 return ToTemplateOrErr.takeError();
902
903 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
904 }
905
907 Expected<TemplateName> ToTemplateOrErr =
908 import(From.getAsTemplateOrTemplatePattern());
909 if (!ToTemplateOrErr)
910 return ToTemplateOrErr.takeError();
911
912 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
913 From.getIsDefaulted());
914 }
915
917 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
918 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
919 From.getIsDefaulted());
920 else
921 return ToExpr.takeError();
922
925 ToPack.reserve(From.pack_size());
926 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
927 return std::move(Err);
928
929 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
930 }
931 }
932
933 llvm_unreachable("Invalid template argument kind");
934}
935
936template <>
938ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
939 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
940 if (!ArgOrErr)
941 return ArgOrErr.takeError();
942 TemplateArgument Arg = *ArgOrErr;
943
944 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
945
948 ExpectedExpr E = import(FromInfo.getAsExpr());
949 if (!E)
950 return E.takeError();
951 ToInfo = TemplateArgumentLocInfo(*E);
952 } else if (Arg.getKind() == TemplateArgument::Type) {
953 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
954 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
955 else
956 return TSIOrErr.takeError();
957 } else {
958 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
959 if (!ToTemplateKWLocOrErr)
960 return ToTemplateKWLocOrErr.takeError();
961 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
962 if (!ToTemplateQualifierLocOrErr)
963 return ToTemplateQualifierLocOrErr.takeError();
964 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
965 if (!ToTemplateNameLocOrErr)
966 return ToTemplateNameLocOrErr.takeError();
967 auto ToTemplateEllipsisLocOrErr =
968 import(FromInfo.getTemplateEllipsisLoc());
969 if (!ToTemplateEllipsisLocOrErr)
970 return ToTemplateEllipsisLocOrErr.takeError();
972 Importer.getToContext(), *ToTemplateKWLocOrErr,
973 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
974 *ToTemplateEllipsisLocOrErr);
975 }
976
977 return TemplateArgumentLoc(Arg, ToInfo);
978}
979
980template <>
981Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
982 if (DG.isNull())
983 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
984 size_t NumDecls = DG.end() - DG.begin();
986 ToDecls.reserve(NumDecls);
987 for (Decl *FromD : DG) {
988 if (auto ToDOrErr = import(FromD))
989 ToDecls.push_back(*ToDOrErr);
990 else
991 return ToDOrErr.takeError();
992 }
993 return DeclGroupRef::Create(Importer.getToContext(),
994 ToDecls.begin(),
995 NumDecls);
996}
997
998template <>
1000ASTNodeImporter::import(const Designator &D) {
1001 if (D.isFieldDesignator()) {
1002 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
1003
1004 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
1005 if (!ToDotLocOrErr)
1006 return ToDotLocOrErr.takeError();
1007
1008 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1009 if (!ToFieldLocOrErr)
1010 return ToFieldLocOrErr.takeError();
1011
1013 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1014 }
1015
1016 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1017 if (!ToLBracketLocOrErr)
1018 return ToLBracketLocOrErr.takeError();
1019
1020 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1021 if (!ToRBracketLocOrErr)
1022 return ToRBracketLocOrErr.takeError();
1023
1024 if (D.isArrayDesignator())
1026 *ToLBracketLocOrErr,
1027 *ToRBracketLocOrErr);
1028
1029 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1030 if (!ToEllipsisLocOrErr)
1031 return ToEllipsisLocOrErr.takeError();
1032
1033 assert(D.isArrayRangeDesignator());
1035 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1036 *ToRBracketLocOrErr);
1037}
1038
1039template <>
1040Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1041 Error Err = Error::success();
1042 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1043 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1044 auto ToConceptNameLoc =
1045 importChecked(Err, From->getConceptNameInfo().getLoc());
1046 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1047 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1048 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1049 if (Err)
1050 return std::move(Err);
1051 TemplateArgumentListInfo ToTAInfo;
1052 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1053 if (ASTTemplateArgs)
1054 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1055 return std::move(Err);
1056 auto *ConceptRef = ConceptReference::Create(
1057 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1058 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1059 ToNamedConcept,
1060 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1061 Importer.getToContext(), ToTAInfo)
1062 : nullptr);
1063 return ConceptRef;
1064}
1065
1066StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1067 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1068 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1069 return StringRef(ToStore, FromStr.size());
1070}
1071
1073 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1074 ToSat.IsSatisfied = FromSat.IsSatisfied;
1075 ToSat.ContainsErrors = FromSat.ContainsErrors;
1076 if (!ToSat.IsSatisfied) {
1077 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1078 if (const Expr *E = Record->dyn_cast<const Expr *>()) {
1079 ExpectedExpr ToSecondExpr = import(E);
1080 if (!ToSecondExpr)
1081 return ToSecondExpr.takeError();
1082 ToSat.Details.emplace_back(ToSecondExpr.get());
1083 } else if (auto CR = Record->dyn_cast<const ConceptReference *>()) {
1084 Expected<ConceptReference *> ToCROrErr = import(CR);
1085 if (!ToCROrErr)
1086 return ToCROrErr.takeError();
1087 ToSat.Details.emplace_back(ToCROrErr.get());
1088 } else {
1089 auto Pair =
1090 Record->dyn_cast<const ConstraintSubstitutionDiagnostic *>();
1091
1092 ExpectedSLoc ToPairFirst = import(Pair->first);
1093 if (!ToPairFirst)
1094 return ToPairFirst.takeError();
1095 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1096 ToSat.Details.emplace_back(new (Importer.getToContext())
1098 ToPairFirst.get(), ToPairSecond});
1099 }
1100 }
1101 }
1102 return Error::success();
1103}
1104
1105template <>
1107ASTNodeImporter::import(
1109 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1110 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1111 if (!ToLoc)
1112 return ToLoc.takeError();
1113 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1114 return new (Importer.getToContext())
1116 ToDiagMessage};
1117}
1118
1121 using namespace concepts;
1122
1123 if (From->isSubstitutionFailure()) {
1124 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1125 if (!DiagOrErr)
1126 return DiagOrErr.takeError();
1127 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1128 } else {
1129 Expected<TypeSourceInfo *> ToType = import(From->getType());
1130 if (!ToType)
1131 return ToType.takeError();
1132 return new (Importer.getToContext()) TypeRequirement(*ToType);
1133 }
1134}
1135
1138 using namespace concepts;
1139
1140 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1141 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1142
1143 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1144 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1145
1146 if (IsRKSimple) {
1147 Req.emplace();
1148 } else {
1149 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1151
1152 if (FromTypeRequirement.isTypeConstraint()) {
1153 const bool IsDependent = FromTypeRequirement.isDependent();
1154 auto ParamsOrErr =
1155 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1156 if (!ParamsOrErr)
1157 return ParamsOrErr.takeError();
1158 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1159 auto SubstConstraintExprOrErr =
1161 if (!SubstConstraintExprOrErr)
1162 return SubstConstraintExprOrErr.takeError();
1163 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1164 }
1165 Req.emplace(ParamsOrErr.get(), IsDependent);
1166 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1167 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1168 if (!DiagOrErr)
1169 return DiagOrErr.takeError();
1170 Req.emplace(DiagOrErr.get());
1171 } else {
1172 Req.emplace();
1173 }
1174 }
1175
1176 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1177 if (!NoexceptLocOrErr)
1178 return NoexceptLocOrErr.takeError();
1179
1180 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1181 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1182 if (!DiagOrErr)
1183 return DiagOrErr.takeError();
1184 return new (Importer.getToContext()) ExprRequirement(
1185 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1186 } else {
1187 Expected<Expr *> ExprOrErr = import(From->getExpr());
1188 if (!ExprOrErr)
1189 return ExprOrErr.takeError();
1190 return new (Importer.getToContext()) concepts::ExprRequirement(
1191 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1192 SubstitutedConstraintExpr);
1193 }
1194}
1195
1198 using namespace concepts;
1199
1200 const ASTConstraintSatisfaction &FromSatisfaction =
1202 if (From->hasInvalidConstraint()) {
1203 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1204 ASTConstraintSatisfaction *ToSatisfaction =
1205 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1206 FromSatisfaction);
1207 return new (Importer.getToContext())
1208 NestedRequirement(ToEntity, ToSatisfaction);
1209 } else {
1210 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1211 if (!ToExpr)
1212 return ToExpr.takeError();
1213 if (ToExpr.get()->isInstantiationDependent()) {
1214 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1215 } else {
1216 ConstraintSatisfaction Satisfaction;
1217 if (Error Err =
1218 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1219 return std::move(Err);
1220 return new (Importer.getToContext()) NestedRequirement(
1221 Importer.getToContext(), ToExpr.get(), Satisfaction);
1222 }
1223 }
1224}
1225
1226template <>
1228ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1229 switch (FromRequire->getKind()) {
1238 }
1239 llvm_unreachable("Unhandled requirement kind");
1240}
1241
1242template <>
1243Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1244 ValueDecl *Var = nullptr;
1245 if (From.capturesVariable()) {
1246 if (auto VarOrErr = import(From.getCapturedVar()))
1247 Var = *VarOrErr;
1248 else
1249 return VarOrErr.takeError();
1250 }
1251
1252 auto LocationOrErr = import(From.getLocation());
1253 if (!LocationOrErr)
1254 return LocationOrErr.takeError();
1255
1256 SourceLocation EllipsisLoc;
1257 if (From.isPackExpansion())
1258 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1259 return std::move(Err);
1260
1261 return LambdaCapture(
1262 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1263 EllipsisLoc);
1264}
1265
1266template <typename T>
1268 if (Found->getLinkageInternal() != From->getLinkageInternal())
1269 return false;
1270
1271 if (From->hasExternalFormalLinkage())
1272 return Found->hasExternalFormalLinkage();
1273 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1274 return false;
1275 if (From->isInAnonymousNamespace())
1276 return Found->isInAnonymousNamespace();
1277 else
1278 return !Found->isInAnonymousNamespace() &&
1279 !Found->hasExternalFormalLinkage();
1280}
1281
1282template <>
1284 TypedefNameDecl *From) {
1285 if (Found->getLinkageInternal() != From->getLinkageInternal())
1286 return false;
1287
1288 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1289 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1290 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1291}
1292
1293} // namespace clang
1294
1295//----------------------------------------------------------------------------
1296// Import Types
1297//----------------------------------------------------------------------------
1298
1299using namespace clang;
1300
1302 const FunctionDecl *D) {
1303 const FunctionDecl *LambdaD = nullptr;
1304 if (!isCycle(D) && D) {
1305 FunctionDeclsWithImportInProgress.insert(D);
1306 LambdaD = D;
1307 }
1308 return llvm::scope_exit([this, LambdaD]() {
1309 if (LambdaD) {
1310 FunctionDeclsWithImportInProgress.erase(LambdaD);
1311 }
1312 });
1313}
1314
1316 const FunctionDecl *D) const {
1317 return FunctionDeclsWithImportInProgress.find(D) !=
1318 FunctionDeclsWithImportInProgress.end();
1319}
1320
1322 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1323 << T->getTypeClassName();
1324 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1325}
1326
1327ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1328 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1329 if (!UnderlyingTypeOrErr)
1330 return UnderlyingTypeOrErr.takeError();
1331
1332 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1333}
1334
1335ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1336 switch (T->getKind()) {
1337#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1338 case BuiltinType::Id: \
1339 return Importer.getToContext().SingletonId;
1340#include "clang/Basic/OpenCLImageTypes.def"
1341#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1342 case BuiltinType::Id: \
1343 return Importer.getToContext().Id##Ty;
1344#include "clang/Basic/OpenCLExtensionTypes.def"
1345#define SVE_TYPE(Name, Id, SingletonId) \
1346 case BuiltinType::Id: \
1347 return Importer.getToContext().SingletonId;
1348#include "clang/Basic/AArch64ACLETypes.def"
1349#define PPC_VECTOR_TYPE(Name, Id, Size) \
1350 case BuiltinType::Id: \
1351 return Importer.getToContext().Id##Ty;
1352#include "clang/Basic/PPCTypes.def"
1353#define RVV_TYPE(Name, Id, SingletonId) \
1354 case BuiltinType::Id: \
1355 return Importer.getToContext().SingletonId;
1356#include "clang/Basic/RISCVVTypes.def"
1357#define WASM_TYPE(Name, Id, SingletonId) \
1358 case BuiltinType::Id: \
1359 return Importer.getToContext().SingletonId;
1360#include "clang/Basic/WebAssemblyReferenceTypes.def"
1361#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1362 case BuiltinType::Id: \
1363 return Importer.getToContext().SingletonId;
1364#include "clang/Basic/AMDGPUTypes.def"
1365#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1366 case BuiltinType::Id: \
1367 return Importer.getToContext().SingletonId;
1368#include "clang/Basic/HLSLIntangibleTypes.def"
1369#define SHARED_SINGLETON_TYPE(Expansion)
1370#define BUILTIN_TYPE(Id, SingletonId) \
1371 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1372#include "clang/AST/BuiltinTypes.def"
1373
1374 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1375 // context supports C++.
1376
1377 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1378 // context supports ObjC.
1379
1380 case BuiltinType::Char_U:
1381 // The context we're importing from has an unsigned 'char'. If we're
1382 // importing into a context with a signed 'char', translate to
1383 // 'unsigned char' instead.
1384 if (Importer.getToContext().getLangOpts().CharIsSigned)
1385 return Importer.getToContext().UnsignedCharTy;
1386
1387 return Importer.getToContext().CharTy;
1388
1389 case BuiltinType::Char_S:
1390 // The context we're importing from has an unsigned 'char'. If we're
1391 // importing into a context with a signed 'char', translate to
1392 // 'unsigned char' instead.
1393 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1394 return Importer.getToContext().SignedCharTy;
1395
1396 return Importer.getToContext().CharTy;
1397
1398 case BuiltinType::WChar_S:
1399 case BuiltinType::WChar_U:
1400 // FIXME: If not in C++, shall we translate to the C equivalent of
1401 // wchar_t?
1402 return Importer.getToContext().WCharTy;
1403 }
1404
1405 llvm_unreachable("Invalid BuiltinType Kind!");
1406}
1407
1408ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1409 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1410 if (!ToOriginalTypeOrErr)
1411 return ToOriginalTypeOrErr.takeError();
1412
1413 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1414}
1415
1416ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1417 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1418 if (!ToElementTypeOrErr)
1419 return ToElementTypeOrErr.takeError();
1420
1421 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1422}
1423
1424ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1425 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1426 if (!ToPointeeTypeOrErr)
1427 return ToPointeeTypeOrErr.takeError();
1428
1429 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1430}
1431
1432ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1433 // FIXME: Check for blocks support in "to" context.
1434 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1435 if (!ToPointeeTypeOrErr)
1436 return ToPointeeTypeOrErr.takeError();
1437
1438 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1439}
1440
1442ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1443 // FIXME: Check for C++ support in "to" context.
1444 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1445 if (!ToPointeeTypeOrErr)
1446 return ToPointeeTypeOrErr.takeError();
1447
1448 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1449}
1450
1452ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1453 // FIXME: Check for C++0x support in "to" context.
1454 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1455 if (!ToPointeeTypeOrErr)
1456 return ToPointeeTypeOrErr.takeError();
1457
1458 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1459}
1460
1462ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1463 // FIXME: Check for C++ support in "to" context.
1464 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1465 if (!ToPointeeTypeOrErr)
1466 return ToPointeeTypeOrErr.takeError();
1467
1468 auto QualifierOrErr = import(T->getQualifier());
1469 if (!QualifierOrErr)
1470 return QualifierOrErr.takeError();
1471
1472 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1473 if (!ClsOrErr)
1474 return ClsOrErr.takeError();
1475
1476 return Importer.getToContext().getMemberPointerType(
1477 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1478}
1479
1481ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1482 Error Err = Error::success();
1483 auto ToElementType = importChecked(Err, T->getElementType());
1484 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1485 if (Err)
1486 return std::move(Err);
1487
1488 return Importer.getToContext().getConstantArrayType(
1489 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1491}
1492
1494ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1495 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1496 if (!ToArrayTypeOrErr)
1497 return ToArrayTypeOrErr.takeError();
1498
1499 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1500}
1501
1503ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1504 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1505 if (!ToElementTypeOrErr)
1506 return ToElementTypeOrErr.takeError();
1507
1508 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1509 T->getSizeModifier(),
1511}
1512
1514ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1515 Error Err = Error::success();
1516 QualType ToElementType = importChecked(Err, T->getElementType());
1517 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1518 if (Err)
1519 return std::move(Err);
1520 return Importer.getToContext().getVariableArrayType(
1521 ToElementType, ToSizeExpr, T->getSizeModifier(),
1523}
1524
1525ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1526 const DependentSizedArrayType *T) {
1527 Error Err = Error::success();
1528 QualType ToElementType = importChecked(Err, T->getElementType());
1529 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1530 if (Err)
1531 return std::move(Err);
1532 // SizeExpr may be null if size is not specified directly.
1533 // For example, 'int a[]'.
1534
1535 return Importer.getToContext().getDependentSizedArrayType(
1536 ToElementType, ToSizeExpr, T->getSizeModifier(),
1538}
1539
1540ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1541 const DependentSizedExtVectorType *T) {
1542 Error Err = Error::success();
1543 QualType ToElementType = importChecked(Err, T->getElementType());
1544 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1545 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1546 if (Err)
1547 return std::move(Err);
1548 return Importer.getToContext().getDependentSizedExtVectorType(
1549 ToElementType, ToSizeExpr, ToAttrLoc);
1550}
1551
1552ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1553 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1554 if (!ToElementTypeOrErr)
1555 return ToElementTypeOrErr.takeError();
1556
1557 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1558 T->getNumElements(),
1559 T->getVectorKind());
1560}
1561
1562ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1563 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1564 if (!ToElementTypeOrErr)
1565 return ToElementTypeOrErr.takeError();
1566
1567 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1568 T->getNumElements());
1569}
1570
1572ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1573 // FIXME: What happens if we're importing a function without a prototype
1574 // into C++? Should we make it variadic?
1575 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1576 if (!ToReturnTypeOrErr)
1577 return ToReturnTypeOrErr.takeError();
1578
1579 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1580 T->getExtInfo());
1581}
1582
1584ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1585 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1586 if (!ToReturnTypeOrErr)
1587 return ToReturnTypeOrErr.takeError();
1588
1589 // Import argument types
1590 SmallVector<QualType, 4> ArgTypes;
1591 for (const auto &A : T->param_types()) {
1592 ExpectedType TyOrErr = import(A);
1593 if (!TyOrErr)
1594 return TyOrErr.takeError();
1595 ArgTypes.push_back(*TyOrErr);
1596 }
1597
1598 // Import exception types
1599 SmallVector<QualType, 4> ExceptionTypes;
1600 for (const auto &E : T->exceptions()) {
1601 ExpectedType TyOrErr = import(E);
1602 if (!TyOrErr)
1603 return TyOrErr.takeError();
1604 ExceptionTypes.push_back(*TyOrErr);
1605 }
1606
1607 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
1608 Error Err = Error::success();
1609 FunctionProtoType::ExtProtoInfo ToEPI;
1610 ToEPI.ExtInfo = FromEPI.ExtInfo;
1611 ToEPI.Variadic = FromEPI.Variadic;
1612 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1613 ToEPI.TypeQuals = FromEPI.TypeQuals;
1614 ToEPI.RefQualifier = FromEPI.RefQualifier;
1615 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1617 importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr);
1619 importChecked(Err, FromEPI.ExceptionSpec.SourceDecl);
1621 importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate);
1622 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1623
1624 if (Err)
1625 return std::move(Err);
1626
1627 return Importer.getToContext().getFunctionType(
1628 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1629}
1630
1631ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1632 const UnresolvedUsingType *T) {
1633 Error Err = Error::success();
1634 auto ToQualifier = importChecked(Err, T->getQualifier());
1635 auto *ToD = importChecked(Err, T->getDecl());
1636 if (Err)
1637 return std::move(Err);
1638
1639 if (T->isCanonicalUnqualified())
1640 return Importer.getToContext().getCanonicalUnresolvedUsingType(ToD);
1641 return Importer.getToContext().getUnresolvedUsingType(T->getKeyword(),
1642 ToQualifier, ToD);
1643}
1644
1645ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1646 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1647 if (!ToInnerTypeOrErr)
1648 return ToInnerTypeOrErr.takeError();
1649
1650 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1651}
1652
1654ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1655
1656 ExpectedType Pattern = import(T->getPattern());
1657 if (!Pattern)
1658 return Pattern.takeError();
1659 ExpectedExpr Index = import(T->getIndexExpr());
1660 if (!Index)
1661 return Index.takeError();
1662 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1663}
1664
1665ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1666 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1667 if (!ToDeclOrErr)
1668 return ToDeclOrErr.takeError();
1669
1670 auto ToQualifierOrErr = import(T->getQualifier());
1671 if (!ToQualifierOrErr)
1672 return ToQualifierOrErr.takeError();
1673
1674 ExpectedType ToUnderlyingTypeOrErr =
1675 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1676 if (!ToUnderlyingTypeOrErr)
1677 return ToUnderlyingTypeOrErr.takeError();
1678
1679 return Importer.getToContext().getTypedefType(
1680 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1681}
1682
1683ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1684 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1685 if (!ToExprOrErr)
1686 return ToExprOrErr.takeError();
1687 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1688}
1689
1690ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1691 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1692 if (!ToUnderlyingTypeOrErr)
1693 return ToUnderlyingTypeOrErr.takeError();
1694 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1695 T->getKind());
1696}
1697
1698ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1699 Error Err = Error::success();
1700 auto ToQualifier = importChecked(Err, T->getQualifier());
1701 auto *ToD = importChecked(Err, T->getDecl());
1702 QualType ToT = importChecked(Err, T->desugar());
1703 if (Err)
1704 return std::move(Err);
1705 return Importer.getToContext().getUsingType(T->getKeyword(), ToQualifier, ToD,
1706 ToT);
1707}
1708
1709ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1710 // FIXME: Make sure that the "to" context supports C++0x!
1711 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1712 if (!ToExprOrErr)
1713 return ToExprOrErr.takeError();
1714
1715 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1716 if (!ToUnderlyingTypeOrErr)
1717 return ToUnderlyingTypeOrErr.takeError();
1718
1719 return Importer.getToContext().getDecltypeType(
1720 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1721}
1722
1724ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1725 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1726 if (!ToBaseTypeOrErr)
1727 return ToBaseTypeOrErr.takeError();
1728
1729 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1730 if (!ToUnderlyingTypeOrErr)
1731 return ToUnderlyingTypeOrErr.takeError();
1732
1733 return Importer.getToContext().getUnaryTransformType(
1734 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1735}
1736
1737ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1738 // FIXME: Make sure that the "to" context supports C++11!
1739 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1740 if (!ToDeducedTypeOrErr)
1741 return ToDeducedTypeOrErr.takeError();
1742
1743 Expected<TemplateDecl *> ToTypeConstraint =
1744 import(T->getTypeConstraintConcept());
1745 if (!ToTypeConstraint)
1746 return ToTypeConstraint.takeError();
1747
1748 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1749 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1750 ToTemplateArgs))
1751 return std::move(Err);
1752
1753 return Importer.getToContext().getAutoType(
1754 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1755 *ToTypeConstraint, ToTemplateArgs);
1756}
1757
1758ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1759 const DeducedTemplateSpecializationType *T) {
1760 // FIXME: Make sure that the "to" context supports C++17!
1761 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1762 if (!ToTemplateNameOrErr)
1763 return ToTemplateNameOrErr.takeError();
1764 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1765 if (!ToDeducedTypeOrErr)
1766 return ToDeducedTypeOrErr.takeError();
1767
1768 return Importer.getToContext().getDeducedTemplateSpecializationType(
1769 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1770 *ToTemplateNameOrErr);
1771}
1772
1773ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1774 TagDecl *DeclForType = T->getDecl();
1775 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1776 if (!ToDeclOrErr)
1777 return ToDeclOrErr.takeError();
1778
1779 // If there is a definition of the 'OriginalDecl', it should be imported to
1780 // have all information for the type in the "To" AST. (In some cases no
1781 // other reference may exist to the definition decl and it would not be
1782 // imported otherwise.)
1783 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1784 if (!ToDefDeclOrErr)
1785 return ToDefDeclOrErr.takeError();
1786
1787 if (T->isCanonicalUnqualified())
1788 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1789
1790 auto ToQualifierOrErr = import(T->getQualifier());
1791 if (!ToQualifierOrErr)
1792 return ToQualifierOrErr.takeError();
1793
1794 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1795 *ToDeclOrErr, T->isTagOwned());
1796}
1797
1798ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1799 return VisitTagType(T);
1800}
1801
1802ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1803 return VisitTagType(T);
1804}
1805
1807ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1808 return VisitTagType(T);
1809}
1810
1811ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1812 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1813 if (!ToModifiedTypeOrErr)
1814 return ToModifiedTypeOrErr.takeError();
1815 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1816 if (!ToEquivalentTypeOrErr)
1817 return ToEquivalentTypeOrErr.takeError();
1818
1819 return Importer.getToContext().getAttributedType(
1820 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1821 T->getAttr());
1822}
1823
1825ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1826 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1827 if (!ToWrappedTypeOrErr)
1828 return ToWrappedTypeOrErr.takeError();
1829
1830 Error Err = Error::success();
1831 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1832
1833 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1834 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1835 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1836 if (!ToDeclOrErr)
1837 return ToDeclOrErr.takeError();
1838 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1839 }
1840
1841 return Importer.getToContext().getCountAttributedType(
1842 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1843 ArrayRef(CoupledDecls));
1844}
1845
1846ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1847 const TemplateTypeParmType *T) {
1848 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1849 if (!ToDeclOrErr)
1850 return ToDeclOrErr.takeError();
1851
1852 return Importer.getToContext().getTemplateTypeParmType(
1853 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1854}
1855
1856ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1857 const SubstTemplateTypeParmType *T) {
1858 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1859 if (!ReplacedOrErr)
1860 return ReplacedOrErr.takeError();
1861
1862 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1863 if (!ToReplacementTypeOrErr)
1864 return ToReplacementTypeOrErr.takeError();
1865
1866 return Importer.getToContext().getSubstTemplateTypeParmType(
1867 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1868 T->getFinal());
1869}
1870
1871ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1872 const SubstTemplateTypeParmPackType *T) {
1873 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1874 if (!ReplacedOrErr)
1875 return ReplacedOrErr.takeError();
1876
1877 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1878 if (!ToArgumentPack)
1879 return ToArgumentPack.takeError();
1880
1881 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1882 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1883}
1884
1885ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1886 const SubstBuiltinTemplatePackType *T) {
1887 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1888 if (!ToArgumentPack)
1889 return ToArgumentPack.takeError();
1890 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1891}
1892
1893ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1894 const TemplateSpecializationType *T) {
1895 auto ToTemplateOrErr = import(T->getTemplateName());
1896 if (!ToTemplateOrErr)
1897 return ToTemplateOrErr.takeError();
1898
1899 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1900 if (Error Err =
1901 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1902 return std::move(Err);
1903
1904 ExpectedType ToUnderlyingOrErr =
1905 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1906 if (!ToUnderlyingOrErr)
1907 return ToUnderlyingOrErr.takeError();
1908 return Importer.getToContext().getTemplateSpecializationType(
1909 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1910 *ToUnderlyingOrErr);
1911}
1912
1914ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1915 ExpectedType ToPatternOrErr = import(T->getPattern());
1916 if (!ToPatternOrErr)
1917 return ToPatternOrErr.takeError();
1918
1919 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1920 T->getNumExpansions(),
1921 /*ExpactPack=*/false);
1922}
1923
1925ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1926 auto ToQualifierOrErr = import(T->getQualifier());
1927 if (!ToQualifierOrErr)
1928 return ToQualifierOrErr.takeError();
1929
1930 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1931 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1932 *ToQualifierOrErr, Name);
1933}
1934
1936ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1937 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1938 if (!ToDeclOrErr)
1939 return ToDeclOrErr.takeError();
1940
1941 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1942}
1943
1944ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1945 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1946 if (!ToBaseTypeOrErr)
1947 return ToBaseTypeOrErr.takeError();
1948
1949 SmallVector<QualType, 4> TypeArgs;
1950 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1951 if (ExpectedType TyOrErr = import(TypeArg))
1952 TypeArgs.push_back(*TyOrErr);
1953 else
1954 return TyOrErr.takeError();
1955 }
1956
1957 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1958 for (auto *P : T->quals()) {
1959 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1960 Protocols.push_back(*ProtocolOrErr);
1961 else
1962 return ProtocolOrErr.takeError();
1963
1964 }
1965
1966 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1967 Protocols,
1968 T->isKindOfTypeAsWritten());
1969}
1970
1972ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1973 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1974 if (!ToPointeeTypeOrErr)
1975 return ToPointeeTypeOrErr.takeError();
1976
1977 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1978}
1979
1981ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1982 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1983 if (!ToUnderlyingTypeOrErr)
1984 return ToUnderlyingTypeOrErr.takeError();
1985
1986 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1987 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1988 ToIdentifier);
1989}
1990
1991ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1992 Error Err = Error::success();
1993 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1994 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1995 if (Err)
1996 return std::move(Err);
1997
1998 return Importer.getToContext().getAdjustedType(ToOriginalType,
1999 ToAdjustedType);
2000}
2001
2002ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
2003 return Importer.getToContext().getBitIntType(T->isUnsigned(),
2004 T->getNumBits());
2005}
2006
2007ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
2008 const clang::BTFTagAttributedType *T) {
2009 Error Err = Error::success();
2010 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
2011 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2012 if (Err)
2013 return std::move(Err);
2014
2015 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
2016 ToWrappedType);
2017}
2018
2019ExpectedType clang::ASTNodeImporter::VisitOverflowBehaviorType(
2020 const clang::OverflowBehaviorType *T) {
2021 Error Err = Error::success();
2022 OverflowBehaviorType::OverflowBehaviorKind ToKind = T->getBehaviorKind();
2023 QualType ToUnderlyingType = importChecked(Err, T->getUnderlyingType());
2024 if (Err)
2025 return std::move(Err);
2026
2027 return Importer.getToContext().getOverflowBehaviorType(ToKind,
2029}
2030
2031ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2032 const clang::HLSLAttributedResourceType *T) {
2033 Error Err = Error::success();
2034 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
2035 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2036 QualType ToContainedType = importChecked(Err, T->getContainedType());
2037 if (Err)
2038 return std::move(Err);
2039
2040 return Importer.getToContext().getHLSLAttributedResourceType(
2041 ToWrappedType, ToContainedType, ToAttrs);
2042}
2043
2044ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2045 const clang::HLSLInlineSpirvType *T) {
2046 Error Err = Error::success();
2047
2048 uint32_t ToOpcode = T->getOpcode();
2049 uint32_t ToSize = T->getSize();
2050 uint32_t ToAlignment = T->getAlignment();
2051
2052 llvm::SmallVector<SpirvOperand> ToOperands;
2053
2054 for (auto &Operand : T->getOperands()) {
2055 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2056
2057 switch (Operand.getKind()) {
2058 case SpirvOperandKind::ConstantId:
2059 ToOperands.push_back(SpirvOperand::createConstant(
2060 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2061 break;
2062 case SpirvOperandKind::Literal:
2063 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2064 break;
2065 case SpirvOperandKind::TypeId:
2066 ToOperands.push_back(SpirvOperand::createType(
2067 importChecked(Err, Operand.getResultType())));
2068 break;
2069 default:
2070 llvm_unreachable("Invalid SpirvOperand kind");
2071 }
2072
2073 if (Err)
2074 return std::move(Err);
2075 }
2076
2077 return Importer.getToContext().getHLSLInlineSpirvType(
2078 ToOpcode, ToSize, ToAlignment, ToOperands);
2079}
2080
2081ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2082 const clang::ConstantMatrixType *T) {
2083 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2084 if (!ToElementTypeOrErr)
2085 return ToElementTypeOrErr.takeError();
2086
2087 return Importer.getToContext().getConstantMatrixType(
2088 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2089}
2090
2091ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2092 const clang::DependentAddressSpaceType *T) {
2093 Error Err = Error::success();
2094 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2095 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2096 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2097 if (Err)
2098 return std::move(Err);
2099
2100 return Importer.getToContext().getDependentAddressSpaceType(
2101 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2102}
2103
2104ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2105 const clang::DependentBitIntType *T) {
2106 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2107 if (!ToNumBitsExprOrErr)
2108 return ToNumBitsExprOrErr.takeError();
2109 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2110 *ToNumBitsExprOrErr);
2111}
2112
2113ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2114 const clang::PredefinedSugarType *T) {
2115 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2116}
2117
2118ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2119 const clang::DependentSizedMatrixType *T) {
2120 Error Err = Error::success();
2121 QualType ToElementType = importChecked(Err, T->getElementType());
2122 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2123 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2124 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2125 if (Err)
2126 return std::move(Err);
2127
2128 return Importer.getToContext().getDependentSizedMatrixType(
2129 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2130}
2131
2132ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2133 const clang::DependentVectorType *T) {
2134 Error Err = Error::success();
2135 QualType ToElementType = importChecked(Err, T->getElementType());
2136 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2137 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2138 if (Err)
2139 return std::move(Err);
2140
2141 return Importer.getToContext().getDependentVectorType(
2142 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2143}
2144
2145ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2146 const clang::ObjCTypeParamType *T) {
2147 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2148 if (!ToDeclOrErr)
2149 return ToDeclOrErr.takeError();
2150
2151 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2152 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2153 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2154 if (!ToProtocolOrErr)
2155 return ToProtocolOrErr.takeError();
2156 ToProtocols.push_back(*ToProtocolOrErr);
2157 }
2158
2159 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2160 ToProtocols);
2161}
2162
2163ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2164 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2165 if (!ToElementTypeOrErr)
2166 return ToElementTypeOrErr.takeError();
2167
2168 ASTContext &ToCtx = Importer.getToContext();
2169 if (T->isReadOnly())
2170 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2171 else
2172 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2173}
2174
2175//----------------------------------------------------------------------------
2176// Import Declarations
2177//----------------------------------------------------------------------------
2179 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2180 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2181 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2182 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2183 // FIXME: We could support these constructs by importing a different type of
2184 // this parameter and by importing the original type of the parameter only
2185 // after the FunctionDecl is created. See
2186 // VisitFunctionDecl::UsedDifferentProtoType.
2187 DeclContext *OrigDC = D->getDeclContext();
2188 FunctionDecl *FunDecl;
2189 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2190 FunDecl->hasBody()) {
2191 auto getLeafPointeeType = [](const Type *T) {
2192 while (T->isPointerType() || T->isArrayType()) {
2193 T = T->getPointeeOrArrayElementType();
2194 }
2195 return T;
2196 };
2197 for (const ParmVarDecl *P : FunDecl->parameters()) {
2198 const Type *LeafT =
2199 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2200 auto *RT = dyn_cast<RecordType>(LeafT);
2201 if (RT && RT->getDecl() == D) {
2202 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2203 << D->getDeclKindName();
2204 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2205 }
2206 }
2207 }
2208
2209 // Import the context of this declaration.
2210 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2211 return Err;
2212
2213 // Import the name of this declaration.
2214 if (Error Err = importInto(Name, D->getDeclName()))
2215 return Err;
2216
2217 // Import the location of this declaration.
2218 if (Error Err = importInto(Loc, D->getLocation()))
2219 return Err;
2220
2221 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2222 if (ToD)
2223 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2224 return Err;
2225
2226 return Error::success();
2227}
2228
2230 NamedDecl *&ToD, SourceLocation &Loc) {
2231
2232 // Import the name of this declaration.
2233 if (Error Err = importInto(Name, D->getDeclName()))
2234 return Err;
2235
2236 // Import the location of this declaration.
2237 if (Error Err = importInto(Loc, D->getLocation()))
2238 return Err;
2239
2240 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2241 if (ToD)
2242 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2243 return Err;
2244
2245 return Error::success();
2246}
2247
2249 if (!FromD)
2250 return Error::success();
2251
2252 if (!ToD)
2253 if (Error Err = importInto(ToD, FromD))
2254 return Err;
2255
2256 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2257 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2258 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2259 !ToRecord->getDefinition()) {
2260 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2261 return Err;
2262 }
2263 }
2264 return Error::success();
2265 }
2266
2267 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2268 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2269 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2270 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2271 return Err;
2272 }
2273 }
2274 return Error::success();
2275 }
2276
2277 return Error::success();
2278}
2279
2280Error
2282 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2283 // NOTE: To.Name and To.Loc are already imported.
2284 // We only have to import To.LocInfo.
2285 switch (To.getName().getNameKind()) {
2292 return Error::success();
2293
2295 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2296 To.setCXXOperatorNameRange(*ToRangeOrErr);
2297 else
2298 return ToRangeOrErr.takeError();
2299 return Error::success();
2300 }
2302 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2303 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2304 else
2305 return LocOrErr.takeError();
2306 return Error::success();
2307 }
2311 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2312 To.setNamedTypeInfo(*ToTInfoOrErr);
2313 else
2314 return ToTInfoOrErr.takeError();
2315 return Error::success();
2316 }
2317 }
2318 llvm_unreachable("Unknown name kind.");
2319}
2320
2321Error
2323 if (Importer.isMinimalImport() && !ForceImport) {
2324 auto ToDCOrErr = Importer.ImportContext(FromDC);
2325 return ToDCOrErr.takeError();
2326 }
2327
2328 // We use strict error handling in case of records and enums, but not
2329 // with e.g. namespaces.
2330 //
2331 // FIXME Clients of the ASTImporter should be able to choose an
2332 // appropriate error handling strategy for their needs. For instance,
2333 // they may not want to mark an entire namespace as erroneous merely
2334 // because there is an ODR error with two typedefs. As another example,
2335 // the client may allow EnumConstantDecls with same names but with
2336 // different values in two distinct translation units.
2337 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2338
2339 auto MightNeedReordering = [](const Decl *D) {
2341 };
2342
2343 // Import everything that might need reordering first.
2344 Error ChildErrors = Error::success();
2345 for (auto *From : FromDC->decls()) {
2346 if (!MightNeedReordering(From))
2347 continue;
2348
2349 ExpectedDecl ImportedOrErr = import(From);
2350
2351 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2352 // want to make sure that we are also completing each FieldDecl. There
2353 // are currently cases where this does not happen and this is correctness
2354 // fix since operations such as code generation will expect this to be so.
2355 if (!ImportedOrErr) {
2356 HandleChildErrors.handleChildImportResult(ChildErrors,
2357 ImportedOrErr.takeError());
2358 continue;
2359 }
2360 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2361 Decl *ImportedDecl = *ImportedOrErr;
2362 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2363 if (FieldFrom && FieldTo) {
2364 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2365 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2366 }
2367 }
2368
2369 // We reorder declarations in RecordDecls because they may have another order
2370 // in the "to" context than they have in the "from" context. This may happen
2371 // e.g when we import a class like this:
2372 // struct declToImport {
2373 // int a = c + b;
2374 // int b = 1;
2375 // int c = 2;
2376 // };
2377 // During the import of `a` we import first the dependencies in sequence,
2378 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2379 // first removing the already imported members and then adding them in the
2380 // order as they appear in the "from" context.
2381 //
2382 // Keeping field order is vital because it determines structure layout.
2383 //
2384 // Here and below, we cannot call field_begin() method and its callers on
2385 // ToDC if it has an external storage. Calling field_begin() will
2386 // automatically load all the fields by calling
2387 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2388 // call ASTImporter::Import(). This is because the ExternalASTSource
2389 // interface in LLDB is implemented by the means of the ASTImporter. However,
2390 // calling an import at this point would result in an uncontrolled import, we
2391 // must avoid that.
2392
2393 auto ToDCOrErr = Importer.ImportContext(FromDC);
2394 if (!ToDCOrErr) {
2395 consumeError(std::move(ChildErrors));
2396 return ToDCOrErr.takeError();
2397 }
2398
2399 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2400 DeclContext *ToDC = *ToDCOrErr;
2401 // Remove all declarations, which may be in wrong order in the
2402 // lexical DeclContext and then add them in the proper order.
2403 for (auto *D : FromRD->decls()) {
2404 if (!MightNeedReordering(D))
2405 continue;
2406
2407 assert(D && "DC contains a null decl");
2408 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2409 // Remove only the decls which we successfully imported.
2410 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2411 // Remove the decl from its wrong place in the linked list.
2412 ToDC->removeDecl(ToD);
2413 // Add the decl to the end of the linked list.
2414 // This time it will be at the proper place because the enclosing for
2415 // loop iterates in the original (good) order of the decls.
2416 ToDC->addDeclInternal(ToD);
2417 }
2418 }
2419 }
2420
2421 // Import everything else.
2422 for (auto *From : FromDC->decls()) {
2423 if (MightNeedReordering(From))
2424 continue;
2425
2426 ExpectedDecl ImportedOrErr = import(From);
2427 if (!ImportedOrErr)
2428 HandleChildErrors.handleChildImportResult(ChildErrors,
2429 ImportedOrErr.takeError());
2430 }
2431
2432 return ChildErrors;
2433}
2434
2436 const FieldDecl *To) {
2437 RecordDecl *FromRecordDecl = nullptr;
2438 RecordDecl *ToRecordDecl = nullptr;
2439 // If we have a field that is an ArrayType we need to check if the array
2440 // element is a RecordDecl and if so we need to import the definition.
2441 QualType FromType = From->getType();
2442 QualType ToType = To->getType();
2443 if (FromType->isArrayType()) {
2444 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2445 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2446 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2447 }
2448
2449 if (!FromRecordDecl || !ToRecordDecl) {
2450 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2451 const RecordType *RecordTo = ToType->getAs<RecordType>();
2452
2453 if (RecordFrom && RecordTo) {
2454 FromRecordDecl = RecordFrom->getDecl();
2455 ToRecordDecl = RecordTo->getDecl();
2456 }
2457 }
2458
2459 if (FromRecordDecl && ToRecordDecl) {
2460 if (FromRecordDecl->isCompleteDefinition() &&
2461 !ToRecordDecl->isCompleteDefinition())
2462 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2463 }
2464
2465 return Error::success();
2466}
2467
2469 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2470 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2471 if (!ToDCOrErr)
2472 return ToDCOrErr.takeError();
2473 ToDC = *ToDCOrErr;
2474
2475 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2476 auto ToLexicalDCOrErr = Importer.ImportContext(
2477 FromD->getLexicalDeclContext());
2478 if (!ToLexicalDCOrErr)
2479 return ToLexicalDCOrErr.takeError();
2480 ToLexicalDC = *ToLexicalDCOrErr;
2481 } else
2482 ToLexicalDC = ToDC;
2483
2484 return Error::success();
2485}
2486
2488 const CXXRecordDecl *From, CXXRecordDecl *To) {
2489 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2490 "Import implicit methods to or from non-definition");
2491
2492 for (CXXMethodDecl *FromM : From->methods())
2493 if (FromM->isImplicit()) {
2494 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2495 if (!ToMOrErr)
2496 return ToMOrErr.takeError();
2497 }
2498
2499 return Error::success();
2500}
2501
2503 ASTImporter &Importer) {
2504 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2505 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2507 else
2508 return ToTypedefOrErr.takeError();
2509 }
2510 return Error::success();
2511}
2512
2514 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2515 auto DefinitionCompleter = [To]() {
2516 // There are cases in LLDB when we first import a class without its
2517 // members. The class will have DefinitionData, but no members. Then,
2518 // importDefinition is called from LLDB, which tries to get the members, so
2519 // when we get here, the class already has the DefinitionData set, so we
2520 // must unset the CompleteDefinition here to be able to complete again the
2521 // definition.
2522 To->setCompleteDefinition(false);
2523 To->completeDefinition();
2524 };
2525
2526 if (To->getDefinition() || To->isBeingDefined()) {
2527 if (Kind == IDK_Everything ||
2528 // In case of lambdas, the class already has a definition ptr set, but
2529 // the contained decls are not imported yet. Also, isBeingDefined was
2530 // set in CXXRecordDecl::CreateLambda. We must import the contained
2531 // decls here and finish the definition.
2532 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2533 if (To->isLambda()) {
2534 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2536 ToCaptures.reserve(FromCXXRD->capture_size());
2537 for (const auto &FromCapture : FromCXXRD->captures()) {
2538 if (auto ToCaptureOrErr = import(FromCapture))
2539 ToCaptures.push_back(*ToCaptureOrErr);
2540 else
2541 return ToCaptureOrErr.takeError();
2542 }
2543 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2544 ToCaptures);
2545 }
2546
2547 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2548 // Finish the definition of the lambda, set isBeingDefined to false.
2549 if (To->isLambda())
2550 DefinitionCompleter();
2551 return Result;
2552 }
2553
2554 return Error::success();
2555 }
2556
2557 To->startDefinition();
2558 // Set the definition to complete even if it is really not complete during
2559 // import. Some AST constructs (expressions) require the record layout
2560 // to be calculated (see 'clang::computeDependence') at the time they are
2561 // constructed. Import of such AST node is possible during import of the
2562 // same record, there is no way to have a completely defined record (all
2563 // fields imported) at that time without multiple AST import passes.
2564 if (!Importer.isMinimalImport())
2565 To->setCompleteDefinition(true);
2566 // Complete the definition even if error is returned.
2567 // The RecordDecl may be already part of the AST so it is better to
2568 // have it in complete state even if something is wrong with it.
2569 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2570
2571 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2572 return Err;
2573
2574 // Add base classes.
2575 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2576 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2577 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2578
2579 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2580 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2581
2582 #define FIELD(Name, Width, Merge) \
2583 ToData.Name = FromData.Name;
2584 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2585
2586 // Copy over the data stored in RecordDeclBits
2587 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2588
2590 for (const auto &Base1 : FromCXX->bases()) {
2591 ExpectedType TyOrErr = import(Base1.getType());
2592 if (!TyOrErr)
2593 return TyOrErr.takeError();
2594
2595 SourceLocation EllipsisLoc;
2596 if (Base1.isPackExpansion()) {
2597 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2598 EllipsisLoc = *LocOrErr;
2599 else
2600 return LocOrErr.takeError();
2601 }
2602
2603 // Ensure that we have a definition for the base.
2604 if (Error Err =
2605 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2606 return Err;
2607
2608 auto RangeOrErr = import(Base1.getSourceRange());
2609 if (!RangeOrErr)
2610 return RangeOrErr.takeError();
2611
2612 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2613 if (!TSIOrErr)
2614 return TSIOrErr.takeError();
2615
2616 Bases.push_back(
2617 new (Importer.getToContext()) CXXBaseSpecifier(
2618 *RangeOrErr,
2619 Base1.isVirtual(),
2620 Base1.isBaseOfClass(),
2621 Base1.getAccessSpecifierAsWritten(),
2622 *TSIOrErr,
2623 EllipsisLoc));
2624 }
2625 if (!Bases.empty())
2626 ToCXX->setBases(Bases.data(), Bases.size());
2627 }
2628
2629 if (shouldForceImportDeclContext(Kind)) {
2630 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2631 return Err;
2632 }
2633
2634 return Error::success();
2635}
2636
2638 if (To->getAnyInitializer())
2639 return Error::success();
2640
2641 Expr *FromInit = From->getInit();
2642 if (!FromInit)
2643 return Error::success();
2644
2645 ExpectedExpr ToInitOrErr = import(FromInit);
2646 if (!ToInitOrErr)
2647 return ToInitOrErr.takeError();
2648
2649 To->setInit(*ToInitOrErr);
2650 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2651 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2652 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2653 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2654 // FIXME: Also import the initializer value.
2655 }
2656
2657 // FIXME: Other bits to merge?
2658 return Error::success();
2659}
2660
2662 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2663 if (To->getDefinition() || To->isBeingDefined()) {
2664 if (Kind == IDK_Everything)
2665 return ImportDeclContext(From, /*ForceImport=*/true);
2666 return Error::success();
2667 }
2668
2669 To->startDefinition();
2670
2671 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2672 return Err;
2673
2674 ExpectedType ToTypeOrErr =
2675 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2676 if (!ToTypeOrErr)
2677 return ToTypeOrErr.takeError();
2678
2679 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2680 if (!ToPromotionTypeOrErr)
2681 return ToPromotionTypeOrErr.takeError();
2682
2684 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2685 return Err;
2686
2687 // FIXME: we might need to merge the number of positive or negative bits
2688 // if the enumerator lists don't match.
2689 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2690 From->getNumPositiveBits(),
2691 From->getNumNegativeBits());
2692 return Error::success();
2693}
2694
2698 for (const auto &Arg : FromArgs) {
2699 if (auto ToOrErr = import(Arg))
2700 ToArgs.push_back(*ToOrErr);
2701 else
2702 return ToOrErr.takeError();
2703 }
2704
2705 return Error::success();
2706}
2707
2708// FIXME: Do not forget to remove this and use only 'import'.
2711 return import(From);
2712}
2713
2714template <typename InContainerTy>
2716 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2717 for (const auto &FromLoc : Container) {
2718 if (auto ToLocOrErr = import(FromLoc))
2719 ToTAInfo.addArgument(*ToLocOrErr);
2720 else
2721 return ToLocOrErr.takeError();
2722 }
2723 return Error::success();
2724}
2725
2731
2732bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2733 bool IgnoreTemplateParmDepth) {
2734 // Eliminate a potential failure point where we attempt to re-import
2735 // something we're trying to import while completing ToRecord.
2736 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2737 if (ToOrigin) {
2738 To = ToOrigin;
2739 }
2740
2742 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2743 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2745 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2746 IgnoreTemplateParmDepth);
2747 return Ctx.IsEquivalent(From, To);
2748}
2749
2751 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2752 << D->getDeclKindName();
2753 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2754}
2755
2757 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2758 << D->getDeclKindName();
2759 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2760}
2761
2763 // Import the context of this declaration.
2764 DeclContext *DC, *LexicalDC;
2765 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2766 return std::move(Err);
2767
2768 // Import the location of this declaration.
2769 ExpectedSLoc LocOrErr = import(D->getLocation());
2770 if (!LocOrErr)
2771 return LocOrErr.takeError();
2772
2773 EmptyDecl *ToD;
2774 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2775 return ToD;
2776
2777 ToD->setLexicalDeclContext(LexicalDC);
2778 LexicalDC->addDeclInternal(ToD);
2779 return ToD;
2780}
2781
2783 TranslationUnitDecl *ToD =
2784 Importer.getToContext().getTranslationUnitDecl();
2785
2786 Importer.MapImported(D, ToD);
2787
2788 return ToD;
2789}
2790
2792 Error Err = Error::success();
2793 Expr *ToAsmString = importChecked(Err, D->getAsmStringExpr());
2794 SourceLocation ToAsmLoc = importChecked(Err, D->getAsmLoc());
2795 SourceLocation ToRParenLoc = importChecked(Err, D->getRParenLoc());
2796 if (Err)
2797 return std::move(Err);
2798
2799 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2800 if (!DCOrErr)
2801 return DCOrErr.takeError();
2802 DeclContext *DC = *DCOrErr;
2803
2804 FileScopeAsmDecl *ToD;
2805 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToAsmString,
2806 ToAsmLoc, ToRParenLoc))
2807 return ToD;
2808
2809 ToD->setLexicalDeclContext(DC);
2810 DC->addDeclInternal(ToD);
2811
2812 return ToD;
2813}
2814
2816 DeclContext *DC, *LexicalDC;
2817 DeclarationName Name;
2818 SourceLocation Loc;
2819 NamedDecl *ToND;
2820 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2821 return std::move(Err);
2822 if (ToND)
2823 return ToND;
2824
2825 BindingDecl *ToD;
2826 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2827 Name.getAsIdentifierInfo(), D->getType()))
2828 return ToD;
2829
2830 Error Err = Error::success();
2831 QualType ToType = importChecked(Err, D->getType());
2832 Expr *ToBinding = importChecked(Err, D->getBinding());
2833 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2834 if (Err)
2835 return std::move(Err);
2836
2837 ToD->setBinding(ToType, ToBinding);
2838 ToD->setDecomposedDecl(ToDecomposedDecl);
2839 addDeclToContexts(D, ToD);
2840
2841 return ToD;
2842}
2843
2845 ExpectedSLoc LocOrErr = import(D->getLocation());
2846 if (!LocOrErr)
2847 return LocOrErr.takeError();
2848 auto ColonLocOrErr = import(D->getColonLoc());
2849 if (!ColonLocOrErr)
2850 return ColonLocOrErr.takeError();
2851
2852 // Import the context of this declaration.
2853 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2854 if (!DCOrErr)
2855 return DCOrErr.takeError();
2856 DeclContext *DC = *DCOrErr;
2857
2858 AccessSpecDecl *ToD;
2859 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2860 DC, *LocOrErr, *ColonLocOrErr))
2861 return ToD;
2862
2863 // Lexical DeclContext and Semantic DeclContext
2864 // is always the same for the accessSpec.
2865 ToD->setLexicalDeclContext(DC);
2866 DC->addDeclInternal(ToD);
2867
2868 return ToD;
2869}
2870
2872 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2873 if (!DCOrErr)
2874 return DCOrErr.takeError();
2875 DeclContext *DC = *DCOrErr;
2876 DeclContext *LexicalDC = DC;
2877
2878 Error Err = Error::success();
2879 auto ToLocation = importChecked(Err, D->getLocation());
2880 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2881 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2882 auto ToMessage = importChecked(Err, D->getMessage());
2883 if (Err)
2884 return std::move(Err);
2885
2886 StaticAssertDecl *ToD;
2887 if (GetImportedOrCreateDecl(
2888 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2889 ToRParenLoc, D->isFailed()))
2890 return ToD;
2891
2892 ToD->setLexicalDeclContext(LexicalDC);
2893 LexicalDC->addDeclInternal(ToD);
2894 return ToD;
2895}
2896
2898 // Import the major distinguishing characteristics of this namespace.
2899 DeclContext *DC, *LexicalDC;
2900 DeclarationName Name;
2901 SourceLocation Loc;
2902 NamedDecl *ToD;
2903 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2904 return std::move(Err);
2905 if (ToD)
2906 return ToD;
2907
2908 NamespaceDecl *MergeWithNamespace = nullptr;
2909 if (!Name) {
2910 // This is an anonymous namespace. Adopt an existing anonymous
2911 // namespace if we can.
2912 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2913 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2914 MergeWithNamespace = TU->getAnonymousNamespace();
2915 else
2916 MergeWithNamespace =
2917 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2918 } else {
2919 SmallVector<NamedDecl *, 4> ConflictingDecls;
2920 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2921 for (auto *FoundDecl : FoundDecls) {
2922 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2923 continue;
2924
2925 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2926 MergeWithNamespace = FoundNS;
2927 ConflictingDecls.clear();
2928 break;
2929 }
2930
2931 ConflictingDecls.push_back(FoundDecl);
2932 }
2933
2934 if (!ConflictingDecls.empty()) {
2935 ExpectedName NameOrErr = Importer.HandleNameConflict(
2936 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2937 ConflictingDecls.size());
2938 if (NameOrErr)
2939 Name = NameOrErr.get();
2940 else
2941 return NameOrErr.takeError();
2942 }
2943 }
2944
2945 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2946 if (!BeginLocOrErr)
2947 return BeginLocOrErr.takeError();
2948 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2949 if (!RBraceLocOrErr)
2950 return RBraceLocOrErr.takeError();
2951
2952 // Create the "to" namespace, if needed.
2953 NamespaceDecl *ToNamespace = MergeWithNamespace;
2954 if (!ToNamespace) {
2955 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2956 D->isInline(), *BeginLocOrErr, Loc,
2957 Name.getAsIdentifierInfo(),
2958 /*PrevDecl=*/nullptr, D->isNested()))
2959 return ToNamespace;
2960 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2961 ToNamespace->setLexicalDeclContext(LexicalDC);
2962 LexicalDC->addDeclInternal(ToNamespace);
2963
2964 // If this is an anonymous namespace, register it as the anonymous
2965 // namespace within its context.
2966 if (!Name) {
2967 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2968 TU->setAnonymousNamespace(ToNamespace);
2969 else
2970 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2971 }
2972 }
2973 Importer.MapImported(D, ToNamespace);
2974
2975 if (Error Err = ImportDeclContext(D))
2976 return std::move(Err);
2977
2978 return ToNamespace;
2979}
2980
2982 // Import the major distinguishing characteristics of this namespace.
2983 DeclContext *DC, *LexicalDC;
2984 DeclarationName Name;
2985 SourceLocation Loc;
2986 NamedDecl *LookupD;
2987 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2988 return std::move(Err);
2989 if (LookupD)
2990 return LookupD;
2991
2992 // NOTE: No conflict resolution is done for namespace aliases now.
2993
2994 Error Err = Error::success();
2995 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2996 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2997 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2998 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2999 auto ToNamespace = importChecked(Err, D->getNamespace());
3000 if (Err)
3001 return std::move(Err);
3002
3003 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
3004
3005 NamespaceAliasDecl *ToD;
3006 if (GetImportedOrCreateDecl(
3007 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
3008 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
3009 return ToD;
3010
3011 ToD->setLexicalDeclContext(LexicalDC);
3012 LexicalDC->addDeclInternal(ToD);
3013
3014 return ToD;
3015}
3016
3019 // Import the major distinguishing characteristics of this typedef.
3020 DeclarationName Name;
3021 SourceLocation Loc;
3022 NamedDecl *ToD;
3023 // Do not import the DeclContext, we will import it once the TypedefNameDecl
3024 // is created.
3025 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
3026 return std::move(Err);
3027 if (ToD)
3028 return ToD;
3029
3030 DeclContext *DC = cast_or_null<DeclContext>(
3031 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
3032 DeclContext *LexicalDC =
3033 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
3035
3036 // If this typedef is not in block scope, determine whether we've
3037 // seen a typedef with the same name (that we can merge with) or any
3038 // other entity by that name (which name lookup could conflict with).
3039 // Note: Repeated typedefs are not valid in C99:
3040 // 'typedef int T; typedef int T;' is invalid
3041 // We do not care about this now.
3042 if (DC && !DC->isFunctionOrMethod()) {
3043 SmallVector<NamedDecl *, 4> ConflictingDecls;
3044 unsigned IDNS = Decl::IDNS_Ordinary;
3045 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3046 for (auto *FoundDecl : FoundDecls) {
3047 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3048 continue;
3049 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3050 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3051 continue;
3052
3053 QualType FromUT = D->getUnderlyingType();
3054 QualType FoundUT = FoundTypedef->getUnderlyingType();
3055 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3056 // If the underlying declarations are unnamed records these can be
3057 // imported as different types. We should create a distinct typedef
3058 // node in this case.
3059 // If we found an existing underlying type with a record in a
3060 // different context (than the imported), this is already reason for
3061 // having distinct typedef nodes for these.
3062 // Again this can create situation like
3063 // 'typedef int T; typedef int T;' but this is hard to avoid without
3064 // a rename strategy at import.
3065 if (!FromUT.isNull() && !FoundUT.isNull()) {
3066 RecordDecl *FromR = FromUT->getAsRecordDecl();
3067 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3068 if (FromR && FoundR &&
3069 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3070 continue;
3071 }
3072 // If the "From" context has a complete underlying type but we
3073 // already have a complete underlying type then return with that.
3074 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3075 return Importer.MapImported(D, FoundTypedef);
3076 // FIXME Handle redecl chain. When you do that make consistent changes
3077 // in ASTImporterLookupTable too.
3078 } else {
3079 ConflictingDecls.push_back(FoundDecl);
3080 }
3081 }
3082 }
3083
3084 if (!ConflictingDecls.empty()) {
3085 ExpectedName NameOrErr = Importer.HandleNameConflict(
3086 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3087 if (NameOrErr)
3088 Name = NameOrErr.get();
3089 else
3090 return NameOrErr.takeError();
3091 }
3092 }
3093
3094 Error Err = Error::success();
3096 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3097 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3098 if (Err)
3099 return std::move(Err);
3100
3101 // Create the new typedef node.
3102 // FIXME: ToUnderlyingType is not used.
3103 (void)ToUnderlyingType;
3104 TypedefNameDecl *ToTypedef;
3105 if (IsAlias) {
3106 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3107 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3108 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3109 return ToTypedef;
3110 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3111 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3112 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3113 return ToTypedef;
3114
3115 // Import the DeclContext and set it to the Typedef.
3116 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3117 return std::move(Err);
3118 ToTypedef->setDeclContext(DC);
3119 ToTypedef->setLexicalDeclContext(LexicalDC);
3120 // Add to the lookupTable because we could not do that in MapImported.
3121 Importer.AddToLookupTable(ToTypedef);
3122
3123 ToTypedef->setAccess(D->getAccess());
3124
3125 // Templated declarations should not appear in DeclContext.
3126 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3127 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3128 LexicalDC->addDeclInternal(ToTypedef);
3129
3130 return ToTypedef;
3131}
3132
3136
3140
3143 // Import the major distinguishing characteristics of this typedef.
3144 DeclContext *DC, *LexicalDC;
3145 DeclarationName Name;
3146 SourceLocation Loc;
3147 NamedDecl *FoundD;
3148 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3149 return std::move(Err);
3150 if (FoundD)
3151 return FoundD;
3152
3153 // If this typedef is not in block scope, determine whether we've
3154 // seen a typedef with the same name (that we can merge with) or any
3155 // other entity by that name (which name lookup could conflict with).
3156 if (!DC->isFunctionOrMethod()) {
3157 SmallVector<NamedDecl *, 4> ConflictingDecls;
3158 unsigned IDNS = Decl::IDNS_Ordinary;
3159 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3160 for (auto *FoundDecl : FoundDecls) {
3161 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3162 continue;
3163 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3164 if (IsStructuralMatch(D, FoundAlias))
3165 return Importer.MapImported(D, FoundAlias);
3166 ConflictingDecls.push_back(FoundDecl);
3167 }
3168 }
3169
3170 if (!ConflictingDecls.empty()) {
3171 ExpectedName NameOrErr = Importer.HandleNameConflict(
3172 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3173 if (NameOrErr)
3174 Name = NameOrErr.get();
3175 else
3176 return NameOrErr.takeError();
3177 }
3178 }
3179
3180 Error Err = Error::success();
3181 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3182 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3183 if (Err)
3184 return std::move(Err);
3185
3186 TypeAliasTemplateDecl *ToAlias;
3187 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3188 Name, ToTemplateParameters, ToTemplatedDecl))
3189 return ToAlias;
3190
3191 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3192
3193 ToAlias->setAccess(D->getAccess());
3194 ToAlias->setLexicalDeclContext(LexicalDC);
3195 LexicalDC->addDeclInternal(ToAlias);
3196 if (DC != Importer.getToContext().getTranslationUnitDecl())
3197 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3198 return ToAlias;
3199}
3200
3202 // Import the major distinguishing characteristics of this label.
3203 DeclContext *DC, *LexicalDC;
3204 DeclarationName Name;
3205 SourceLocation Loc;
3206 NamedDecl *ToD;
3207 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3208 return std::move(Err);
3209 if (ToD)
3210 return ToD;
3211
3212 assert(LexicalDC->isFunctionOrMethod());
3213
3214 LabelDecl *ToLabel;
3215 if (D->isGnuLocal()) {
3216 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3217 if (!BeginLocOrErr)
3218 return BeginLocOrErr.takeError();
3219 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3220 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3221 return ToLabel;
3222
3223 } else {
3224 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3225 Name.getAsIdentifierInfo()))
3226 return ToLabel;
3227
3228 }
3229
3230 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3231 if (!ToStmtOrErr)
3232 return ToStmtOrErr.takeError();
3233
3234 ToLabel->setStmt(*ToStmtOrErr);
3235 ToLabel->setLexicalDeclContext(LexicalDC);
3236 LexicalDC->addDeclInternal(ToLabel);
3237 return ToLabel;
3238}
3239
3241 // Import the major distinguishing characteristics of this enum.
3242 DeclContext *DC, *LexicalDC;
3243 DeclarationName Name;
3244 SourceLocation Loc;
3245 NamedDecl *ToD;
3246 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3247 return std::move(Err);
3248 if (ToD)
3249 return ToD;
3250
3251 // Figure out what enum name we're looking for.
3252 unsigned IDNS = Decl::IDNS_Tag;
3253 DeclarationName SearchName = Name;
3254 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3255 if (Error Err = importInto(
3256 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3257 return std::move(Err);
3258 IDNS = Decl::IDNS_Ordinary;
3259 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3260 IDNS |= Decl::IDNS_Ordinary;
3261
3262 // We may already have an enum of the same name; try to find and match it.
3263 EnumDecl *PrevDecl = nullptr;
3264 if (!DC->isFunctionOrMethod()) {
3265 SmallVector<NamedDecl *, 4> ConflictingDecls;
3266 auto FoundDecls =
3267 Importer.findDeclsInToCtx(DC, SearchName);
3268 for (auto *FoundDecl : FoundDecls) {
3269 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3270 continue;
3271
3272 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3273 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3274 FoundDecl = Tag->getDecl();
3275 }
3276
3277 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3278 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3279 continue;
3280 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3281 EnumDecl *FoundDef = FoundEnum->getDefinition();
3282 if (D->isThisDeclarationADefinition() && FoundDef)
3283 return Importer.MapImported(D, FoundDef);
3284 PrevDecl = FoundEnum->getMostRecentDecl();
3285 break;
3286 }
3287 ConflictingDecls.push_back(FoundDecl);
3288 }
3289 }
3290
3291 // In case of unnamed enums, we try to find an existing similar one, if none
3292 // was found, perform the import always.
3293 // Structural in-equivalence is not detected in this way here, but it may
3294 // be found when the parent decl is imported (if the enum is part of a
3295 // class). To make this totally exact a more difficult solution is needed.
3296 if (SearchName && !ConflictingDecls.empty()) {
3297 ExpectedName NameOrErr = Importer.HandleNameConflict(
3298 SearchName, DC, IDNS, ConflictingDecls.data(),
3299 ConflictingDecls.size());
3300 if (NameOrErr)
3301 Name = NameOrErr.get();
3302 else
3303 return NameOrErr.takeError();
3304 }
3305 }
3306
3307 Error Err = Error::success();
3308 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3309 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3310 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3311 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3312 if (Err)
3313 return std::move(Err);
3314
3315 // Create the enum declaration.
3316 EnumDecl *D2;
3317 if (GetImportedOrCreateDecl(
3318 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3319 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3320 D->isScopedUsingClassTag(), D->isFixed()))
3321 return D2;
3322
3323 D2->setQualifierInfo(ToQualifierLoc);
3324 D2->setIntegerType(ToIntegerType);
3325 D2->setBraceRange(ToBraceRange);
3326 D2->setAccess(D->getAccess());
3327 D2->setLexicalDeclContext(LexicalDC);
3328 addDeclToContexts(D, D2);
3329
3331 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3332 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3333 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3334 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3335 else
3336 return ToInstOrErr.takeError();
3337 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3339 else
3340 return POIOrErr.takeError();
3341 }
3342
3343 // Import the definition
3344 if (D->isCompleteDefinition())
3345 if (Error Err = ImportDefinition(D, D2))
3346 return std::move(Err);
3347
3348 return D2;
3349}
3350
3352 bool IsFriendTemplate = false;
3353 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3354 IsFriendTemplate =
3355 DCXX->getDescribedClassTemplate() &&
3356 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3358 }
3359
3360 // Import the major distinguishing characteristics of this record.
3361 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3362 DeclarationName Name;
3363 SourceLocation Loc;
3364 NamedDecl *ToD = nullptr;
3365 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3366 return std::move(Err);
3367 if (ToD)
3368 return ToD;
3369
3370 // Figure out what structure name we're looking for.
3371 unsigned IDNS = Decl::IDNS_Tag;
3372 DeclarationName SearchName = Name;
3373 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3374 if (Error Err = importInto(
3375 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3376 return std::move(Err);
3377 IDNS = Decl::IDNS_Ordinary;
3378 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3380
3381 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3382 : DC->isDependentContext();
3383 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3384
3385 // We may already have a record of the same name; try to find and match it.
3386 RecordDecl *PrevDecl = nullptr;
3387 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3388 SmallVector<NamedDecl *, 4> ConflictingDecls;
3389 auto FoundDecls =
3390 Importer.findDeclsInToCtx(DC, SearchName);
3391 if (!FoundDecls.empty()) {
3392 // We're going to have to compare D against potentially conflicting Decls,
3393 // so complete it.
3396 }
3397
3398 for (auto *FoundDecl : FoundDecls) {
3399 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3400 continue;
3401
3402 Decl *Found = FoundDecl;
3403 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3404 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3405 Found = Tag->getDecl();
3406 }
3407
3408 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3409 // Do not emit false positive diagnostic in case of unnamed
3410 // struct/union and in case of anonymous structs. Would be false
3411 // because there may be several anonymous/unnamed structs in a class.
3412 // E.g. these are both valid:
3413 // struct A { // unnamed structs
3414 // struct { struct A *next; } entry0;
3415 // struct { struct A *next; } entry1;
3416 // };
3417 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3418 if (!SearchName)
3419 if (!IsStructuralMatch(D, FoundRecord, false))
3420 continue;
3421
3422 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3423 continue;
3424
3425 if (IsStructuralMatch(D, FoundRecord)) {
3426 RecordDecl *FoundDef = FoundRecord->getDefinition();
3427 if (D->isThisDeclarationADefinition() && FoundDef) {
3428 // FIXME: Structural equivalence check should check for same
3429 // user-defined methods.
3430 Importer.MapImported(D, FoundDef);
3431 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3432 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3433 assert(FoundCXX && "Record type mismatch");
3434
3435 if (!Importer.isMinimalImport())
3436 // FoundDef may not have every implicit method that D has
3437 // because implicit methods are created only if they are used.
3438 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3439 return std::move(Err);
3440 }
3441 // FIXME: We can return FoundDef here.
3442 }
3443 PrevDecl = FoundRecord->getMostRecentDecl();
3444 break;
3445 }
3446 ConflictingDecls.push_back(FoundDecl);
3447 } // kind is RecordDecl
3448 } // for
3449
3450 if (!ConflictingDecls.empty() && SearchName) {
3451 ExpectedName NameOrErr = Importer.HandleNameConflict(
3452 SearchName, DC, IDNS, ConflictingDecls.data(),
3453 ConflictingDecls.size());
3454 if (NameOrErr)
3455 Name = NameOrErr.get();
3456 else
3457 return NameOrErr.takeError();
3458 }
3459 }
3460
3461 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3462 if (!BeginLocOrErr)
3463 return BeginLocOrErr.takeError();
3464
3465 // Create the record declaration.
3466 RecordDecl *D2 = nullptr;
3467 CXXRecordDecl *D2CXX = nullptr;
3468 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3469 if (DCXX->isLambda()) {
3470 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3471 if (!TInfoOrErr)
3472 return TInfoOrErr.takeError();
3473 if (GetImportedOrCreateSpecialDecl(
3474 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3475 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3476 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3477 return D2CXX;
3478 Decl *ContextDecl = DCXX->getLambdaContextDecl();
3479 ExpectedDecl CDeclOrErr = import(ContextDecl);
3480 if (!CDeclOrErr)
3481 return CDeclOrErr.takeError();
3482 if (ContextDecl != nullptr) {
3483 D2CXX->setLambdaContextDecl(*CDeclOrErr);
3484 }
3485 D2CXX->setLambdaNumbering(DCXX->getLambdaNumbering());
3486 } else {
3487 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3488 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3489 Name.getAsIdentifierInfo(),
3490 cast_or_null<CXXRecordDecl>(PrevDecl)))
3491 return D2CXX;
3492 }
3493
3494 D2 = D2CXX;
3495 D2->setAccess(D->getAccess());
3496 D2->setLexicalDeclContext(LexicalDC);
3497 addDeclToContexts(D, D2);
3498
3499 if (ClassTemplateDecl *FromDescribed =
3500 DCXX->getDescribedClassTemplate()) {
3501 ClassTemplateDecl *ToDescribed;
3502 if (Error Err = importInto(ToDescribed, FromDescribed))
3503 return std::move(Err);
3504 D2CXX->setDescribedClassTemplate(ToDescribed);
3505 } else if (MemberSpecializationInfo *MemberInfo =
3506 DCXX->getMemberSpecializationInfo()) {
3508 MemberInfo->getTemplateSpecializationKind();
3510
3511 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3512 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3513 else
3514 return ToInstOrErr.takeError();
3515
3516 if (ExpectedSLoc POIOrErr =
3517 import(MemberInfo->getPointOfInstantiation()))
3519 *POIOrErr);
3520 else
3521 return POIOrErr.takeError();
3522 }
3523
3524 } else {
3525 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3526 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3527 Name.getAsIdentifierInfo(), PrevDecl))
3528 return D2;
3529 D2->setLexicalDeclContext(LexicalDC);
3530 addDeclToContexts(D, D2);
3531 }
3532
3533 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3534 D2->setBraceRange(*BraceRangeOrErr);
3535 else
3536 return BraceRangeOrErr.takeError();
3537 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3538 D2->setQualifierInfo(*QualifierLocOrErr);
3539 else
3540 return QualifierLocOrErr.takeError();
3541
3542 if (D->isAnonymousStructOrUnion())
3543 D2->setAnonymousStructOrUnion(true);
3544
3545 if (D->isCompleteDefinition())
3546 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3547 return std::move(Err);
3548
3549 return D2;
3550}
3551
3553 // Import the major distinguishing characteristics of this enumerator.
3554 DeclContext *DC, *LexicalDC;
3555 DeclarationName Name;
3556 SourceLocation Loc;
3557 NamedDecl *ToD;
3558 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3559 return std::move(Err);
3560 if (ToD)
3561 return ToD;
3562
3563 // Determine whether there are any other declarations with the same name and
3564 // in the same context.
3565 if (!LexicalDC->isFunctionOrMethod()) {
3566 SmallVector<NamedDecl *, 4> ConflictingDecls;
3567 unsigned IDNS = Decl::IDNS_Ordinary;
3568 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3569 for (auto *FoundDecl : FoundDecls) {
3570 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3571 continue;
3572
3573 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3574 if (IsStructuralMatch(D, FoundEnumConstant))
3575 return Importer.MapImported(D, FoundEnumConstant);
3576 ConflictingDecls.push_back(FoundDecl);
3577 }
3578 }
3579
3580 if (!ConflictingDecls.empty()) {
3581 ExpectedName NameOrErr = Importer.HandleNameConflict(
3582 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3583 if (NameOrErr)
3584 Name = NameOrErr.get();
3585 else
3586 return NameOrErr.takeError();
3587 }
3588 }
3589
3590 ExpectedType TypeOrErr = import(D->getType());
3591 if (!TypeOrErr)
3592 return TypeOrErr.takeError();
3593
3594 ExpectedExpr InitOrErr = import(D->getInitExpr());
3595 if (!InitOrErr)
3596 return InitOrErr.takeError();
3597
3598 EnumConstantDecl *ToEnumerator;
3599 if (GetImportedOrCreateDecl(
3600 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3601 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3602 return ToEnumerator;
3603
3604 ToEnumerator->setAccess(D->getAccess());
3605 ToEnumerator->setLexicalDeclContext(LexicalDC);
3606 LexicalDC->addDeclInternal(ToEnumerator);
3607 return ToEnumerator;
3608}
3609
3610template <typename DeclTy>
3612 DeclTy *ToD) {
3614 FromD->getTemplateParameterLists();
3615 if (FromTPLs.empty())
3616 return Error::success();
3617 SmallVector<TemplateParameterList *, 2> ToTPLists(FromTPLs.size());
3618 for (unsigned int I = 0; I < FromTPLs.size(); ++I)
3619 if (Expected<TemplateParameterList *> ToTPListOrErr = import(FromTPLs[I]))
3620 ToTPLists[I] = *ToTPListOrErr;
3621 else
3622 return ToTPListOrErr.takeError();
3623 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3624 return Error::success();
3625}
3626
3628 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3629 switch (FromFD->getTemplatedKind()) {
3632 return Error::success();
3633
3635 if (Expected<FunctionDecl *> InstFDOrErr =
3636 import(FromFD->getInstantiatedFromDecl()))
3637 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3638 return Error::success();
3641
3642 if (Expected<FunctionDecl *> InstFDOrErr =
3643 import(FromFD->getInstantiatedFromMemberFunction()))
3644 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3645 else
3646 return InstFDOrErr.takeError();
3647
3648 if (ExpectedSLoc POIOrErr = import(
3651 else
3652 return POIOrErr.takeError();
3653
3654 return Error::success();
3655 }
3656
3658 auto FunctionAndArgsOrErr =
3660 if (!FunctionAndArgsOrErr)
3661 return FunctionAndArgsOrErr.takeError();
3662
3664 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3665
3666 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3667 TemplateArgumentListInfo ToTAInfo;
3668 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3669 if (FromTAArgsAsWritten)
3671 *FromTAArgsAsWritten, ToTAInfo))
3672 return Err;
3673
3674 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3675 if (!POIOrErr)
3676 return POIOrErr.takeError();
3677
3678 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3679 return Err;
3680
3681 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3682 ToFD->setFunctionTemplateSpecialization(
3683 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3684 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3685 return Error::success();
3686 }
3687
3689 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3690 UnresolvedSet<8> Candidates;
3691 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3692 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3693 Candidates.addDecl(*ToFTDOrErr);
3694 else
3695 return ToFTDOrErr.takeError();
3696 }
3697
3698 // Import TemplateArgumentListInfo.
3699 TemplateArgumentListInfo ToTAInfo;
3700 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3701 if (FromTAArgsAsWritten)
3702 if (Error Err =
3703 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3704 return Err;
3705
3707 Importer.getToContext(), Candidates,
3708 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3709 return Error::success();
3710 }
3711 }
3712 llvm_unreachable("All cases should be covered!");
3713}
3714
3717 auto FunctionAndArgsOrErr =
3719 if (!FunctionAndArgsOrErr)
3720 return FunctionAndArgsOrErr.takeError();
3721
3723 TemplateArgsTy ToTemplArgs;
3724 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3725 void *InsertPos = nullptr;
3726 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3727 return FoundSpec;
3728}
3729
3731 FunctionDecl *ToFD) {
3732 if (Stmt *FromBody = FromFD->getBody()) {
3733 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3734 ToFD->setBody(*ToBodyOrErr);
3735 else
3736 return ToBodyOrErr.takeError();
3737 }
3738 return Error::success();
3739}
3740
3741// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3742// which is equal to the given DC, or D is equal to DC.
3743static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3744 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3745 if (!DCi)
3746 DCi = D->getDeclContext();
3747 assert(DCi && "Declaration should have a context");
3748 while (DCi != D->getTranslationUnitDecl()) {
3749 if (DCi == DC)
3750 return true;
3751 DCi = DCi->getParent();
3752 }
3753 return false;
3754}
3755
3756// Check if there is a declaration that has 'DC' as parent context and is
3757// referenced from statement 'S' or one of its children. The search is done in
3758// BFS order through children of 'S'.
3759static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3760 SmallVector<const Stmt *> ToProcess;
3761 ToProcess.push_back(S);
3762 while (!ToProcess.empty()) {
3763 const Stmt *CurrentS = ToProcess.pop_back_val();
3764 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3765 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3766 if (const Decl *D = DeclRef->getDecl())
3767 if (isAncestorDeclContextOf(DC, D))
3768 return true;
3769 } else if (const auto *E =
3770 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3771 if (const Decl *D = E->getAssociatedDecl())
3772 if (isAncestorDeclContextOf(DC, D))
3773 return true;
3774 }
3775 }
3776 return false;
3777}
3778
3779namespace {
3780/// Check if a type has any reference to a declaration that is inside the body
3781/// of a function.
3782/// The \c CheckType(QualType) function should be used to determine
3783/// this property.
3784///
3785/// The type visitor visits one type object only (not recursive).
3786/// To find all referenced declarations we must discover all type objects until
3787/// the canonical type is reached (walk over typedef and similar objects). This
3788/// is done by loop over all "sugar" type objects. For every such type we must
3789/// check all declarations that are referenced from it. For this check the
3790/// visitor is used. In the visit functions all referenced declarations except
3791/// the one that follows in the sugar chain (if any) must be checked. For this
3792/// check the same visitor is re-used (it has no state-dependent data).
3793///
3794/// The visit functions have 3 possible return values:
3795/// - True, found a declaration inside \c ParentDC.
3796/// - False, found declarations only outside \c ParentDC and it is not possible
3797/// to find more declarations (the "sugar" chain does not continue).
3798/// - Empty optional value, found no declarations or only outside \c ParentDC,
3799/// but it is possible to find more declarations in the type "sugar" chain.
3800/// The loop over the "sugar" types can be implemented by using type visit
3801/// functions only (call \c CheckType with the desugared type). With the current
3802/// solution no visit function is needed if the type has only a desugared type
3803/// as data.
3804class IsTypeDeclaredInsideVisitor
3805 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3806public:
3807 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3808 : ParentDC(ParentDC) {}
3809
3810 bool CheckType(QualType T) {
3811 // Check the chain of "sugar" types.
3812 // The "sugar" types are typedef or similar types that have the same
3813 // canonical type.
3814 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3815 return *Res;
3816 QualType DsT =
3817 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3818 while (DsT != T) {
3819 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3820 return *Res;
3821 T = DsT;
3822 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3823 }
3824 return false;
3825 }
3826
3827 std::optional<bool> VisitTagType(const TagType *T) {
3828 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3829 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3830 if (checkTemplateArgument(Arg))
3831 return true;
3832 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3833 }
3834
3835 std::optional<bool> VisitPointerType(const PointerType *T) {
3836 return CheckType(T->getPointeeType());
3837 }
3838
3839 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3840 return CheckType(T->getPointeeTypeAsWritten());
3841 }
3842
3843 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3844 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3845 }
3846
3847 std::optional<bool> VisitUsingType(const UsingType *T) {
3848 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3849 }
3850
3851 std::optional<bool>
3852 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3853 for (const auto &Arg : T->template_arguments())
3854 if (checkTemplateArgument(Arg))
3855 return true;
3856 // This type is a "sugar" to a record type, it can have a desugared type.
3857 return {};
3858 }
3859
3860 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3861 return CheckType(T->getBaseType());
3862 }
3863
3864 std::optional<bool>
3865 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3866 // The "associated declaration" can be the same as ParentDC.
3867 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3868 return true;
3869 return {};
3870 }
3871
3872 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3873 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3874 return true;
3875
3876 return CheckType(T->getElementType());
3877 }
3878
3879 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3880 llvm_unreachable(
3881 "Variable array should not occur in deduced return type of a function");
3882 }
3883
3884 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3885 llvm_unreachable("Incomplete array should not occur in deduced return type "
3886 "of a function");
3887 }
3888
3889 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3890 llvm_unreachable("Dependent array should not occur in deduced return type "
3891 "of a function");
3892 }
3893
3894private:
3895 const DeclContext *const ParentDC;
3896
3897 bool checkTemplateArgument(const TemplateArgument &Arg) {
3898 switch (Arg.getKind()) {
3900 return false;
3902 return CheckType(Arg.getIntegralType());
3904 return CheckType(Arg.getAsType());
3906 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3908 // FIXME: The declaration in this case is not allowed to be in a function?
3909 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3911 // FIXME: The type is not allowed to be in the function?
3912 return CheckType(Arg.getNullPtrType());
3914 return CheckType(Arg.getStructuralValueType());
3916 for (const auto &PackArg : Arg.getPackAsArray())
3917 if (checkTemplateArgument(PackArg))
3918 return true;
3919 return false;
3921 // Templates can not be defined locally in functions.
3922 // A template passed as argument can be not in ParentDC.
3923 return false;
3925 // Templates can not be defined locally in functions.
3926 // A template passed as argument can be not in ParentDC.
3927 return false;
3928 }
3929 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3930 };
3931};
3932} // namespace
3933
3934/// This function checks if the given function has a return type that contains
3935/// a reference (in any way) to a declaration inside the same function.
3937 QualType FromTy = D->getType();
3938 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3939 assert(FromFPT && "Must be called on FunctionProtoType");
3940
3941 auto IsCXX11Lambda = [&]() {
3942 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3943 return false;
3944
3945 return isLambdaMethod(D);
3946 };
3947
3948 QualType RetT = FromFPT->getReturnType();
3949 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3950 FunctionDecl *Def = D->getDefinition();
3951 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3952 return Visitor.CheckType(RetT);
3953 }
3954
3955 return false;
3956}
3957
3959ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3960 Expr *ExplicitExpr = ESpec.getExpr();
3961 if (ExplicitExpr)
3962 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3963 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3964}
3965
3967
3969 auto RedeclIt = Redecls.begin();
3970 // Import the first part of the decl chain. I.e. import all previous
3971 // declarations starting from the canonical decl.
3972 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3973 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3974 if (!ToRedeclOrErr)
3975 return ToRedeclOrErr.takeError();
3976 }
3977 assert(*RedeclIt == D);
3978
3979 // Import the major distinguishing characteristics of this function.
3980 DeclContext *DC, *LexicalDC;
3981 DeclarationName Name;
3982 SourceLocation Loc;
3983 NamedDecl *ToD;
3984 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3985 return std::move(Err);
3986 if (ToD)
3987 return ToD;
3988
3989 FunctionDecl *FoundByLookup = nullptr;
3991
3992 // If this is a function template specialization, then try to find the same
3993 // existing specialization in the "to" context. The lookup below will not
3994 // find any specialization, but would find the primary template; thus, we
3995 // have to skip normal lookup in case of specializations.
3996 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3997 if (D->getTemplatedKind() ==
3999 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
4000 if (!FoundFunctionOrErr)
4001 return FoundFunctionOrErr.takeError();
4002 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
4003 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
4004 return Def;
4005 FoundByLookup = FoundFunction;
4006 }
4007 }
4008 // Try to find a function in our own ("to") context with the same name, same
4009 // type, and in the same context as the function we're importing.
4010 else if (!LexicalDC->isFunctionOrMethod()) {
4011 SmallVector<NamedDecl *, 4> ConflictingDecls;
4013 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4014 for (auto *FoundDecl : FoundDecls) {
4015 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4016 continue;
4017
4018 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
4019 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
4020 continue;
4021
4022 if (IsStructuralMatch(D, FoundFunction)) {
4023 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
4024 return Def;
4025 FoundByLookup = FoundFunction;
4026 break;
4027 }
4028 // FIXME: Check for overloading more carefully, e.g., by boosting
4029 // Sema::IsOverload out to the AST library.
4030
4031 // Function overloading is okay in C++.
4032 if (Importer.getToContext().getLangOpts().CPlusPlus)
4033 continue;
4034
4035 // Complain about inconsistent function types.
4036 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
4037 << Name << D->getType() << FoundFunction->getType();
4038 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
4039 << FoundFunction->getType();
4040 ConflictingDecls.push_back(FoundDecl);
4041 }
4042 }
4043
4044 if (!ConflictingDecls.empty()) {
4045 ExpectedName NameOrErr = Importer.HandleNameConflict(
4046 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4047 if (NameOrErr)
4048 Name = NameOrErr.get();
4049 else
4050 return NameOrErr.takeError();
4051 }
4052 }
4053
4054 // We do not allow more than one in-class declaration of a function. This is
4055 // because AST clients like VTableBuilder asserts on this. VTableBuilder
4056 // assumes there is only one in-class declaration. Building a redecl
4057 // chain would result in more than one in-class declaration for
4058 // overrides (even if they are part of the same redecl chain inside the
4059 // derived class.)
4060 if (FoundByLookup) {
4061 if (isa<CXXMethodDecl>(FoundByLookup)) {
4062 if (D->getLexicalDeclContext() == D->getDeclContext()) {
4063 if (!D->doesThisDeclarationHaveABody()) {
4064 if (FunctionTemplateDecl *DescribedD =
4066 // Handle a "templated" function together with its described
4067 // template. This avoids need for a similar check at import of the
4068 // described template.
4069 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4070 "Templated function mapped to non-templated?");
4071 Importer.MapImported(DescribedD,
4072 FoundByLookup->getDescribedFunctionTemplate());
4073 }
4074 return Importer.MapImported(D, FoundByLookup);
4075 } else {
4076 // Let's continue and build up the redecl chain in this case.
4077 // FIXME Merge the functions into one decl.
4078 }
4079 }
4080 }
4081 }
4082
4083 DeclarationNameInfo NameInfo(Name, Loc);
4084 // Import additional name location/type info.
4085 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4086 return std::move(Err);
4087
4088 QualType FromTy = D->getType();
4089 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4090 // Set to true if we do not import the type of the function as is. There are
4091 // cases when the original type would result in an infinite recursion during
4092 // the import. To avoid an infinite recursion when importing, we create the
4093 // FunctionDecl with a simplified function type and update it only after the
4094 // relevant AST nodes are already imported.
4095 // The type is related to TypeSourceInfo (it references the type), so we must
4096 // do the same with TypeSourceInfo.
4097 bool UsedDifferentProtoType = false;
4098 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4099 QualType FromReturnTy = FromFPT->getReturnType();
4100 // Functions with auto return type may define a struct inside their body
4101 // and the return type could refer to that struct.
4102 // E.g.: auto foo() { struct X{}; return X(); }
4103 // To avoid an infinite recursion when importing, create the FunctionDecl
4104 // with a simplified return type.
4105 // Reuse this approach for auto return types declared as typenames from
4106 // template params, tracked in FindFunctionDeclImportCycle.
4108 Importer.FindFunctionDeclImportCycle.isCycle(D)) {
4109 FromReturnTy = Importer.getFromContext().VoidTy;
4110 UsedDifferentProtoType = true;
4111 }
4112 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4113 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4114 // FunctionDecl that we are importing the FunctionProtoType for.
4115 // To avoid an infinite recursion when importing, create the FunctionDecl
4116 // with a simplified function type.
4117 if (FromEPI.ExceptionSpec.SourceDecl ||
4118 FromEPI.ExceptionSpec.SourceTemplate ||
4119 FromEPI.ExceptionSpec.NoexceptExpr) {
4121 FromEPI = DefaultEPI;
4122 UsedDifferentProtoType = true;
4123 }
4124 FromTy = Importer.getFromContext().getFunctionType(
4125 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4126 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4127 FromTy, D->getBeginLoc());
4128 }
4129
4130 Error Err = Error::success();
4131 auto ScopedReturnTypeDeclCycleDetector =
4132 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
4133 auto T = importChecked(Err, FromTy);
4134 auto TInfo = importChecked(Err, FromTSI);
4135 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4136 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4137 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4138 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4139 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4140 TrailingRequiresClause.ConstraintExpr =
4141 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4142 if (Err)
4143 return std::move(Err);
4144
4145 // Import the function parameters.
4147 for (auto *P : D->parameters()) {
4148 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4149 Parameters.push_back(*ToPOrErr);
4150 else
4151 return ToPOrErr.takeError();
4152 }
4153
4154 // Create the imported function.
4155 FunctionDecl *ToFunction = nullptr;
4156 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4157 ExplicitSpecifier ESpec =
4158 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4159 if (Err)
4160 return std::move(Err);
4161 auto ToInheritedConstructor = InheritedConstructor();
4162 if (FromConstructor->isInheritingConstructor()) {
4163 Expected<InheritedConstructor> ImportedInheritedCtor =
4164 import(FromConstructor->getInheritedConstructor());
4165 if (!ImportedInheritedCtor)
4166 return ImportedInheritedCtor.takeError();
4167 ToInheritedConstructor = *ImportedInheritedCtor;
4168 }
4169 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4170 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4171 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4173 ToInheritedConstructor, TrailingRequiresClause))
4174 return ToFunction;
4175 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4176
4177 Error Err = Error::success();
4178 auto ToOperatorDelete = importChecked(
4179 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4180 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4181 if (Err)
4182 return std::move(Err);
4183
4184 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4185 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4186 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4188 TrailingRequiresClause))
4189 return ToFunction;
4190
4191 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4192
4193 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4194 } else if (CXXConversionDecl *FromConversion =
4195 dyn_cast<CXXConversionDecl>(D)) {
4196 ExplicitSpecifier ESpec =
4197 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4198 if (Err)
4199 return std::move(Err);
4200 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4201 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4202 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4203 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4204 SourceLocation(), TrailingRequiresClause))
4205 return ToFunction;
4206 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4207 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4208 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4209 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4210 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4211 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4212 return ToFunction;
4213 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4214 ExplicitSpecifier ESpec =
4215 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4216 CXXConstructorDecl *Ctor =
4217 importChecked(Err, Guide->getCorrespondingConstructor());
4218 const CXXDeductionGuideDecl *SourceDG =
4219 importChecked(Err, Guide->getSourceDeductionGuide());
4220 if (Err)
4221 return std::move(Err);
4222 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4223 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4224 NameInfo, T, TInfo, ToEndLoc, Ctor,
4225 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4226 SourceDG, Guide->getSourceDeductionGuideKind()))
4227 return ToFunction;
4228 } else {
4229 if (GetImportedOrCreateDecl(
4230 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4231 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4233 D->getConstexprKind(), TrailingRequiresClause))
4234 return ToFunction;
4235 }
4236
4237 // Connect the redecl chain.
4238 if (FoundByLookup) {
4239 auto *Recent = const_cast<FunctionDecl *>(
4240 FoundByLookup->getMostRecentDecl());
4241 ToFunction->setPreviousDecl(Recent);
4242 // FIXME Probably we should merge exception specifications. E.g. In the
4243 // "To" context the existing function may have exception specification with
4244 // noexcept-unevaluated, while the newly imported function may have an
4245 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4246 // decl and its redeclarations may be required.
4247 }
4248
4249 StringLiteral *Msg = D->getDeletedMessage();
4250 if (Msg) {
4251 auto Imported = import(Msg);
4252 if (!Imported)
4253 return Imported.takeError();
4254 Msg = *Imported;
4255 }
4256
4257 ToFunction->setQualifierInfo(ToQualifierLoc);
4258 ToFunction->setAccess(D->getAccess());
4259 ToFunction->setLexicalDeclContext(LexicalDC);
4260 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4261 ToFunction->setTrivial(D->isTrivial());
4262 ToFunction->setIsPureVirtual(D->isPureVirtual());
4263 ToFunction->setDefaulted(D->isDefaulted());
4265 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4271 ToFunction->setRangeEnd(ToEndLoc);
4272 ToFunction->setDefaultLoc(ToDefaultLoc);
4273
4274 if (Msg)
4275 ToFunction->setDefaultedOrDeletedInfo(
4277 Importer.getToContext(), {}, Msg));
4278
4279 // Set the parameters.
4280 for (auto *Param : Parameters) {
4281 Param->setOwningFunction(ToFunction);
4282 ToFunction->addDeclInternal(Param);
4283 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4284 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4285 }
4286 ToFunction->setParams(Parameters);
4287
4288 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4289 // params it refers to.
4290 if (TInfo) {
4291 if (auto ProtoLoc =
4292 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4293 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4294 ProtoLoc.setParam(I, Parameters[I]);
4295 }
4296 }
4297
4298 // Import the describing template function, if any.
4299 if (FromFT) {
4300 auto ToFTOrErr = import(FromFT);
4301 if (!ToFTOrErr)
4302 return ToFTOrErr.takeError();
4303 }
4304
4305 // Import Ctor initializers.
4306 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4307 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4308 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4309 // Import first, then allocate memory and copy if there was no error.
4310 if (Error Err = ImportContainerChecked(
4311 FromConstructor->inits(), CtorInitializers))
4312 return std::move(Err);
4313 auto **Memory =
4314 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4315 llvm::copy(CtorInitializers, Memory);
4316 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4317 ToCtor->setCtorInitializers(Memory);
4318 ToCtor->setNumCtorInitializers(NumInitializers);
4319 }
4320 }
4321
4322 // If it is a template, import all related things.
4323 if (Error Err = ImportTemplateInformation(D, ToFunction))
4324 return std::move(Err);
4325
4326 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4328 FromCXXMethod))
4329 return std::move(Err);
4330
4332 Error Err = ImportFunctionDeclBody(D, ToFunction);
4333
4334 if (Err)
4335 return std::move(Err);
4336 }
4337
4338 // Import and set the original type in case we used another type.
4339 if (UsedDifferentProtoType) {
4340 if (ExpectedType TyOrErr = import(D->getType()))
4341 ToFunction->setType(*TyOrErr);
4342 else
4343 return TyOrErr.takeError();
4344 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4345 ToFunction->setTypeSourceInfo(*TSIOrErr);
4346 else
4347 return TSIOrErr.takeError();
4348 }
4349
4350 // FIXME: Other bits to merge?
4351
4352 addDeclToContexts(D, ToFunction);
4353
4354 // Import the rest of the chain. I.e. import all subsequent declarations.
4355 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4356 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4357 if (!ToRedeclOrErr)
4358 return ToRedeclOrErr.takeError();
4359 }
4360
4361 return ToFunction;
4362}
4363
4367
4371
4375
4379
4384
4386 // Import the major distinguishing characteristics of a variable.
4387 DeclContext *DC, *LexicalDC;
4388 DeclarationName Name;
4389 SourceLocation Loc;
4390 NamedDecl *ToD;
4391 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4392 return std::move(Err);
4393 if (ToD)
4394 return ToD;
4395
4396 // Determine whether we've already imported this field.
4397 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4398 for (auto *FoundDecl : FoundDecls) {
4399 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4400 // For anonymous fields, match up by index.
4401 if (!Name &&
4403 ASTImporter::getFieldIndex(FoundField))
4404 continue;
4405
4406 if (Importer.IsStructurallyEquivalent(D->getType(),
4407 FoundField->getType())) {
4408 Importer.MapImported(D, FoundField);
4409 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4410 // initializer of a FieldDecl might not had been instantiated in the
4411 // "To" context. However, the "From" context might instantiated that,
4412 // thus we have to merge that.
4413 // Note: `hasInClassInitializer()` is not the same as non-null
4414 // `getInClassInitializer()` value.
4415 if (Expr *FromInitializer = D->getInClassInitializer()) {
4416 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4417 // Import of the FromInitializer may result in the setting of
4418 // InClassInitializer. If not, set it here.
4419 assert(FoundField->hasInClassInitializer() &&
4420 "Field should have an in-class initializer if it has an "
4421 "expression for it.");
4422 if (!FoundField->getInClassInitializer())
4423 FoundField->setInClassInitializer(*ToInitializerOrErr);
4424 } else {
4425 return ToInitializerOrErr.takeError();
4426 }
4427 }
4428 return FoundField;
4429 }
4430
4431 // FIXME: Why is this case not handled with calling HandleNameConflict?
4432 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4433 << Name << D->getType() << FoundField->getType();
4434 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4435 << FoundField->getType();
4436
4437 return make_error<ASTImportError>(ASTImportError::NameConflict);
4438 }
4439 }
4440
4441 Error Err = Error::success();
4442 auto ToType = importChecked(Err, D->getType());
4443 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4444 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4445 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4446 if (Err)
4447 return std::move(Err);
4448 const Type *ToCapturedVLAType = nullptr;
4449 if (Error Err = Importer.importInto(
4450 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4451 return std::move(Err);
4452
4453 FieldDecl *ToField;
4454 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4455 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4456 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4457 D->getInClassInitStyle()))
4458 return ToField;
4459
4460 ToField->setAccess(D->getAccess());
4461 ToField->setLexicalDeclContext(LexicalDC);
4462 ToField->setImplicit(D->isImplicit());
4463 if (ToCapturedVLAType)
4464 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4465 LexicalDC->addDeclInternal(ToField);
4466 // Import initializer only after the field was created, it may have recursive
4467 // reference to the field.
4468 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4469 if (Err)
4470 return std::move(Err);
4471 if (ToInitializer) {
4472 auto *AlreadyImported = ToField->getInClassInitializer();
4473 if (AlreadyImported)
4474 assert(ToInitializer == AlreadyImported &&
4475 "Duplicate import of in-class initializer.");
4476 else
4477 ToField->setInClassInitializer(ToInitializer);
4478 }
4479
4480 return ToField;
4481}
4482
4484 // Import the major distinguishing characteristics of a variable.
4485 DeclContext *DC, *LexicalDC;
4486 DeclarationName Name;
4487 SourceLocation Loc;
4488 NamedDecl *ToD;
4489 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4490 return std::move(Err);
4491 if (ToD)
4492 return ToD;
4493
4494 // Determine whether we've already imported this field.
4495 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4496 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4497 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4498 // For anonymous indirect fields, match up by index.
4499 if (!Name &&
4501 ASTImporter::getFieldIndex(FoundField))
4502 continue;
4503
4504 if (Importer.IsStructurallyEquivalent(D->getType(),
4505 FoundField->getType(),
4506 !Name.isEmpty())) {
4507 Importer.MapImported(D, FoundField);
4508 return FoundField;
4509 }
4510
4511 // If there are more anonymous fields to check, continue.
4512 if (!Name && I < N-1)
4513 continue;
4514
4515 // FIXME: Why is this case not handled with calling HandleNameConflict?
4516 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4517 << Name << D->getType() << FoundField->getType();
4518 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4519 << FoundField->getType();
4520
4521 return make_error<ASTImportError>(ASTImportError::NameConflict);
4522 }
4523 }
4524
4525 // Import the type.
4526 auto TypeOrErr = import(D->getType());
4527 if (!TypeOrErr)
4528 return TypeOrErr.takeError();
4529
4530 auto **NamedChain =
4531 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4532
4533 unsigned i = 0;
4534 for (auto *PI : D->chain())
4535 if (Expected<NamedDecl *> ToD = import(PI))
4536 NamedChain[i++] = *ToD;
4537 else
4538 return ToD.takeError();
4539
4540 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4541 IndirectFieldDecl *ToIndirectField;
4542 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4543 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4544 // FIXME here we leak `NamedChain` which is allocated before
4545 return ToIndirectField;
4546
4547 ToIndirectField->setAccess(D->getAccess());
4548 ToIndirectField->setLexicalDeclContext(LexicalDC);
4549 LexicalDC->addDeclInternal(ToIndirectField);
4550 return ToIndirectField;
4551}
4552
4553/// Used as return type of getFriendCountAndPosition.
4555 /// Number of similar looking friends.
4556 unsigned int TotalCount;
4557 /// Index of the specific FriendDecl.
4558 unsigned int IndexOfDecl;
4559};
4560
4561static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4562 FriendDecl *FD2) {
4563 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4564 return false;
4565
4566 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4567 return Importer.IsStructurallyEquivalent(
4568 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4569
4570 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4572 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4573 FD2->getASTContext(), NonEquivalentDecls,
4575 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4576 return Ctx.IsEquivalent(FD1, FD2);
4577}
4578
4580 FriendDecl *FD) {
4581 unsigned int FriendCount = 0;
4582 UnsignedOrNone FriendPosition = std::nullopt;
4583 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4584
4585 for (FriendDecl *FoundFriend : RD->friends()) {
4586 if (FoundFriend == FD) {
4587 FriendPosition = FriendCount;
4588 ++FriendCount;
4589 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4590 ++FriendCount;
4591 }
4592 }
4593
4594 assert(FriendPosition && "Friend decl not found in own parent.");
4595
4596 return {FriendCount, *FriendPosition};
4597}
4598
4600 // Import the major distinguishing characteristics of a declaration.
4601 DeclContext *DC, *LexicalDC;
4602 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4603 return std::move(Err);
4604
4605 // Determine whether we've already imported this decl.
4606 // FriendDecl is not a NamedDecl so we cannot use lookup.
4607 // We try to maintain order and count of redundant friend declarations.
4608 const auto *RD = cast<CXXRecordDecl>(DC);
4609 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4610 for (FriendDecl *ImportedFriend : RD->friends())
4611 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4612 ImportedEquivalentFriends.push_back(ImportedFriend);
4613
4614 FriendCountAndPosition CountAndPosition =
4615 getFriendCountAndPosition(Importer, D);
4616
4617 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4618 "Class with non-matching friends is imported, ODR check wrong?");
4619 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4620 return Importer.MapImported(
4621 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4622
4623 // Not found. Create it.
4624 // The declarations will be put into order later by ImportDeclContext.
4626 if (NamedDecl *FriendD = D->getFriendDecl()) {
4627 NamedDecl *ToFriendD;
4628 if (Error Err = importInto(ToFriendD, FriendD))
4629 return std::move(Err);
4630
4631 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4632 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4633 ToFriendD->setObjectOfFriendDecl(false);
4634
4635 ToFU = ToFriendD;
4636 } else { // The friend is a type, not a decl.
4637 if (auto TSIOrErr = import(D->getFriendType()))
4638 ToFU = *TSIOrErr;
4639 else
4640 return TSIOrErr.takeError();
4641 }
4642
4643 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4644 auto **FromTPLists = D->getTrailingObjects();
4645 for (unsigned I = 0; I < D->NumTPLists; I++) {
4646 if (auto ListOrErr = import(FromTPLists[I]))
4647 ToTPLists[I] = *ListOrErr;
4648 else
4649 return ListOrErr.takeError();
4650 }
4651
4652 auto LocationOrErr = import(D->getLocation());
4653 if (!LocationOrErr)
4654 return LocationOrErr.takeError();
4655 auto FriendLocOrErr = import(D->getFriendLoc());
4656 if (!FriendLocOrErr)
4657 return FriendLocOrErr.takeError();
4658 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4659 if (!EllipsisLocOrErr)
4660 return EllipsisLocOrErr.takeError();
4661
4662 FriendDecl *FrD;
4663 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4664 *LocationOrErr, ToFU, *FriendLocOrErr,
4665 *EllipsisLocOrErr, ToTPLists))
4666 return FrD;
4667
4668 FrD->setAccess(D->getAccess());
4669 FrD->setLexicalDeclContext(LexicalDC);
4670 LexicalDC->addDeclInternal(FrD);
4671 return FrD;
4672}
4673
4675 // Import the major distinguishing characteristics of an ivar.
4676 DeclContext *DC, *LexicalDC;
4677 DeclarationName Name;
4678 SourceLocation Loc;
4679 NamedDecl *ToD;
4680 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4681 return std::move(Err);
4682 if (ToD)
4683 return ToD;
4684
4685 // Determine whether we've already imported this ivar
4686 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4687 for (auto *FoundDecl : FoundDecls) {
4688 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4689 if (Importer.IsStructurallyEquivalent(D->getType(),
4690 FoundIvar->getType())) {
4691 Importer.MapImported(D, FoundIvar);
4692 return FoundIvar;
4693 }
4694
4695 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4696 << Name << D->getType() << FoundIvar->getType();
4697 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4698 << FoundIvar->getType();
4699
4700 return make_error<ASTImportError>(ASTImportError::NameConflict);
4701 }
4702 }
4703
4704 Error Err = Error::success();
4705 auto ToType = importChecked(Err, D->getType());
4706 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4707 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4708 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4709 if (Err)
4710 return std::move(Err);
4711
4712 ObjCIvarDecl *ToIvar;
4713 if (GetImportedOrCreateDecl(
4714 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4715 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4716 ToType, ToTypeSourceInfo,
4717 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4718 return ToIvar;
4719
4720 ToIvar->setLexicalDeclContext(LexicalDC);
4721 LexicalDC->addDeclInternal(ToIvar);
4722 return ToIvar;
4723}
4724
4726
4728 auto RedeclIt = Redecls.begin();
4729 // Import the first part of the decl chain. I.e. import all previous
4730 // declarations starting from the canonical decl.
4731 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4732 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4733 if (!RedeclOrErr)
4734 return RedeclOrErr.takeError();
4735 }
4736 assert(*RedeclIt == D);
4737
4738 // Import the major distinguishing characteristics of a variable.
4739 DeclContext *DC, *LexicalDC;
4740 DeclarationName Name;
4741 SourceLocation Loc;
4742 NamedDecl *ToD;
4743 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4744 return std::move(Err);
4745 if (ToD)
4746 return ToD;
4747
4748 // Try to find a variable in our own ("to") context with the same name and
4749 // in the same context as the variable we're importing.
4750 VarDecl *FoundByLookup = nullptr;
4751 if (D->isFileVarDecl()) {
4752 SmallVector<NamedDecl *, 4> ConflictingDecls;
4753 unsigned IDNS = Decl::IDNS_Ordinary;
4754 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4755 for (auto *FoundDecl : FoundDecls) {
4756 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4757 continue;
4758
4759 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4760 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4761 continue;
4762 if (Importer.IsStructurallyEquivalent(D->getType(),
4763 FoundVar->getType())) {
4764
4765 // The VarDecl in the "From" context has a definition, but in the
4766 // "To" context we already have a definition.
4767 VarDecl *FoundDef = FoundVar->getDefinition();
4768 if (D->isThisDeclarationADefinition() && FoundDef)
4769 // FIXME Check for ODR error if the two definitions have
4770 // different initializers?
4771 return Importer.MapImported(D, FoundDef);
4772
4773 // The VarDecl in the "From" context has an initializer, but in the
4774 // "To" context we already have an initializer.
4775 const VarDecl *FoundDInit = nullptr;
4776 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4777 // FIXME Diagnose ODR error if the two initializers are different?
4778 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4779
4780 FoundByLookup = FoundVar;
4781 break;
4782 }
4783
4784 const ArrayType *FoundArray
4785 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4786 const ArrayType *TArray
4787 = Importer.getToContext().getAsArrayType(D->getType());
4788 if (FoundArray && TArray) {
4789 if (isa<IncompleteArrayType>(FoundArray) &&
4790 isa<ConstantArrayType>(TArray)) {
4791 // Import the type.
4792 if (auto TyOrErr = import(D->getType()))
4793 FoundVar->setType(*TyOrErr);
4794 else
4795 return TyOrErr.takeError();
4796
4797 FoundByLookup = FoundVar;
4798 break;
4799 } else if (isa<IncompleteArrayType>(TArray) &&
4800 isa<ConstantArrayType>(FoundArray)) {
4801 FoundByLookup = FoundVar;
4802 break;
4803 }
4804 }
4805
4806 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4807 << Name << D->getType() << FoundVar->getType();
4808 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4809 << FoundVar->getType();
4810 ConflictingDecls.push_back(FoundDecl);
4811 }
4812 }
4813
4814 if (!ConflictingDecls.empty()) {
4815 ExpectedName NameOrErr = Importer.HandleNameConflict(
4816 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4817 if (NameOrErr)
4818 Name = NameOrErr.get();
4819 else
4820 return NameOrErr.takeError();
4821 }
4822 }
4823
4824 Error Err = Error::success();
4825 auto ToType = importChecked(Err, D->getType());
4826 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4827 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4828 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4829 if (Err)
4830 return std::move(Err);
4831
4832 VarDecl *ToVar;
4833 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4834 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4835 if (Error Err =
4836 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4837 return std::move(Err);
4838 DecompositionDecl *ToDecomp;
4839 if (GetImportedOrCreateDecl(
4840 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4841 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4842 return ToDecomp;
4843 ToVar = ToDecomp;
4844 } else {
4845 // Create the imported variable.
4846 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4847 ToInnerLocStart, Loc,
4848 Name.getAsIdentifierInfo(), ToType,
4849 ToTypeSourceInfo, D->getStorageClass()))
4850 return ToVar;
4851 }
4852
4853 ToVar->setTSCSpec(D->getTSCSpec());
4854 ToVar->setQualifierInfo(ToQualifierLoc);
4855 ToVar->setAccess(D->getAccess());
4856 ToVar->setLexicalDeclContext(LexicalDC);
4857 if (D->isInlineSpecified())
4858 ToVar->setInlineSpecified();
4859 if (D->isInline())
4860 ToVar->setImplicitlyInline();
4861
4862 if (FoundByLookup) {
4863 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4864 ToVar->setPreviousDecl(Recent);
4865 }
4866
4867 // Import the described template, if any.
4868 if (D->getDescribedVarTemplate()) {
4869 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4870 if (!ToVTOrErr)
4871 return ToVTOrErr.takeError();
4873 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4875 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4876 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4877 else
4878 return ToInstOrErr.takeError();
4879 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4881 else
4882 return POIOrErr.takeError();
4883 }
4884
4885 if (Error Err = ImportInitializer(D, ToVar))
4886 return std::move(Err);
4887
4888 if (D->isConstexpr())
4889 ToVar->setConstexpr(true);
4890
4891 addDeclToContexts(D, ToVar);
4892
4893 // Import the rest of the chain. I.e. import all subsequent declarations.
4894 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4895 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4896 if (!RedeclOrErr)
4897 return RedeclOrErr.takeError();
4898 }
4899
4900 return ToVar;
4901}
4902
4904 // Parameters are created in the translation unit's context, then moved
4905 // into the function declaration's context afterward.
4906 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4907
4908 Error Err = Error::success();
4909 auto ToDeclName = importChecked(Err, D->getDeclName());
4910 auto ToLocation = importChecked(Err, D->getLocation());
4911 auto ToType = importChecked(Err, D->getType());
4912 if (Err)
4913 return std::move(Err);
4914
4915 // Create the imported parameter.
4916 ImplicitParamDecl *ToParm = nullptr;
4917 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4918 ToLocation, ToDeclName.getAsIdentifierInfo(),
4919 ToType, D->getParameterKind()))
4920 return ToParm;
4921 return ToParm;
4922}
4923
4925 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4926
4927 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4928 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4929 else
4930 return LocOrErr.takeError();
4931
4933 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4934
4935 if (FromParam->hasUninstantiatedDefaultArg()) {
4936 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4937 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4938 else
4939 return ToDefArgOrErr.takeError();
4940 } else if (FromParam->hasUnparsedDefaultArg()) {
4941 ToParam->setUnparsedDefaultArg();
4942 } else if (FromParam->hasDefaultArg()) {
4943 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4944 ToParam->setDefaultArg(*ToDefArgOrErr);
4945 else
4946 return ToDefArgOrErr.takeError();
4947 }
4948
4949 return Error::success();
4950}
4951
4954 Error Err = Error::success();
4955 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4956 ConstructorUsingShadowDecl *ToShadow =
4957 importChecked(Err, From.getShadowDecl());
4958 if (Err)
4959 return std::move(Err);
4960 return InheritedConstructor(ToShadow, ToBaseCtor);
4961}
4962
4964 // Parameters are created in the translation unit's context, then moved
4965 // into the function declaration's context afterward.
4966 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4967
4968 Error Err = Error::success();
4969 auto ToDeclName = importChecked(Err, D->getDeclName());
4970 auto ToLocation = importChecked(Err, D->getLocation());
4971 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4972 auto ToType = importChecked(Err, D->getType());
4973 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4974 if (Err)
4975 return std::move(Err);
4976
4977 ParmVarDecl *ToParm;
4978 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4979 ToInnerLocStart, ToLocation,
4980 ToDeclName.getAsIdentifierInfo(), ToType,
4981 ToTypeSourceInfo, D->getStorageClass(),
4982 /*DefaultArg*/ nullptr))
4983 return ToParm;
4984
4985 // Set the default argument. It should be no problem if it was already done.
4986 // Do not import the default expression before GetImportedOrCreateDecl call
4987 // to avoid possible infinite import loop because circular dependency.
4988 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4989 return std::move(Err);
4990
4991 if (D->isObjCMethodParameter()) {
4994 } else {
4997 }
4998
4999 return ToParm;
5000}
5001
5003 // Import the major distinguishing characteristics of a method.
5004 DeclContext *DC, *LexicalDC;
5005 DeclarationName Name;
5006 SourceLocation Loc;
5007 NamedDecl *ToD;
5008 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5009 return std::move(Err);
5010 if (ToD)
5011 return ToD;
5012
5013 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5014 for (auto *FoundDecl : FoundDecls) {
5015 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
5016 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
5017 continue;
5018
5019 // Check return types.
5020 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
5021 FoundMethod->getReturnType())) {
5022 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
5023 << D->isInstanceMethod() << Name << D->getReturnType()
5024 << FoundMethod->getReturnType();
5025 Importer.ToDiag(FoundMethod->getLocation(),
5026 diag::note_odr_objc_method_here)
5027 << D->isInstanceMethod() << Name;
5028
5029 return make_error<ASTImportError>(ASTImportError::NameConflict);
5030 }
5031
5032 // Check the number of parameters.
5033 if (D->param_size() != FoundMethod->param_size()) {
5034 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
5035 << D->isInstanceMethod() << Name
5036 << D->param_size() << FoundMethod->param_size();
5037 Importer.ToDiag(FoundMethod->getLocation(),
5038 diag::note_odr_objc_method_here)
5039 << D->isInstanceMethod() << Name;
5040
5041 return make_error<ASTImportError>(ASTImportError::NameConflict);
5042 }
5043
5044 // Check parameter types.
5046 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
5047 P != PEnd; ++P, ++FoundP) {
5048 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
5049 (*FoundP)->getType())) {
5050 Importer.FromDiag((*P)->getLocation(),
5051 diag::warn_odr_objc_method_param_type_inconsistent)
5052 << D->isInstanceMethod() << Name
5053 << (*P)->getType() << (*FoundP)->getType();
5054 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
5055 << (*FoundP)->getType();
5056
5057 return make_error<ASTImportError>(ASTImportError::NameConflict);
5058 }
5059 }
5060
5061 // Check variadic/non-variadic.
5062 // Check the number of parameters.
5063 if (D->isVariadic() != FoundMethod->isVariadic()) {
5064 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
5065 << D->isInstanceMethod() << Name;
5066 Importer.ToDiag(FoundMethod->getLocation(),
5067 diag::note_odr_objc_method_here)
5068 << D->isInstanceMethod() << Name;
5069
5070 return make_error<ASTImportError>(ASTImportError::NameConflict);
5071 }
5072
5073 // FIXME: Any other bits we need to merge?
5074 return Importer.MapImported(D, FoundMethod);
5075 }
5076 }
5077
5078 Error Err = Error::success();
5079 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5080 auto ToReturnType = importChecked(Err, D->getReturnType());
5081 auto ToReturnTypeSourceInfo =
5083 if (Err)
5084 return std::move(Err);
5085
5086 ObjCMethodDecl *ToMethod;
5087 if (GetImportedOrCreateDecl(
5088 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5089 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5093 return ToMethod;
5094
5095 // FIXME: When we decide to merge method definitions, we'll need to
5096 // deal with implicit parameters.
5097
5098 // Import the parameters
5100 for (auto *FromP : D->parameters()) {
5101 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5102 ToParams.push_back(*ToPOrErr);
5103 else
5104 return ToPOrErr.takeError();
5105 }
5106
5107 // Set the parameters.
5108 for (auto *ToParam : ToParams) {
5109 ToParam->setOwningFunction(ToMethod);
5110 ToMethod->addDeclInternal(ToParam);
5111 }
5112
5114 D->getSelectorLocs(FromSelLocs);
5115 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5116 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5117 return std::move(Err);
5118
5119 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5120
5121 ToMethod->setLexicalDeclContext(LexicalDC);
5122 LexicalDC->addDeclInternal(ToMethod);
5123
5124 // Implicit params are declared when Sema encounters the definition but this
5125 // never happens when the method is imported. Manually declare the implicit
5126 // params now that the MethodDecl knows its class interface.
5127 if (D->getSelfDecl())
5128 ToMethod->createImplicitParams(Importer.getToContext(),
5129 ToMethod->getClassInterface());
5130
5131 return ToMethod;
5132}
5133
5135 // Import the major distinguishing characteristics of a category.
5136 DeclContext *DC, *LexicalDC;
5137 DeclarationName Name;
5138 SourceLocation Loc;
5139 NamedDecl *ToD;
5140 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5141 return std::move(Err);
5142 if (ToD)
5143 return ToD;
5144
5145 Error Err = Error::success();
5146 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5147 auto ToLocation = importChecked(Err, D->getLocation());
5148 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5149 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5150 if (Err)
5151 return std::move(Err);
5152
5154 if (GetImportedOrCreateDecl(
5155 Result, D, Importer.getToContext(), DC, D->getVariance(),
5156 ToVarianceLoc, D->getIndex(),
5157 ToLocation, Name.getAsIdentifierInfo(),
5158 ToColonLoc, ToTypeSourceInfo))
5159 return Result;
5160
5161 // Only import 'ObjCTypeParamType' after the decl is created.
5162 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5163 if (Err)
5164 return std::move(Err);
5165 Result->setTypeForDecl(ToTypeForDecl);
5166 Result->setLexicalDeclContext(LexicalDC);
5167 return Result;
5168}
5169
5171 // Import the major distinguishing characteristics of a category.
5172 DeclContext *DC, *LexicalDC;
5173 DeclarationName Name;
5174 SourceLocation Loc;
5175 NamedDecl *ToD;
5176 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5177 return std::move(Err);
5178 if (ToD)
5179 return ToD;
5180
5181 ObjCInterfaceDecl *ToInterface;
5182 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5183 return std::move(Err);
5184
5185 // Determine if we've already encountered this category.
5186 ObjCCategoryDecl *MergeWithCategory
5187 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5188 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5189 if (!ToCategory) {
5190
5191 Error Err = Error::success();
5192 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5193 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5194 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5195 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5196 if (Err)
5197 return std::move(Err);
5198
5199 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5200 ToAtStartLoc, Loc,
5201 ToCategoryNameLoc,
5202 Name.getAsIdentifierInfo(), ToInterface,
5203 /*TypeParamList=*/nullptr,
5204 ToIvarLBraceLoc,
5205 ToIvarRBraceLoc))
5206 return ToCategory;
5207
5208 ToCategory->setLexicalDeclContext(LexicalDC);
5209 LexicalDC->addDeclInternal(ToCategory);
5210 // Import the type parameter list after MapImported, to avoid
5211 // loops when bringing in their DeclContext.
5212 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5213 ToCategory->setTypeParamList(*PListOrErr);
5214 else
5215 return PListOrErr.takeError();
5216
5217 // Import protocols
5219 SmallVector<SourceLocation, 4> ProtocolLocs;
5221 = D->protocol_loc_begin();
5223 FromProtoEnd = D->protocol_end();
5224 FromProto != FromProtoEnd;
5225 ++FromProto, ++FromProtoLoc) {
5226 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5227 Protocols.push_back(*ToProtoOrErr);
5228 else
5229 return ToProtoOrErr.takeError();
5230
5231 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5232 ProtocolLocs.push_back(*ToProtoLocOrErr);
5233 else
5234 return ToProtoLocOrErr.takeError();
5235 }
5236
5237 // FIXME: If we're merging, make sure that the protocol list is the same.
5238 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5239 ProtocolLocs.data(), Importer.getToContext());
5240
5241 } else {
5242 Importer.MapImported(D, ToCategory);
5243 }
5244
5245 // Import all of the members of this category.
5246 if (Error Err = ImportDeclContext(D))
5247 return std::move(Err);
5248
5249 // If we have an implementation, import it as well.
5250 if (D->getImplementation()) {
5251 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5252 import(D->getImplementation()))
5253 ToCategory->setImplementation(*ToImplOrErr);
5254 else
5255 return ToImplOrErr.takeError();
5256 }
5257
5258 return ToCategory;
5259}
5260
5263 if (To->getDefinition()) {
5265 if (Error Err = ImportDeclContext(From))
5266 return Err;
5267 return Error::success();
5268 }
5269
5270 // Start the protocol definition
5271 To->startDefinition();
5272
5273 // Import protocols
5275 SmallVector<SourceLocation, 4> ProtocolLocs;
5277 From->protocol_loc_begin();
5278 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5279 FromProtoEnd = From->protocol_end();
5280 FromProto != FromProtoEnd;
5281 ++FromProto, ++FromProtoLoc) {
5282 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5283 Protocols.push_back(*ToProtoOrErr);
5284 else
5285 return ToProtoOrErr.takeError();
5286
5287 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5288 ProtocolLocs.push_back(*ToProtoLocOrErr);
5289 else
5290 return ToProtoLocOrErr.takeError();
5291
5292 }
5293
5294 // FIXME: If we're merging, make sure that the protocol list is the same.
5295 To->setProtocolList(Protocols.data(), Protocols.size(),
5296 ProtocolLocs.data(), Importer.getToContext());
5297
5298 if (shouldForceImportDeclContext(Kind)) {
5299 // Import all of the members of this protocol.
5300 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5301 return Err;
5302 }
5303 return Error::success();
5304}
5305
5307 // If this protocol has a definition in the translation unit we're coming
5308 // from, but this particular declaration is not that definition, import the
5309 // definition and map to that.
5311 if (Definition && Definition != D) {
5312 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5313 return Importer.MapImported(D, *ImportedDefOrErr);
5314 else
5315 return ImportedDefOrErr.takeError();
5316 }
5317
5318 // Import the major distinguishing characteristics of a protocol.
5319 DeclContext *DC, *LexicalDC;
5320 DeclarationName Name;
5321 SourceLocation Loc;
5322 NamedDecl *ToD;
5323 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5324 return std::move(Err);
5325 if (ToD)
5326 return ToD;
5327
5328 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5329 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5330 for (auto *FoundDecl : FoundDecls) {
5331 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5332 continue;
5333
5334 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5335 break;
5336 }
5337
5338 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5339 if (!ToProto) {
5340 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5341 if (!ToAtBeginLocOrErr)
5342 return ToAtBeginLocOrErr.takeError();
5343
5344 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5345 Name.getAsIdentifierInfo(), Loc,
5346 *ToAtBeginLocOrErr,
5347 /*PrevDecl=*/nullptr))
5348 return ToProto;
5349 ToProto->setLexicalDeclContext(LexicalDC);
5350 LexicalDC->addDeclInternal(ToProto);
5351 }
5352
5353 Importer.MapImported(D, ToProto);
5354
5356 if (Error Err = ImportDefinition(D, ToProto))
5357 return std::move(Err);
5358
5359 return ToProto;
5360}
5361
5363 DeclContext *DC, *LexicalDC;
5364 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5365 return std::move(Err);
5366
5367 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5368 if (!ExternLocOrErr)
5369 return ExternLocOrErr.takeError();
5370
5371 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5372 if (!LangLocOrErr)
5373 return LangLocOrErr.takeError();
5374
5375 bool HasBraces = D->hasBraces();
5376
5377 LinkageSpecDecl *ToLinkageSpec;
5378 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5379 *ExternLocOrErr, *LangLocOrErr,
5380 D->getLanguage(), HasBraces))
5381 return ToLinkageSpec;
5382
5383 if (HasBraces) {
5384 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5385 if (!RBraceLocOrErr)
5386 return RBraceLocOrErr.takeError();
5387 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5388 }
5389
5390 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5391 LexicalDC->addDeclInternal(ToLinkageSpec);
5392
5393 return ToLinkageSpec;
5394}
5395
5397 BaseUsingDecl *ToSI) {
5398 for (UsingShadowDecl *FromShadow : D->shadows()) {
5399 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5400 ToSI->addShadowDecl(*ToShadowOrErr);
5401 else
5402 // FIXME: We return error here but the definition is already created
5403 // and available with lookups. How to fix this?..
5404 return ToShadowOrErr.takeError();
5405 }
5406 return ToSI;
5407}
5408
5410 DeclContext *DC, *LexicalDC;
5411 DeclarationName Name;
5412 SourceLocation Loc;
5413 NamedDecl *ToD = nullptr;
5414 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5415 return std::move(Err);
5416 if (ToD)
5417 return ToD;
5418
5419 Error Err = Error::success();
5420 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5421 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5422 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5423 if (Err)
5424 return std::move(Err);
5425
5426 DeclarationNameInfo NameInfo(Name, ToLoc);
5427 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5428 return std::move(Err);
5429
5430 UsingDecl *ToUsing;
5431 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5432 ToUsingLoc, ToQualifierLoc, NameInfo,
5433 D->hasTypename()))
5434 return ToUsing;
5435
5436 ToUsing->setLexicalDeclContext(LexicalDC);
5437 LexicalDC->addDeclInternal(ToUsing);
5438
5439 if (NamedDecl *FromPattern =
5440 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5441 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5442 Importer.getToContext().setInstantiatedFromUsingDecl(
5443 ToUsing, *ToPatternOrErr);
5444 else
5445 return ToPatternOrErr.takeError();
5446 }
5447
5448 return ImportUsingShadowDecls(D, ToUsing);
5449}
5450
5452 DeclContext *DC, *LexicalDC;
5453 DeclarationName Name;
5454 SourceLocation Loc;
5455 NamedDecl *ToD = nullptr;
5456 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5457 return std::move(Err);
5458 if (ToD)
5459 return ToD;
5460
5461 Error Err = Error::success();
5462 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5463 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5464 auto ToNameLoc = importChecked(Err, D->getLocation());
5465 auto *ToEnumType = importChecked(Err, D->getEnumType());
5466 if (Err)
5467 return std::move(Err);
5468
5469 UsingEnumDecl *ToUsingEnum;
5470 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5471 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5472 return ToUsingEnum;
5473
5474 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5475 LexicalDC->addDeclInternal(ToUsingEnum);
5476
5477 if (UsingEnumDecl *FromPattern =
5478 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5479 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5480 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5481 *ToPatternOrErr);
5482 else
5483 return ToPatternOrErr.takeError();
5484 }
5485
5486 return ImportUsingShadowDecls(D, ToUsingEnum);
5487}
5488
5490 DeclContext *DC, *LexicalDC;
5491 DeclarationName Name;
5492 SourceLocation Loc;
5493 NamedDecl *ToD = nullptr;
5494 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5495 return std::move(Err);
5496 if (ToD)
5497 return ToD;
5498
5499 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5500 if (!ToIntroducerOrErr)
5501 return ToIntroducerOrErr.takeError();
5502
5503 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5504 if (!ToTargetOrErr)
5505 return ToTargetOrErr.takeError();
5506
5507 UsingShadowDecl *ToShadow;
5508 if (auto *FromConstructorUsingShadow =
5509 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5510 Error Err = Error::success();
5512 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5513 if (Err)
5514 return std::move(Err);
5515 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5516 // is really the "NominatedBaseClassShadowDecl" value if it exists
5517 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5518 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5519 // get the correct values.
5520 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5521 ToShadow, D, Importer.getToContext(), DC, Loc,
5522 cast<UsingDecl>(*ToIntroducerOrErr),
5523 Nominated ? Nominated : *ToTargetOrErr,
5524 FromConstructorUsingShadow->constructsVirtualBase()))
5525 return ToShadow;
5526 } else {
5527 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5528 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5529 return ToShadow;
5530 }
5531
5532 ToShadow->setLexicalDeclContext(LexicalDC);
5533 ToShadow->setAccess(D->getAccess());
5534
5535 if (UsingShadowDecl *FromPattern =
5536 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5537 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5538 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5539 ToShadow, *ToPatternOrErr);
5540 else
5541 // FIXME: We return error here but the definition is already created
5542 // and available with lookups. How to fix this?..
5543 return ToPatternOrErr.takeError();
5544 }
5545
5546 LexicalDC->addDeclInternal(ToShadow);
5547
5548 return ToShadow;
5549}
5550
5552 DeclContext *DC, *LexicalDC;
5553 DeclarationName Name;
5554 SourceLocation Loc;
5555 NamedDecl *ToD = nullptr;
5556 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5557 return std::move(Err);
5558 if (ToD)
5559 return ToD;
5560
5561 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5562 if (!ToComAncestorOrErr)
5563 return ToComAncestorOrErr.takeError();
5564
5565 Error Err = Error::success();
5566 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5567 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5568 auto ToNamespaceKeyLocation =
5570 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5571 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5572 if (Err)
5573 return std::move(Err);
5574
5575 UsingDirectiveDecl *ToUsingDir;
5576 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5577 ToUsingLoc,
5578 ToNamespaceKeyLocation,
5579 ToQualifierLoc,
5580 ToIdentLocation,
5581 ToNominatedNamespace, *ToComAncestorOrErr))
5582 return ToUsingDir;
5583
5584 ToUsingDir->setLexicalDeclContext(LexicalDC);
5585 LexicalDC->addDeclInternal(ToUsingDir);
5586
5587 return ToUsingDir;
5588}
5589
5591 DeclContext *DC, *LexicalDC;
5592 DeclarationName Name;
5593 SourceLocation Loc;
5594 NamedDecl *ToD = nullptr;
5595 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5596 return std::move(Err);
5597 if (ToD)
5598 return ToD;
5599
5600 auto ToInstantiatedFromUsingOrErr =
5601 Importer.Import(D->getInstantiatedFromUsingDecl());
5602 if (!ToInstantiatedFromUsingOrErr)
5603 return ToInstantiatedFromUsingOrErr.takeError();
5604 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5605 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5606 return std::move(Err);
5607
5608 UsingPackDecl *ToUsingPack;
5609 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5610 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5611 Expansions))
5612 return ToUsingPack;
5613
5614 addDeclToContexts(D, ToUsingPack);
5615
5616 return ToUsingPack;
5617}
5618
5621 DeclContext *DC, *LexicalDC;
5622 DeclarationName Name;
5623 SourceLocation Loc;
5624 NamedDecl *ToD = nullptr;
5625 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5626 return std::move(Err);
5627 if (ToD)
5628 return ToD;
5629
5630 Error Err = Error::success();
5631 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5632 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5633 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5634 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5635 if (Err)
5636 return std::move(Err);
5637
5638 DeclarationNameInfo NameInfo(Name, ToLoc);
5639 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5640 return std::move(Err);
5641
5642 UnresolvedUsingValueDecl *ToUsingValue;
5643 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5644 ToUsingLoc, ToQualifierLoc, NameInfo,
5645 ToEllipsisLoc))
5646 return ToUsingValue;
5647
5648 ToUsingValue->setAccess(D->getAccess());
5649 ToUsingValue->setLexicalDeclContext(LexicalDC);
5650 LexicalDC->addDeclInternal(ToUsingValue);
5651
5652 return ToUsingValue;
5653}
5654
5657 DeclContext *DC, *LexicalDC;
5658 DeclarationName Name;
5659 SourceLocation Loc;
5660 NamedDecl *ToD = nullptr;
5661 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5662 return std::move(Err);
5663 if (ToD)
5664 return ToD;
5665
5666 Error Err = Error::success();
5667 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5668 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5669 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5670 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5671 if (Err)
5672 return std::move(Err);
5673
5675 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5676 ToUsingLoc, ToTypenameLoc,
5677 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5678 return ToUsing;
5679
5680 ToUsing->setAccess(D->getAccess());
5681 ToUsing->setLexicalDeclContext(LexicalDC);
5682 LexicalDC->addDeclInternal(ToUsing);
5683
5684 return ToUsing;
5685}
5686
5688 Decl* ToD = nullptr;
5689 switch (D->getBuiltinTemplateKind()) {
5690#define BuiltinTemplate(BTName) \
5691 case BuiltinTemplateKind::BTK##BTName: \
5692 ToD = Importer.getToContext().get##BTName##Decl(); \
5693 break;
5694#include "clang/Basic/BuiltinTemplates.inc"
5695 }
5696 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5697 Importer.MapImported(D, ToD);
5698 return ToD;
5699}
5700
5703 if (To->getDefinition()) {
5704 // Check consistency of superclass.
5705 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5706 if (FromSuper) {
5707 if (auto FromSuperOrErr = import(FromSuper))
5708 FromSuper = *FromSuperOrErr;
5709 else
5710 return FromSuperOrErr.takeError();
5711 }
5712
5713 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5714 if ((bool)FromSuper != (bool)ToSuper ||
5715 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5716 Importer.ToDiag(To->getLocation(),
5717 diag::warn_odr_objc_superclass_inconsistent)
5718 << To->getDeclName();
5719 if (ToSuper)
5720 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5721 << To->getSuperClass()->getDeclName();
5722 else
5723 Importer.ToDiag(To->getLocation(),
5724 diag::note_odr_objc_missing_superclass);
5725 if (From->getSuperClass())
5726 Importer.FromDiag(From->getSuperClassLoc(),
5727 diag::note_odr_objc_superclass)
5728 << From->getSuperClass()->getDeclName();
5729 else
5730 Importer.FromDiag(From->getLocation(),
5731 diag::note_odr_objc_missing_superclass);
5732 }
5733
5735 if (Error Err = ImportDeclContext(From))
5736 return Err;
5737 return Error::success();
5738 }
5739
5740 // Start the definition.
5741 To->startDefinition();
5742
5743 // If this class has a superclass, import it.
5744 if (From->getSuperClass()) {
5745 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5746 To->setSuperClass(*SuperTInfoOrErr);
5747 else
5748 return SuperTInfoOrErr.takeError();
5749 }
5750
5751 // Import protocols
5753 SmallVector<SourceLocation, 4> ProtocolLocs;
5755 From->protocol_loc_begin();
5756
5758 FromProtoEnd = From->protocol_end();
5759 FromProto != FromProtoEnd;
5760 ++FromProto, ++FromProtoLoc) {
5761 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5762 Protocols.push_back(*ToProtoOrErr);
5763 else
5764 return ToProtoOrErr.takeError();
5765
5766 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5767 ProtocolLocs.push_back(*ToProtoLocOrErr);
5768 else
5769 return ToProtoLocOrErr.takeError();
5770
5771 }
5772
5773 // FIXME: If we're merging, make sure that the protocol list is the same.
5774 To->setProtocolList(Protocols.data(), Protocols.size(),
5775 ProtocolLocs.data(), Importer.getToContext());
5776
5777 // Import categories. When the categories themselves are imported, they'll
5778 // hook themselves into this interface.
5779 for (auto *Cat : From->known_categories()) {
5780 auto ToCatOrErr = import(Cat);
5781 if (!ToCatOrErr)
5782 return ToCatOrErr.takeError();
5783 }
5784
5785 // If we have an @implementation, import it as well.
5786 if (From->getImplementation()) {
5787 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5788 import(From->getImplementation()))
5789 To->setImplementation(*ToImplOrErr);
5790 else
5791 return ToImplOrErr.takeError();
5792 }
5793
5794 // Import all of the members of this class.
5795 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5796 return Err;
5797
5798 return Error::success();
5799}
5800
5803 if (!list)
5804 return nullptr;
5805
5807 for (auto *fromTypeParam : *list) {
5808 if (auto toTypeParamOrErr = import(fromTypeParam))
5809 toTypeParams.push_back(*toTypeParamOrErr);
5810 else
5811 return toTypeParamOrErr.takeError();
5812 }
5813
5814 auto LAngleLocOrErr = import(list->getLAngleLoc());
5815 if (!LAngleLocOrErr)
5816 return LAngleLocOrErr.takeError();
5817
5818 auto RAngleLocOrErr = import(list->getRAngleLoc());
5819 if (!RAngleLocOrErr)
5820 return RAngleLocOrErr.takeError();
5821
5822 return ObjCTypeParamList::create(Importer.getToContext(),
5823 *LAngleLocOrErr,
5824 toTypeParams,
5825 *RAngleLocOrErr);
5826}
5827
5829 // If this class has a definition in the translation unit we're coming from,
5830 // but this particular declaration is not that definition, import the
5831 // definition and map to that.
5833 if (Definition && Definition != D) {
5834 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5835 return Importer.MapImported(D, *ImportedDefOrErr);
5836 else
5837 return ImportedDefOrErr.takeError();
5838 }
5839
5840 // Import the major distinguishing characteristics of an @interface.
5841 DeclContext *DC, *LexicalDC;
5842 DeclarationName Name;
5843 SourceLocation Loc;
5844 NamedDecl *ToD;
5845 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5846 return std::move(Err);
5847 if (ToD)
5848 return ToD;
5849
5850 // Look for an existing interface with the same name.
5851 ObjCInterfaceDecl *MergeWithIface = nullptr;
5852 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5853 for (auto *FoundDecl : FoundDecls) {
5854 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5855 continue;
5856
5857 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5858 break;
5859 }
5860
5861 // Create an interface declaration, if one does not already exist.
5862 ObjCInterfaceDecl *ToIface = MergeWithIface;
5863 if (!ToIface) {
5864 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5865 if (!AtBeginLocOrErr)
5866 return AtBeginLocOrErr.takeError();
5867
5868 if (GetImportedOrCreateDecl(
5869 ToIface, D, Importer.getToContext(), DC,
5870 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5871 /*TypeParamList=*/nullptr,
5872 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5873 return ToIface;
5874 ToIface->setLexicalDeclContext(LexicalDC);
5875 LexicalDC->addDeclInternal(ToIface);
5876 }
5877 Importer.MapImported(D, ToIface);
5878 // Import the type parameter list after MapImported, to avoid
5879 // loops when bringing in their DeclContext.
5880 if (auto ToPListOrErr =
5882 ToIface->setTypeParamList(*ToPListOrErr);
5883 else
5884 return ToPListOrErr.takeError();
5885
5887 if (Error Err = ImportDefinition(D, ToIface))
5888 return std::move(Err);
5889
5890 return ToIface;
5891}
5892
5895 ObjCCategoryDecl *Category;
5896 if (Error Err = importInto(Category, D->getCategoryDecl()))
5897 return std::move(Err);
5898
5899 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5900 if (!ToImpl) {
5901 DeclContext *DC, *LexicalDC;
5902 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5903 return std::move(Err);
5904
5905 Error Err = Error::success();
5906 auto ToLocation = importChecked(Err, D->getLocation());
5907 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5908 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5909 if (Err)
5910 return std::move(Err);
5911
5912 if (GetImportedOrCreateDecl(
5913 ToImpl, D, Importer.getToContext(), DC,
5914 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5915 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5916 return ToImpl;
5917
5918 ToImpl->setLexicalDeclContext(LexicalDC);
5919 LexicalDC->addDeclInternal(ToImpl);
5920 Category->setImplementation(ToImpl);
5921 }
5922
5923 Importer.MapImported(D, ToImpl);
5924 if (Error Err = ImportDeclContext(D))
5925 return std::move(Err);
5926
5927 return ToImpl;
5928}
5929
5932 // Find the corresponding interface.
5933 ObjCInterfaceDecl *Iface;
5934 if (Error Err = importInto(Iface, D->getClassInterface()))
5935 return std::move(Err);
5936
5937 // Import the superclass, if any.
5938 ObjCInterfaceDecl *Super;
5939 if (Error Err = importInto(Super, D->getSuperClass()))
5940 return std::move(Err);
5941
5943 if (!Impl) {
5944 // We haven't imported an implementation yet. Create a new @implementation
5945 // now.
5946 DeclContext *DC, *LexicalDC;
5947 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5948 return std::move(Err);
5949
5950 Error Err = Error::success();
5951 auto ToLocation = importChecked(Err, D->getLocation());
5952 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5953 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5954 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5955 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5956 if (Err)
5957 return std::move(Err);
5958
5959 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5960 DC, Iface, Super,
5961 ToLocation,
5962 ToAtStartLoc,
5963 ToSuperClassLoc,
5964 ToIvarLBraceLoc,
5965 ToIvarRBraceLoc))
5966 return Impl;
5967
5968 Impl->setLexicalDeclContext(LexicalDC);
5969
5970 // Associate the implementation with the class it implements.
5971 Iface->setImplementation(Impl);
5972 Importer.MapImported(D, Iface->getImplementation());
5973 } else {
5974 Importer.MapImported(D, Iface->getImplementation());
5975
5976 // Verify that the existing @implementation has the same superclass.
5977 if ((Super && !Impl->getSuperClass()) ||
5978 (!Super && Impl->getSuperClass()) ||
5979 (Super && Impl->getSuperClass() &&
5981 Impl->getSuperClass()))) {
5982 Importer.ToDiag(Impl->getLocation(),
5983 diag::warn_odr_objc_superclass_inconsistent)
5984 << Iface->getDeclName();
5985 // FIXME: It would be nice to have the location of the superclass
5986 // below.
5987 if (Impl->getSuperClass())
5988 Importer.ToDiag(Impl->getLocation(),
5989 diag::note_odr_objc_superclass)
5990 << Impl->getSuperClass()->getDeclName();
5991 else
5992 Importer.ToDiag(Impl->getLocation(),
5993 diag::note_odr_objc_missing_superclass);
5994 if (D->getSuperClass())
5995 Importer.FromDiag(D->getLocation(),
5996 diag::note_odr_objc_superclass)
5997 << D->getSuperClass()->getDeclName();
5998 else
5999 Importer.FromDiag(D->getLocation(),
6000 diag::note_odr_objc_missing_superclass);
6001
6002 return make_error<ASTImportError>(ASTImportError::NameConflict);
6003 }
6004 }
6005
6006 // Import all of the members of this @implementation.
6007 if (Error Err = ImportDeclContext(D))
6008 return std::move(Err);
6009
6010 return Impl;
6011}
6012
6014 // Import the major distinguishing characteristics of an @property.
6015 DeclContext *DC, *LexicalDC;
6016 DeclarationName Name;
6017 SourceLocation Loc;
6018 NamedDecl *ToD;
6019 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6020 return std::move(Err);
6021 if (ToD)
6022 return ToD;
6023
6024 // Check whether we have already imported this property.
6025 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6026 for (auto *FoundDecl : FoundDecls) {
6027 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
6028 // Instance and class properties can share the same name but are different
6029 // declarations.
6030 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
6031 continue;
6032
6033 // Check property types.
6034 if (!Importer.IsStructurallyEquivalent(D->getType(),
6035 FoundProp->getType())) {
6036 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
6037 << Name << D->getType() << FoundProp->getType();
6038 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
6039 << FoundProp->getType();
6040
6041 return make_error<ASTImportError>(ASTImportError::NameConflict);
6042 }
6043
6044 // FIXME: Check property attributes, getters, setters, etc.?
6045
6046 // Consider these properties to be equivalent.
6047 Importer.MapImported(D, FoundProp);
6048 return FoundProp;
6049 }
6050 }
6051
6052 Error Err = Error::success();
6053 auto ToType = importChecked(Err, D->getType());
6054 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6055 auto ToAtLoc = importChecked(Err, D->getAtLoc());
6056 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
6057 if (Err)
6058 return std::move(Err);
6059
6060 // Create the new property.
6061 ObjCPropertyDecl *ToProperty;
6062 if (GetImportedOrCreateDecl(
6063 ToProperty, D, Importer.getToContext(), DC, Loc,
6064 Name.getAsIdentifierInfo(), ToAtLoc,
6065 ToLParenLoc, ToType,
6066 ToTypeSourceInfo, D->getPropertyImplementation()))
6067 return ToProperty;
6068
6069 auto ToGetterName = importChecked(Err, D->getGetterName());
6070 auto ToSetterName = importChecked(Err, D->getSetterName());
6071 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6072 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6073 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6074 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6075 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6076 if (Err)
6077 return std::move(Err);
6078
6079 ToProperty->setLexicalDeclContext(LexicalDC);
6080 LexicalDC->addDeclInternal(ToProperty);
6081
6085 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6086 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6087 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6088 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6089 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6090 return ToProperty;
6091}
6092
6096 if (Error Err = importInto(Property, D->getPropertyDecl()))
6097 return std::move(Err);
6098
6099 DeclContext *DC, *LexicalDC;
6100 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6101 return std::move(Err);
6102
6103 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6104
6105 // Import the ivar (for an @synthesize).
6106 ObjCIvarDecl *Ivar = nullptr;
6107 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6108 return std::move(Err);
6109
6110 ObjCPropertyImplDecl *ToImpl
6111 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6112 Property->getQueryKind());
6113 if (!ToImpl) {
6114
6115 Error Err = Error::success();
6116 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6117 auto ToLocation = importChecked(Err, D->getLocation());
6118 auto ToPropertyIvarDeclLoc =
6120 if (Err)
6121 return std::move(Err);
6122
6123 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6124 ToBeginLoc,
6125 ToLocation, Property,
6126 D->getPropertyImplementation(), Ivar,
6127 ToPropertyIvarDeclLoc))
6128 return ToImpl;
6129
6130 ToImpl->setLexicalDeclContext(LexicalDC);
6131 LexicalDC->addDeclInternal(ToImpl);
6132 } else {
6133 // Check that we have the same kind of property implementation (@synthesize
6134 // vs. @dynamic).
6136 Importer.ToDiag(ToImpl->getLocation(),
6137 diag::warn_odr_objc_property_impl_kind_inconsistent)
6138 << Property->getDeclName()
6139 << (ToImpl->getPropertyImplementation()
6141 Importer.FromDiag(D->getLocation(),
6142 diag::note_odr_objc_property_impl_kind)
6143 << D->getPropertyDecl()->getDeclName()
6145
6146 return make_error<ASTImportError>(ASTImportError::NameConflict);
6147 }
6148
6149 // For @synthesize, check that we have the same
6151 Ivar != ToImpl->getPropertyIvarDecl()) {
6152 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6153 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6154 << Property->getDeclName()
6155 << ToImpl->getPropertyIvarDecl()->getDeclName()
6156 << Ivar->getDeclName();
6157 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6158 diag::note_odr_objc_synthesize_ivar_here)
6160
6161 return make_error<ASTImportError>(ASTImportError::NameConflict);
6162 }
6163
6164 // Merge the existing implementation with the new implementation.
6165 Importer.MapImported(D, ToImpl);
6166 }
6167
6168 return ToImpl;
6169}
6170
6173 Error Err = Error::success();
6174 auto ToType = importChecked(Err, D->getType());
6175 auto ToValue = importChecked(Err, D->getValue());
6176 if (Err)
6177 return std::move(Err);
6178
6180 auto Create = [this](QualType T, const APValue &V) {
6181 return Importer.ToContext.getTemplateParamObjectDecl(T, V);
6182 };
6183 (void)GetImportedOrCreateSpecialDecl(ToD, Create, D, ToType, ToValue);
6184 return ToD;
6185}
6186
6189 // For template arguments, we adopt the translation unit as our declaration
6190 // context. This context will be fixed when (during) the actual template
6191 // declaration is created.
6192
6193 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6194 if (!BeginLocOrErr)
6195 return BeginLocOrErr.takeError();
6196
6197 ExpectedSLoc LocationOrErr = import(D->getLocation());
6198 if (!LocationOrErr)
6199 return LocationOrErr.takeError();
6200
6201 TemplateTypeParmDecl *ToD = nullptr;
6202 if (GetImportedOrCreateDecl(
6203 ToD, D, Importer.getToContext(),
6204 Importer.getToContext().getTranslationUnitDecl(),
6205 *BeginLocOrErr, *LocationOrErr,
6206 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6208 D->hasTypeConstraint()))
6209 return ToD;
6210
6211 // Import the type-constraint
6212 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6213
6214 Error Err = Error::success();
6215 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6216 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6217 if (Err)
6218 return std::move(Err);
6219
6220 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6221 }
6222
6223 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6224 return Err;
6225
6226 return ToD;
6227}
6228
6231
6232 Error Err = Error::success();
6233 auto ToDeclName = importChecked(Err, D->getDeclName());
6234 auto ToLocation = importChecked(Err, D->getLocation());
6235 auto ToType = importChecked(Err, D->getType());
6236 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6237 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6238 if (Err)
6239 return std::move(Err);
6240
6241 NonTypeTemplateParmDecl *ToD = nullptr;
6242 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6243 Importer.getToContext().getTranslationUnitDecl(),
6244 ToInnerLocStart, ToLocation, D->getDepth(),
6245 D->getPosition(),
6246 ToDeclName.getAsIdentifierInfo(), ToType,
6247 D->isParameterPack(), ToTypeSourceInfo))
6248 return ToD;
6249
6250 Err = importTemplateParameterDefaultArgument(D, ToD);
6251 if (Err)
6252 return Err;
6253
6254 return ToD;
6255}
6256
6259 bool IsCanonical = false;
6260 if (auto *CanonD = Importer.getFromContext()
6261 .findCanonicalTemplateTemplateParmDeclInternal(D);
6262 CanonD == D)
6263 IsCanonical = true;
6264
6265 // Import the name of this declaration.
6266 auto NameOrErr = import(D->getDeclName());
6267 if (!NameOrErr)
6268 return NameOrErr.takeError();
6269
6270 // Import the location of this declaration.
6271 ExpectedSLoc LocationOrErr = import(D->getLocation());
6272 if (!LocationOrErr)
6273 return LocationOrErr.takeError();
6274
6275 // Import template parameters.
6276 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6277 if (!TemplateParamsOrErr)
6278 return TemplateParamsOrErr.takeError();
6279
6280 TemplateTemplateParmDecl *ToD = nullptr;
6281 if (GetImportedOrCreateDecl(
6282 ToD, D, Importer.getToContext(),
6283 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6284 D->getDepth(), D->getPosition(), D->isParameterPack(),
6285 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6286 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6287 return ToD;
6288
6289 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6290 return Err;
6291
6292 if (IsCanonical)
6293 return Importer.getToContext()
6294 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6295
6296 return ToD;
6297}
6298
6299// Returns the definition for a (forward) declaration of a TemplateDecl, if
6300// it has any definition in the redecl chain.
6301template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6302 assert(D->getTemplatedDecl() && "Should be called on templates only");
6303 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6304 if (!ToTemplatedDef)
6305 return nullptr;
6306 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6307 return cast_or_null<T>(TemplateWithDef);
6308}
6309
6311
6312 // Import the major distinguishing characteristics of this class template.
6313 DeclContext *DC, *LexicalDC;
6314 DeclarationName Name;
6315 SourceLocation Loc;
6316 NamedDecl *ToD;
6317 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6318 return std::move(Err);
6319 if (ToD)
6320 return ToD;
6321
6322 // Should check if a declaration is friend in a dependent context.
6323 // Such templates are not linked together in a declaration chain.
6324 // The ASTImporter strategy is to map existing forward declarations to
6325 // imported ones only if strictly necessary, otherwise import these as new
6326 // forward declarations. In case of the "dependent friend" declarations, new
6327 // declarations are created, but not linked in a declaration chain.
6328 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6329 return TD->getFriendObjectKind() != Decl::FOK_None &&
6330 TD->getLexicalDeclContext()->isDependentContext();
6331 };
6332 bool DependentFriend = IsDependentFriend(D);
6333
6334 ClassTemplateDecl *FoundByLookup = nullptr;
6335
6336 // We may already have a template of the same name; try to find and match it.
6337 if (!DC->isFunctionOrMethod()) {
6338 SmallVector<NamedDecl *, 4> ConflictingDecls;
6339 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6340 for (auto *FoundDecl : FoundDecls) {
6341 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6343 continue;
6344
6345 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6346 if (FoundTemplate) {
6347 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6348 continue;
6349
6350 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6351 bool IgnoreTemplateParmDepth =
6352 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6354 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6355 IgnoreTemplateParmDepth)) {
6356 if (DependentFriend || IsDependentFriend(FoundTemplate))
6357 continue;
6358
6359 ClassTemplateDecl *TemplateWithDef =
6360 getTemplateDefinition(FoundTemplate);
6361 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6362 return Importer.MapImported(D, TemplateWithDef);
6363 if (!FoundByLookup)
6364 FoundByLookup = FoundTemplate;
6365 // Search in all matches because there may be multiple decl chains,
6366 // see ASTTests test ImportExistingFriendClassTemplateDef.
6367 continue;
6368 }
6369 // When importing a friend, it is possible that multiple declarations
6370 // with same name can co-exist in specific cases (if a template contains
6371 // a friend template and has a specialization). For this case the
6372 // declarations should match, except that the "template depth" is
6373 // different. No linking of previous declaration is needed in this case.
6374 // FIXME: This condition may need refinement.
6375 if (D->getFriendObjectKind() != Decl::FOK_None &&
6376 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6377 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6378 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6379 /*IgnoreTemplateParmDepth=*/true))
6380 continue;
6381
6382 ConflictingDecls.push_back(FoundDecl);
6383 }
6384 }
6385
6386 if (!ConflictingDecls.empty()) {
6387 ExpectedName NameOrErr = Importer.HandleNameConflict(
6388 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6389 ConflictingDecls.size());
6390 if (NameOrErr)
6391 Name = NameOrErr.get();
6392 else
6393 return NameOrErr.takeError();
6394 }
6395 }
6396
6397 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6398
6399 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6400 if (!TemplateParamsOrErr)
6401 return TemplateParamsOrErr.takeError();
6402
6403 // Create the declaration that is being templated.
6404 CXXRecordDecl *ToTemplated;
6405 if (Error Err = importInto(ToTemplated, FromTemplated))
6406 return std::move(Err);
6407
6408 // Create the class template declaration itself.
6410 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6411 *TemplateParamsOrErr, ToTemplated))
6412 return D2;
6413
6414 ToTemplated->setDescribedClassTemplate(D2);
6415
6416 D2->setAccess(D->getAccess());
6417 D2->setLexicalDeclContext(LexicalDC);
6418
6419 addDeclToContexts(D, D2);
6420 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6421
6422 if (FoundByLookup) {
6423 auto *Recent =
6424 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6425
6426 // It is possible that during the import of the class template definition
6427 // we start the import of a fwd friend decl of the very same class template
6428 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6429 // had been created earlier and by that time the lookup could not find
6430 // anything existing, so it has no previous decl. Later, (still during the
6431 // import of the fwd friend decl) we start to import the definition again
6432 // and this time the lookup finds the previous fwd friend class template.
6433 // In this case we must set up the previous decl for the templated decl.
6434 if (!ToTemplated->getPreviousDecl()) {
6435 assert(FoundByLookup->getTemplatedDecl() &&
6436 "Found decl must have its templated decl set");
6437 CXXRecordDecl *PrevTemplated =
6438 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6439 if (ToTemplated != PrevTemplated)
6440 ToTemplated->setPreviousDecl(PrevTemplated);
6441 }
6442
6443 D2->setPreviousDecl(Recent);
6444 }
6445
6446 return D2;
6447}
6448
6451 ClassTemplateDecl *ClassTemplate;
6452 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6453 return std::move(Err);
6454
6455 // Import the context of this declaration.
6456 DeclContext *DC, *LexicalDC;
6457 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6458 return std::move(Err);
6459
6460 // Import template arguments.
6462 if (Error Err =
6463 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6464 return std::move(Err);
6465 // Try to find an existing specialization with these template arguments and
6466 // template parameter list.
6467 void *InsertPos = nullptr;
6468 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6470 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6471
6472 // Import template parameters.
6473 TemplateParameterList *ToTPList = nullptr;
6474
6475 if (PartialSpec) {
6476 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6477 if (!ToTPListOrErr)
6478 return ToTPListOrErr.takeError();
6479 ToTPList = *ToTPListOrErr;
6480 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6481 *ToTPListOrErr,
6482 InsertPos);
6483 } else
6484 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6485
6486 if (PrevDecl) {
6487 if (IsStructuralMatch(D, PrevDecl)) {
6488 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6489 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6490 Importer.MapImported(D, PrevDefinition);
6491 // Import those default field initializers which have been
6492 // instantiated in the "From" context, but not in the "To" context.
6493 for (auto *FromField : D->fields()) {
6494 auto ToOrErr = import(FromField);
6495 if (!ToOrErr)
6496 return ToOrErr.takeError();
6497 }
6498
6499 // Import those methods which have been instantiated in the
6500 // "From" context, but not in the "To" context.
6501 for (CXXMethodDecl *FromM : D->methods()) {
6502 auto ToOrErr = import(FromM);
6503 if (!ToOrErr)
6504 return ToOrErr.takeError();
6505 }
6506
6507 // TODO Import instantiated default arguments.
6508 // TODO Import instantiated exception specifications.
6509 //
6510 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6511 // what else could be fused during an AST merge.
6512 return PrevDefinition;
6513 }
6514 } else { // ODR violation.
6515 // FIXME HandleNameConflict
6516 return make_error<ASTImportError>(ASTImportError::NameConflict);
6517 }
6518 }
6519
6520 // Import the location of this declaration.
6521 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6522 if (!BeginLocOrErr)
6523 return BeginLocOrErr.takeError();
6524 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6525 if (!IdLocOrErr)
6526 return IdLocOrErr.takeError();
6527
6528 // Import TemplateArgumentListInfo.
6529 TemplateArgumentListInfo ToTAInfo;
6530 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6531 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6532 return std::move(Err);
6533 }
6534
6535 // Create the specialization.
6536 ClassTemplateSpecializationDecl *D2 = nullptr;
6537 if (PartialSpec) {
6538 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6539 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6540 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6541 /*CanonInjectedTST=*/CanQualType(),
6542 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6543 return D2;
6544
6545 // Update InsertPos, because preceding import calls may have invalidated
6546 // it by adding new specializations.
6548 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6549 InsertPos))
6550 // Add this partial specialization to the class template.
6551 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6553 import(PartialSpec->getInstantiatedFromMember()))
6554 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6555 else
6556 return ToInstOrErr.takeError();
6557
6558 updateLookupTableForTemplateParameters(*ToTPList);
6559 } else { // Not a partial specialization.
6560 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6561 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6562 TemplateArgs, D->hasStrictPackMatch(),
6563 PrevDecl))
6564 return D2;
6565
6566 // Update InsertPos, because preceding import calls may have invalidated
6567 // it by adding new specializations.
6568 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6569 // Add this specialization to the class template.
6570 ClassTemplate->AddSpecialization(D2, InsertPos);
6571 }
6572
6574
6575 // Set the context of this specialization/instantiation.
6576 D2->setLexicalDeclContext(LexicalDC);
6577
6578 // Add to the DC only if it was an explicit specialization/instantiation.
6580 LexicalDC->addDeclInternal(D2);
6581 }
6582
6583 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6584 D2->setBraceRange(*BraceRangeOrErr);
6585 else
6586 return BraceRangeOrErr.takeError();
6587
6588 if (Error Err = ImportTemplateParameterLists(D, D2))
6589 return std::move(Err);
6590
6591 // Import the qualifier, if any.
6592 if (auto LocOrErr = import(D->getQualifierLoc()))
6593 D2->setQualifierInfo(*LocOrErr);
6594 else
6595 return LocOrErr.takeError();
6596
6597 if (D->getTemplateArgsAsWritten())
6598 D2->setTemplateArgsAsWritten(ToTAInfo);
6599
6600 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6601 D2->setTemplateKeywordLoc(*LocOrErr);
6602 else
6603 return LocOrErr.takeError();
6604
6605 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6606 D2->setExternKeywordLoc(*LocOrErr);
6607 else
6608 return LocOrErr.takeError();
6609
6610 if (D->getPointOfInstantiation().isValid()) {
6611 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6612 D2->setPointOfInstantiation(*POIOrErr);
6613 else
6614 return POIOrErr.takeError();
6615 }
6616
6618
6619 if (auto P = D->getInstantiatedFrom()) {
6620 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6621 if (auto CTDorErr = import(CTD))
6622 D2->setInstantiationOf(*CTDorErr);
6623 } else {
6625 auto CTPSDOrErr = import(CTPSD);
6626 if (!CTPSDOrErr)
6627 return CTPSDOrErr.takeError();
6629 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6630 for (unsigned I = 0; I < DArgs.size(); ++I) {
6631 const TemplateArgument &DArg = DArgs[I];
6632 if (auto ArgOrErr = import(DArg))
6633 D2ArgsVec[I] = *ArgOrErr;
6634 else
6635 return ArgOrErr.takeError();
6636 }
6638 *CTPSDOrErr,
6639 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6640 }
6641 }
6642
6643 if (D->isCompleteDefinition())
6644 if (Error Err = ImportDefinition(D, D2))
6645 return std::move(Err);
6646
6647 return D2;
6648}
6649
6651 // Import the major distinguishing characteristics of this variable template.
6652 DeclContext *DC, *LexicalDC;
6653 DeclarationName Name;
6654 SourceLocation Loc;
6655 NamedDecl *ToD;
6656 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6657 return std::move(Err);
6658 if (ToD)
6659 return ToD;
6660
6661 // We may already have a template of the same name; try to find and match it.
6662 assert(!DC->isFunctionOrMethod() &&
6663 "Variable templates cannot be declared at function scope");
6664
6665 SmallVector<NamedDecl *, 4> ConflictingDecls;
6666 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6667 VarTemplateDecl *FoundByLookup = nullptr;
6668 for (auto *FoundDecl : FoundDecls) {
6669 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6670 continue;
6671
6672 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6673 // Use the templated decl, some linkage flags are set only there.
6674 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6675 D->getTemplatedDecl()))
6676 continue;
6677 if (IsStructuralMatch(D, FoundTemplate)) {
6678 // FIXME Check for ODR error if the two definitions have
6679 // different initializers?
6680 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6681 if (D->getDeclContext()->isRecord()) {
6682 assert(FoundTemplate->getDeclContext()->isRecord() &&
6683 "Member variable template imported as non-member, "
6684 "inconsistent imported AST?");
6685 if (FoundDef)
6686 return Importer.MapImported(D, FoundDef);
6688 return Importer.MapImported(D, FoundTemplate);
6689 } else {
6690 if (FoundDef && D->isThisDeclarationADefinition())
6691 return Importer.MapImported(D, FoundDef);
6692 }
6693 FoundByLookup = FoundTemplate;
6694 break;
6695 }
6696 ConflictingDecls.push_back(FoundDecl);
6697 }
6698 }
6699
6700 if (!ConflictingDecls.empty()) {
6701 ExpectedName NameOrErr = Importer.HandleNameConflict(
6702 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6703 ConflictingDecls.size());
6704 if (NameOrErr)
6705 Name = NameOrErr.get();
6706 else
6707 return NameOrErr.takeError();
6708 }
6709
6710 VarDecl *DTemplated = D->getTemplatedDecl();
6711
6712 // Import the type.
6713 // FIXME: Value not used?
6714 ExpectedType TypeOrErr = import(DTemplated->getType());
6715 if (!TypeOrErr)
6716 return TypeOrErr.takeError();
6717
6718 // Create the declaration that is being templated.
6719 VarDecl *ToTemplated;
6720 if (Error Err = importInto(ToTemplated, DTemplated))
6721 return std::move(Err);
6722
6723 // Create the variable template declaration itself.
6724 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6725 if (!TemplateParamsOrErr)
6726 return TemplateParamsOrErr.takeError();
6727
6728 VarTemplateDecl *ToVarTD;
6729 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6730 Name, *TemplateParamsOrErr, ToTemplated))
6731 return ToVarTD;
6732
6733 ToTemplated->setDescribedVarTemplate(ToVarTD);
6734
6735 ToVarTD->setAccess(D->getAccess());
6736 ToVarTD->setLexicalDeclContext(LexicalDC);
6737 LexicalDC->addDeclInternal(ToVarTD);
6738 if (DC != Importer.getToContext().getTranslationUnitDecl())
6739 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6740
6741 if (FoundByLookup) {
6742 auto *Recent =
6743 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6744 if (!ToTemplated->getPreviousDecl()) {
6745 auto *PrevTemplated =
6746 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6747 if (ToTemplated != PrevTemplated)
6748 ToTemplated->setPreviousDecl(PrevTemplated);
6749 }
6750 ToVarTD->setPreviousDecl(Recent);
6751 }
6752
6753 return ToVarTD;
6754}
6755
6758 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6759 // in an analog way (but specialized for this case).
6760
6762 auto RedeclIt = Redecls.begin();
6763 // Import the first part of the decl chain. I.e. import all previous
6764 // declarations starting from the canonical decl.
6765 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6766 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6767 if (!RedeclOrErr)
6768 return RedeclOrErr.takeError();
6769 }
6770 assert(*RedeclIt == D);
6771
6772 VarTemplateDecl *VarTemplate = nullptr;
6774 return std::move(Err);
6775
6776 // Import the context of this declaration.
6777 DeclContext *DC, *LexicalDC;
6778 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6779 return std::move(Err);
6780
6781 // Import the location of this declaration.
6782 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6783 if (!BeginLocOrErr)
6784 return BeginLocOrErr.takeError();
6785
6786 auto IdLocOrErr = import(D->getLocation());
6787 if (!IdLocOrErr)
6788 return IdLocOrErr.takeError();
6789
6790 // Import template arguments.
6792 if (Error Err =
6793 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6794 return std::move(Err);
6795
6796 // Try to find an existing specialization with these template arguments.
6797 void *InsertPos = nullptr;
6798 VarTemplateSpecializationDecl *FoundSpecialization =
6799 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6800 if (FoundSpecialization) {
6801 if (IsStructuralMatch(D, FoundSpecialization)) {
6802 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6803 if (D->getDeclContext()->isRecord()) {
6804 // In a record, it is allowed only to have one optional declaration and
6805 // one definition of the (static or constexpr) variable template.
6806 assert(
6807 FoundSpecialization->getDeclContext()->isRecord() &&
6808 "Member variable template specialization imported as non-member, "
6809 "inconsistent imported AST?");
6810 if (FoundDef)
6811 return Importer.MapImported(D, FoundDef);
6813 return Importer.MapImported(D, FoundSpecialization);
6814 } else {
6815 // If definition is imported and there is already one, map to it.
6816 // Otherwise create a new variable and link it to the existing.
6817 if (FoundDef && D->isThisDeclarationADefinition())
6818 return Importer.MapImported(D, FoundDef);
6819 }
6820 } else {
6821 return make_error<ASTImportError>(ASTImportError::NameConflict);
6822 }
6823 }
6824
6825 VarTemplateSpecializationDecl *D2 = nullptr;
6826
6827 TemplateArgumentListInfo ToTAInfo;
6828 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6829 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6830 return std::move(Err);
6831 }
6832
6833 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6834 // Create a new specialization.
6835 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6836 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6837 if (!ToTPListOrErr)
6838 return ToTPListOrErr.takeError();
6839
6840 PartVarSpecDecl *ToPartial;
6841 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6842 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6843 VarTemplate, QualType(), nullptr,
6844 D->getStorageClass(), TemplateArgs))
6845 return ToPartial;
6846
6847 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6848 import(FromPartial->getInstantiatedFromMember()))
6849 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6850 else
6851 return ToInstOrErr.takeError();
6852
6853 if (FromPartial->isMemberSpecialization())
6854 ToPartial->setMemberSpecialization();
6855
6856 D2 = ToPartial;
6857
6858 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6859 // to adopt template parameters.
6860 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6861 } else { // Full specialization
6862 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6863 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6864 QualType(), nullptr, D->getStorageClass(),
6865 TemplateArgs))
6866 return D2;
6867 }
6868
6869 // Update InsertPos, because preceding import calls may have invalidated
6870 // it by adding new specializations.
6871 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6872 VarTemplate->AddSpecialization(D2, InsertPos);
6873
6874 QualType T;
6875 if (Error Err = importInto(T, D->getType()))
6876 return std::move(Err);
6877 D2->setType(T);
6878
6879 auto TInfoOrErr = import(D->getTypeSourceInfo());
6880 if (!TInfoOrErr)
6881 return TInfoOrErr.takeError();
6882 D2->setTypeSourceInfo(*TInfoOrErr);
6883
6884 if (D->getPointOfInstantiation().isValid()) {
6885 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6886 D2->setPointOfInstantiation(*POIOrErr);
6887 else
6888 return POIOrErr.takeError();
6889 }
6890
6892
6893 if (D->getTemplateArgsAsWritten())
6894 D2->setTemplateArgsAsWritten(ToTAInfo);
6895
6896 if (auto LocOrErr = import(D->getQualifierLoc()))
6897 D2->setQualifierInfo(*LocOrErr);
6898 else
6899 return LocOrErr.takeError();
6900
6901 if (D->isConstexpr())
6902 D2->setConstexpr(true);
6903
6904 D2->setAccess(D->getAccess());
6905
6906 if (Error Err = ImportInitializer(D, D2))
6907 return std::move(Err);
6908
6909 if (FoundSpecialization)
6910 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6911
6912 addDeclToContexts(D, D2);
6913
6914 // Import the rest of the chain. I.e. import all subsequent declarations.
6915 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6916 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6917 if (!RedeclOrErr)
6918 return RedeclOrErr.takeError();
6919 }
6920
6921 return D2;
6922}
6923
6926 DeclContext *DC, *LexicalDC;
6927 DeclarationName Name;
6928 SourceLocation Loc;
6929 NamedDecl *ToD;
6930
6931 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6932 return std::move(Err);
6933
6934 if (ToD)
6935 return ToD;
6936
6937 const FunctionTemplateDecl *FoundByLookup = nullptr;
6938
6939 // Try to find a function in our own ("to") context with the same name, same
6940 // type, and in the same context as the function we're importing.
6941 // FIXME Split this into a separate function.
6942 if (!LexicalDC->isFunctionOrMethod()) {
6944 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6945 for (auto *FoundDecl : FoundDecls) {
6946 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6947 continue;
6948
6949 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6950 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6951 continue;
6952 if (IsStructuralMatch(D, FoundTemplate)) {
6953 FunctionTemplateDecl *TemplateWithDef =
6954 getTemplateDefinition(FoundTemplate);
6955 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6956 return Importer.MapImported(D, TemplateWithDef);
6957
6958 FoundByLookup = FoundTemplate;
6959 break;
6960 // TODO: handle conflicting names
6961 }
6962 }
6963 }
6964 }
6965
6966 auto ParamsOrErr = import(D->getTemplateParameters());
6967 if (!ParamsOrErr)
6968 return ParamsOrErr.takeError();
6969 TemplateParameterList *Params = *ParamsOrErr;
6970
6971 FunctionDecl *TemplatedFD;
6972 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6973 return std::move(Err);
6974
6975 // At creation of the template the template parameters are "adopted"
6976 // (DeclContext is changed). After this possible change the lookup table
6977 // must be updated.
6978 // At deduction guides the DeclContext of the template parameters may be
6979 // different from what we would expect, it may be the class template, or a
6980 // probably different CXXDeductionGuideDecl. This may come from the fact that
6981 // the template parameter objects may be shared between deduction guides or
6982 // the class template, and at creation of multiple FunctionTemplateDecl
6983 // objects (for deduction guides) the same parameters are re-used. The
6984 // "adoption" happens multiple times with different parent, even recursively
6985 // for TemplateTemplateParmDecl. The same happens at import when the
6986 // FunctionTemplateDecl objects are created, but in different order.
6987 // In this way the DeclContext of these template parameters is not necessarily
6988 // the same as in the "from" context.
6990 OldParamDC.reserve(Params->size());
6991 llvm::transform(*Params, std::back_inserter(OldParamDC),
6992 [](NamedDecl *ND) { return ND->getDeclContext(); });
6993
6994 FunctionTemplateDecl *ToFunc;
6995 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6996 Params, TemplatedFD))
6997 return ToFunc;
6998
6999 // Fail if TemplatedFD is already part of a template.
7000 // The template should have been found by structural equivalence check before,
7001 // or ToFunc should be already imported.
7002 // If not, there is AST incompatibility that can be caused by previous import
7003 // errors. (NameConflict is not exact here.)
7004 if (TemplatedFD->getDescribedTemplate())
7005 return make_error<ASTImportError>(ASTImportError::NameConflict);
7006
7007 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
7008
7009 ToFunc->setAccess(D->getAccess());
7010 ToFunc->setLexicalDeclContext(LexicalDC);
7011 addDeclToContexts(D, ToFunc);
7012
7013 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
7014 if (LT && !OldParamDC.empty()) {
7015 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
7016 LT->updateForced(Params->getParam(I), OldParamDC[I]);
7017 }
7018
7019 if (FoundByLookup) {
7020 auto *Recent =
7021 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
7022 if (!TemplatedFD->getPreviousDecl()) {
7023 assert(FoundByLookup->getTemplatedDecl() &&
7024 "Found decl must have its templated decl set");
7025 auto *PrevTemplated =
7026 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
7027 if (TemplatedFD != PrevTemplated)
7028 TemplatedFD->setPreviousDecl(PrevTemplated);
7029 }
7030 ToFunc->setPreviousDecl(Recent);
7031 }
7032
7033 return ToFunc;
7034}
7035
7037 DeclContext *DC, *LexicalDC;
7038 Error Err = ImportDeclContext(D, DC, LexicalDC);
7039 auto LocationOrErr = importChecked(Err, D->getLocation());
7040 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
7041 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
7042 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
7043 if (Err)
7044 return std::move(Err);
7045
7046 ConceptDecl *To;
7047 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
7048 NameDeclOrErr, ToTemplateParameters,
7049 ConstraintExpr))
7050 return To;
7051 To->setLexicalDeclContext(LexicalDC);
7052 LexicalDC->addDeclInternal(To);
7053 return To;
7054}
7055
7058 DeclContext *DC, *LexicalDC;
7059 Error Err = ImportDeclContext(D, DC, LexicalDC);
7060 auto RequiresLoc = importChecked(Err, D->getLocation());
7061 if (Err)
7062 return std::move(Err);
7063
7065 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
7066 return To;
7067 To->setLexicalDeclContext(LexicalDC);
7068 LexicalDC->addDeclInternal(To);
7069 return To;
7070}
7071
7074 DeclContext *DC, *LexicalDC;
7075 Error Err = ImportDeclContext(D, DC, LexicalDC);
7076 auto ToSL = importChecked(Err, D->getLocation());
7077 if (Err)
7078 return std::move(Err);
7079
7081 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
7082 return std::move(Err);
7083
7085 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
7086 return To;
7087 To->setLexicalDeclContext(LexicalDC);
7088 LexicalDC->addDeclInternal(To);
7089 return To;
7090}
7091
7092//----------------------------------------------------------------------------
7093// Import Statements
7094//----------------------------------------------------------------------------
7095
7097 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7098 << S->getStmtClassName();
7099 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7100}
7101
7102
7104 if (Importer.returnWithErrorInTest())
7105 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7107 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7108 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7109 // ToII is nullptr when no symbolic name is given for output operand
7110 // see ParseStmtAsm::ParseAsmOperandsOpt
7111 Names.push_back(ToII);
7112 }
7113
7114 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7115 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7116 // ToII is nullptr when no symbolic name is given for input operand
7117 // see ParseStmtAsm::ParseAsmOperandsOpt
7118 Names.push_back(ToII);
7119 }
7120
7121 SmallVector<Expr *, 4> Clobbers;
7122 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7123 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7124 Clobbers.push_back(*ClobberOrErr);
7125 else
7126 return ClobberOrErr.takeError();
7127
7128 }
7129
7130 SmallVector<Expr *, 4> Constraints;
7131 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7132 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7133 Constraints.push_back(*OutputOrErr);
7134 else
7135 return OutputOrErr.takeError();
7136 }
7137
7138 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7139 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7140 Constraints.push_back(*InputOrErr);
7141 else
7142 return InputOrErr.takeError();
7143 }
7144
7146 S->getNumLabels());
7147 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7148 return std::move(Err);
7149
7150 if (Error Err =
7151 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7152 return std::move(Err);
7153
7154 if (Error Err = ImportArrayChecked(
7155 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7156 return std::move(Err);
7157
7158 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7159 if (!AsmLocOrErr)
7160 return AsmLocOrErr.takeError();
7161 auto AsmStrOrErr = import(S->getAsmStringExpr());
7162 if (!AsmStrOrErr)
7163 return AsmStrOrErr.takeError();
7164 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7165 if (!RParenLocOrErr)
7166 return RParenLocOrErr.takeError();
7167
7168 return new (Importer.getToContext()) GCCAsmStmt(
7169 Importer.getToContext(),
7170 *AsmLocOrErr,
7171 S->isSimple(),
7172 S->isVolatile(),
7173 S->getNumOutputs(),
7174 S->getNumInputs(),
7175 Names.data(),
7176 Constraints.data(),
7177 Exprs.data(),
7178 *AsmStrOrErr,
7179 S->getNumClobbers(),
7180 Clobbers.data(),
7181 S->getNumLabels(),
7182 *RParenLocOrErr);
7183}
7184
7186
7187 Error Err = Error::success();
7188 auto ToDG = importChecked(Err, S->getDeclGroup());
7189 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7190 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7191 if (Err)
7192 return std::move(Err);
7193 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7194}
7195
7197 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7198 if (!ToSemiLocOrErr)
7199 return ToSemiLocOrErr.takeError();
7200 return new (Importer.getToContext()) NullStmt(
7201 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7202}
7203
7205 SmallVector<Stmt *, 8> ToStmts(S->size());
7206
7207 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7208 return std::move(Err);
7209
7210 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7211 if (!ToLBracLocOrErr)
7212 return ToLBracLocOrErr.takeError();
7213
7214 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7215 if (!ToRBracLocOrErr)
7216 return ToRBracLocOrErr.takeError();
7217
7218 FPOptionsOverride FPO =
7220 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7221 *ToLBracLocOrErr, *ToRBracLocOrErr);
7222}
7223
7225
7226 Error Err = Error::success();
7227 auto ToLHS = importChecked(Err, S->getLHS());
7228 auto ToRHS = importChecked(Err, S->getRHS());
7229 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7230 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7231 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7232 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7233 if (Err)
7234 return std::move(Err);
7235
7236 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7237 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7238 ToStmt->setSubStmt(ToSubStmt);
7239
7240 return ToStmt;
7241}
7242
7244
7245 Error Err = Error::success();
7246 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7247 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7248 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7249 if (Err)
7250 return std::move(Err);
7251
7252 return new (Importer.getToContext()) DefaultStmt(
7253 ToDefaultLoc, ToColonLoc, ToSubStmt);
7254}
7255
7257
7258 Error Err = Error::success();
7259 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7260 auto ToLabelDecl = importChecked(Err, S->getDecl());
7261 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7262 if (Err)
7263 return std::move(Err);
7264
7265 return new (Importer.getToContext()) LabelStmt(
7266 ToIdentLoc, ToLabelDecl, ToSubStmt);
7267}
7268
7270 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7271 if (!ToAttrLocOrErr)
7272 return ToAttrLocOrErr.takeError();
7273 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7274 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7275 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7276 return std::move(Err);
7277 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7278 if (!ToSubStmtOrErr)
7279 return ToSubStmtOrErr.takeError();
7280
7282 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7283}
7284
7286
7287 Error Err = Error::success();
7288 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7289 auto ToInit = importChecked(Err, S->getInit());
7290 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7291 auto ToCond = importChecked(Err, S->getCond());
7292 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7293 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7294 auto ToThen = importChecked(Err, S->getThen());
7295 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7296 auto ToElse = importChecked(Err, S->getElse());
7297 if (Err)
7298 return std::move(Err);
7299
7300 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7301 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7302 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7303}
7304
7306
7307 Error Err = Error::success();
7308 auto ToInit = importChecked(Err, S->getInit());
7309 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7310 auto ToCond = importChecked(Err, S->getCond());
7311 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7312 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7313 auto ToBody = importChecked(Err, S->getBody());
7314 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7315 if (Err)
7316 return std::move(Err);
7317
7318 auto *ToStmt =
7319 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7320 ToCond, ToLParenLoc, ToRParenLoc);
7321 ToStmt->setBody(ToBody);
7322 ToStmt->setSwitchLoc(ToSwitchLoc);
7323
7324 // Now we have to re-chain the cases.
7325 SwitchCase *LastChainedSwitchCase = nullptr;
7326 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7327 SC = SC->getNextSwitchCase()) {
7328 Expected<SwitchCase *> ToSCOrErr = import(SC);
7329 if (!ToSCOrErr)
7330 return ToSCOrErr.takeError();
7331 if (LastChainedSwitchCase)
7332 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7333 else
7334 ToStmt->setSwitchCaseList(*ToSCOrErr);
7335 LastChainedSwitchCase = *ToSCOrErr;
7336 }
7337
7338 return ToStmt;
7339}
7340
7342
7343 Error Err = Error::success();
7344 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7345 auto ToCond = importChecked(Err, S->getCond());
7346 auto ToBody = importChecked(Err, S->getBody());
7347 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7348 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7349 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7350 if (Err)
7351 return std::move(Err);
7352
7353 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7354 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7355}
7356
7358
7359 Error Err = Error::success();
7360 auto ToBody = importChecked(Err, S->getBody());
7361 auto ToCond = importChecked(Err, S->getCond());
7362 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7363 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7364 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7365 if (Err)
7366 return std::move(Err);
7367
7368 return new (Importer.getToContext()) DoStmt(
7369 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7370}
7371
7373
7374 Error Err = Error::success();
7375 auto ToInit = importChecked(Err, S->getInit());
7376 auto ToCond = importChecked(Err, S->getCond());
7377 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7378 auto ToInc = importChecked(Err, S->getInc());
7379 auto ToBody = importChecked(Err, S->getBody());
7380 auto ToForLoc = importChecked(Err, S->getForLoc());
7381 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7382 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7383 if (Err)
7384 return std::move(Err);
7385
7386 return new (Importer.getToContext()) ForStmt(
7387 Importer.getToContext(),
7388 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7389 ToRParenLoc);
7390}
7391
7393
7394 Error Err = Error::success();
7395 auto ToLabel = importChecked(Err, S->getLabel());
7396 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7397 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7398 if (Err)
7399 return std::move(Err);
7400
7401 return new (Importer.getToContext()) GotoStmt(
7402 ToLabel, ToGotoLoc, ToLabelLoc);
7403}
7404
7406
7407 Error Err = Error::success();
7408 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7409 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7410 auto ToTarget = importChecked(Err, S->getTarget());
7411 if (Err)
7412 return std::move(Err);
7413
7414 return new (Importer.getToContext()) IndirectGotoStmt(
7415 ToGotoLoc, ToStarLoc, ToTarget);
7416}
7417
7418template <typename StmtClass>
7420 ASTImporter &Importer, StmtClass *S) {
7421 Error Err = Error::success();
7422 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7423 auto ToLabelLoc = S->hasLabelTarget()
7424 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7425 : SourceLocation();
7426 auto ToDecl = S->hasLabelTarget()
7427 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7428 : nullptr;
7429 if (Err)
7430 return std::move(Err);
7431 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7432}
7433
7437
7441
7443
7444 Error Err = Error::success();
7445 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7446 auto ToRetValue = importChecked(Err, S->getRetValue());
7447 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7448 if (Err)
7449 return std::move(Err);
7450
7451 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7452 ToNRVOCandidate);
7453}
7454
7456
7457 Error Err = Error::success();
7458 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7459 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7460 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7461 if (Err)
7462 return std::move(Err);
7463
7464 return new (Importer.getToContext()) CXXCatchStmt (
7465 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7466}
7467
7469 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7470 if (!ToTryLocOrErr)
7471 return ToTryLocOrErr.takeError();
7472
7473 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7474 if (!ToTryBlockOrErr)
7475 return ToTryBlockOrErr.takeError();
7476
7477 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7478 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7479 CXXCatchStmt *FromHandler = S->getHandler(HI);
7480 if (auto ToHandlerOrErr = import(FromHandler))
7481 ToHandlers[HI] = *ToHandlerOrErr;
7482 else
7483 return ToHandlerOrErr.takeError();
7484 }
7485
7486 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7487 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7488}
7489
7491
7492 Error Err = Error::success();
7493 auto ToInit = importChecked(Err, S->getInit());
7494 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7495 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7496 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7497 auto ToCond = importChecked(Err, S->getCond());
7498 auto ToInc = importChecked(Err, S->getInc());
7499 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7500 auto ToBody = importChecked(Err, S->getBody());
7501 auto ToForLoc = importChecked(Err, S->getForLoc());
7502 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7503 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7504 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7505 if (Err)
7506 return std::move(Err);
7507
7508 return new (Importer.getToContext()) CXXForRangeStmt(
7509 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7510 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7511}
7512
7515 Error Err = Error::success();
7516 auto ToElement = importChecked(Err, S->getElement());
7517 auto ToCollection = importChecked(Err, S->getCollection());
7518 auto ToBody = importChecked(Err, S->getBody());
7519 auto ToForLoc = importChecked(Err, S->getForLoc());
7520 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7521 if (Err)
7522 return std::move(Err);
7523
7524 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7525 ToCollection,
7526 ToBody,
7527 ToForLoc,
7528 ToRParenLoc);
7529}
7530
7532
7533 Error Err = Error::success();
7534 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7535 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7536 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7537 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7538 if (Err)
7539 return std::move(Err);
7540
7541 return new (Importer.getToContext()) ObjCAtCatchStmt (
7542 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7543}
7544
7546 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7547 if (!ToAtFinallyLocOrErr)
7548 return ToAtFinallyLocOrErr.takeError();
7549 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7550 if (!ToAtFinallyStmtOrErr)
7551 return ToAtFinallyStmtOrErr.takeError();
7552 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7553 *ToAtFinallyStmtOrErr);
7554}
7555
7557
7558 Error Err = Error::success();
7559 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7560 auto ToTryBody = importChecked(Err, S->getTryBody());
7561 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7562 if (Err)
7563 return std::move(Err);
7564
7565 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7566 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7567 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7568 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7569 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7570 else
7571 return ToCatchStmtOrErr.takeError();
7572 }
7573
7574 return ObjCAtTryStmt::Create(Importer.getToContext(),
7575 ToAtTryLoc, ToTryBody,
7576 ToCatchStmts.begin(), ToCatchStmts.size(),
7577 ToFinallyStmt);
7578}
7579
7582
7583 Error Err = Error::success();
7584 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7585 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7586 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7587 if (Err)
7588 return std::move(Err);
7589
7590 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7591 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7592}
7593
7595 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7596 if (!ToThrowLocOrErr)
7597 return ToThrowLocOrErr.takeError();
7598 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7599 if (!ToThrowExprOrErr)
7600 return ToThrowExprOrErr.takeError();
7601 return new (Importer.getToContext()) ObjCAtThrowStmt(
7602 *ToThrowLocOrErr, *ToThrowExprOrErr);
7603}
7604
7607 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7608 if (!ToAtLocOrErr)
7609 return ToAtLocOrErr.takeError();
7610 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7611 if (!ToSubStmtOrErr)
7612 return ToSubStmtOrErr.takeError();
7613 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7614 *ToSubStmtOrErr);
7615}
7616
7617//----------------------------------------------------------------------------
7618// Import Expressions
7619//----------------------------------------------------------------------------
7621 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7622 << E->getStmtClassName();
7623 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7624}
7625
7627 Error Err = Error::success();
7628 auto ToType = importChecked(Err, E->getType());
7629 auto BLoc = importChecked(Err, E->getBeginLoc());
7630 auto RParenLoc = importChecked(Err, E->getEndLoc());
7631 if (Err)
7632 return std::move(Err);
7633 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7634 if (!ParentContextOrErr)
7635 return ParentContextOrErr.takeError();
7636
7637 return new (Importer.getToContext())
7638 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7639 RParenLoc, *ParentContextOrErr);
7640}
7641
7643
7644 Error Err = Error::success();
7645 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7646 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7647 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7648 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7649 auto ToType = importChecked(Err, E->getType());
7650 if (Err)
7651 return std::move(Err);
7652
7653 return new (Importer.getToContext()) VAArgExpr(
7654 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7655 E->isMicrosoftABI());
7656}
7657
7659
7660 Error Err = Error::success();
7661 auto ToCond = importChecked(Err, E->getCond());
7662 auto ToLHS = importChecked(Err, E->getLHS());
7663 auto ToRHS = importChecked(Err, E->getRHS());
7664 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7665 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7666 auto ToType = importChecked(Err, E->getType());
7667 if (Err)
7668 return std::move(Err);
7669
7671 ExprObjectKind OK = E->getObjectKind();
7672
7673 // The value of CondIsTrue only matters if the value is not
7674 // condition-dependent.
7675 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7676
7677 return new (Importer.getToContext())
7678 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7679 ToRParenLoc, CondIsTrue);
7680}
7681
7683 Error Err = Error::success();
7684 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7685 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7686 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7687 auto ToType = importChecked(Err, E->getType());
7688 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7689 if (Err)
7690 return std::move(Err);
7691
7693 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7694 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7696}
7697
7699 Error Err = Error::success();
7700 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7701 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7702 auto ToType = importChecked(Err, E->getType());
7703 const unsigned NumSubExprs = E->getNumSubExprs();
7704
7706 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7707 ToSubExprs.resize(NumSubExprs);
7708
7709 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7710 return std::move(Err);
7711
7712 return new (Importer.getToContext()) ShuffleVectorExpr(
7713 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7714}
7715
7717 ExpectedType TypeOrErr = import(E->getType());
7718 if (!TypeOrErr)
7719 return TypeOrErr.takeError();
7720
7721 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7722 if (!BeginLocOrErr)
7723 return BeginLocOrErr.takeError();
7724
7725 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7726}
7727
7730 Error Err = Error::success();
7731 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7732 Expr *ToControllingExpr = nullptr;
7733 TypeSourceInfo *ToControllingType = nullptr;
7734 if (E->isExprPredicate())
7735 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7736 else
7737 ToControllingType = importChecked(Err, E->getControllingType());
7738 assert((ToControllingExpr || ToControllingType) &&
7739 "Either the controlling expr or type must be nonnull");
7740 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7741 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7742 if (Err)
7743 return std::move(Err);
7744
7746 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7747 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7748 return std::move(Err);
7749
7750 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7751 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7752 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7753 return std::move(Err);
7754
7755 const ASTContext &ToCtx = Importer.getToContext();
7756 if (E->isResultDependent()) {
7757 if (ToControllingExpr) {
7759 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7760 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7762 }
7764 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7765 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7767 }
7768
7769 if (ToControllingExpr) {
7771 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7772 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7774 }
7776 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7777 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7779}
7780
7782
7783 Error Err = Error::success();
7784 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7785 auto ToType = importChecked(Err, E->getType());
7786 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7787 if (Err)
7788 return std::move(Err);
7789
7790 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7791 E->getIdentKind(), E->isTransparent(),
7792 ToFunctionName);
7793}
7794
7796
7797 Error Err = Error::success();
7798 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7799 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7800 auto ToDecl = importChecked(Err, E->getDecl());
7801 auto ToLocation = importChecked(Err, E->getLocation());
7802 auto ToType = importChecked(Err, E->getType());
7803 if (Err)
7804 return std::move(Err);
7805
7806 NamedDecl *ToFoundD = nullptr;
7807 if (E->getDecl() != E->getFoundDecl()) {
7808 auto FoundDOrErr = import(E->getFoundDecl());
7809 if (!FoundDOrErr)
7810 return FoundDOrErr.takeError();
7811 ToFoundD = *FoundDOrErr;
7812 }
7813
7814 TemplateArgumentListInfo ToTAInfo;
7815 TemplateArgumentListInfo *ToResInfo = nullptr;
7816 if (E->hasExplicitTemplateArgs()) {
7817 if (Error Err =
7819 E->template_arguments(), ToTAInfo))
7820 return std::move(Err);
7821 ToResInfo = &ToTAInfo;
7822 }
7823
7824 auto *ToE = DeclRefExpr::Create(
7825 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7826 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7827 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7828 if (E->hadMultipleCandidates())
7829 ToE->setHadMultipleCandidates(true);
7830 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7831 return ToE;
7832}
7833
7835 ExpectedType TypeOrErr = import(E->getType());
7836 if (!TypeOrErr)
7837 return TypeOrErr.takeError();
7838
7839 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7840}
7841
7843 ExpectedExpr ToInitOrErr = import(E->getInit());
7844 if (!ToInitOrErr)
7845 return ToInitOrErr.takeError();
7846
7847 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7848 if (!ToEqualOrColonLocOrErr)
7849 return ToEqualOrColonLocOrErr.takeError();
7850
7851 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7852 // List elements from the second, the first is Init itself
7853 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7854 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7855 ToIndexExprs[I - 1] = *ToArgOrErr;
7856 else
7857 return ToArgOrErr.takeError();
7858 }
7859
7860 SmallVector<Designator, 4> ToDesignators(E->size());
7861 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7862 return std::move(Err);
7863
7865 Importer.getToContext(), ToDesignators,
7866 ToIndexExprs, *ToEqualOrColonLocOrErr,
7867 E->usesGNUSyntax(), *ToInitOrErr);
7868}
7869
7872 ExpectedType ToTypeOrErr = import(E->getType());
7873 if (!ToTypeOrErr)
7874 return ToTypeOrErr.takeError();
7875
7876 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7877 if (!ToLocationOrErr)
7878 return ToLocationOrErr.takeError();
7879
7880 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7881 *ToTypeOrErr, *ToLocationOrErr);
7882}
7883
7885 ExpectedType ToTypeOrErr = import(E->getType());
7886 if (!ToTypeOrErr)
7887 return ToTypeOrErr.takeError();
7888
7889 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7890 if (!ToLocationOrErr)
7891 return ToLocationOrErr.takeError();
7892
7894 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7895}
7896
7897
7899 ExpectedType ToTypeOrErr = import(E->getType());
7900 if (!ToTypeOrErr)
7901 return ToTypeOrErr.takeError();
7902
7903 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7904 if (!ToLocationOrErr)
7905 return ToLocationOrErr.takeError();
7906
7908 Importer.getToContext(), E->getValue(), E->isExact(),
7909 *ToTypeOrErr, *ToLocationOrErr);
7910}
7911
7913 auto ToTypeOrErr = import(E->getType());
7914 if (!ToTypeOrErr)
7915 return ToTypeOrErr.takeError();
7916
7917 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7918 if (!ToSubExprOrErr)
7919 return ToSubExprOrErr.takeError();
7920
7921 return new (Importer.getToContext()) ImaginaryLiteral(
7922 *ToSubExprOrErr, *ToTypeOrErr);
7923}
7924
7926 auto ToTypeOrErr = import(E->getType());
7927 if (!ToTypeOrErr)
7928 return ToTypeOrErr.takeError();
7929
7930 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7931 if (!ToLocationOrErr)
7932 return ToLocationOrErr.takeError();
7933
7934 return new (Importer.getToContext()) FixedPointLiteral(
7935 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7936 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7937}
7938
7940 ExpectedType ToTypeOrErr = import(E->getType());
7941 if (!ToTypeOrErr)
7942 return ToTypeOrErr.takeError();
7943
7944 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7945 if (!ToLocationOrErr)
7946 return ToLocationOrErr.takeError();
7947
7948 return new (Importer.getToContext()) CharacterLiteral(
7949 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7950}
7951
7953 ExpectedType ToTypeOrErr = import(E->getType());
7954 if (!ToTypeOrErr)
7955 return ToTypeOrErr.takeError();
7956
7958 if (Error Err = ImportArrayChecked(
7959 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7960 return std::move(Err);
7961
7962 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7963 E->getKind(), E->isPascal(), *ToTypeOrErr,
7964 ToLocations);
7965}
7966
7968
7969 Error Err = Error::success();
7970 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7971 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7972 auto ToType = importChecked(Err, E->getType());
7973 auto ToInitializer = importChecked(Err, E->getInitializer());
7974 if (Err)
7975 return std::move(Err);
7976
7977 return new (Importer.getToContext()) CompoundLiteralExpr(
7978 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7979 ToInitializer, E->isFileScope());
7980}
7981
7983
7984 Error Err = Error::success();
7985 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7986 auto ToType = importChecked(Err, E->getType());
7987 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7988 if (Err)
7989 return std::move(Err);
7990
7992 if (Error Err = ImportArrayChecked(
7993 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7994 ToExprs.begin()))
7995 return std::move(Err);
7996
7997 return new (Importer.getToContext()) AtomicExpr(
7998
7999 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
8000}
8001
8003 Error Err = Error::success();
8004 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
8005 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
8006 auto ToLabel = importChecked(Err, E->getLabel());
8007 auto ToType = importChecked(Err, E->getType());
8008 if (Err)
8009 return std::move(Err);
8010
8011 return new (Importer.getToContext()) AddrLabelExpr(
8012 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
8013}
8015 Error Err = Error::success();
8016 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8017 auto ToResult = importChecked(Err, E->getAPValueResult());
8018 if (Err)
8019 return std::move(Err);
8020
8021 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
8022}
8024 Error Err = Error::success();
8025 auto ToLParen = importChecked(Err, E->getLParen());
8026 auto ToRParen = importChecked(Err, E->getRParen());
8027 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8028 if (Err)
8029 return std::move(Err);
8030
8031 return new (Importer.getToContext())
8032 ParenExpr(ToLParen, ToRParen, ToSubExpr);
8033}
8034
8036 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
8037 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
8038 return std::move(Err);
8039
8040 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
8041 if (!ToLParenLocOrErr)
8042 return ToLParenLocOrErr.takeError();
8043
8044 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
8045 if (!ToRParenLocOrErr)
8046 return ToRParenLocOrErr.takeError();
8047
8048 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
8049 ToExprs, *ToRParenLocOrErr);
8050}
8051
8053 Error Err = Error::success();
8054 auto ToSubStmt = importChecked(Err, E->getSubStmt());
8055 auto ToType = importChecked(Err, E->getType());
8056 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8057 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8058 if (Err)
8059 return std::move(Err);
8060
8061 return new (Importer.getToContext())
8062 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8063 E->getTemplateDepth());
8064}
8065
8067 Error Err = Error::success();
8068 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8069 auto ToType = importChecked(Err, E->getType());
8070 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8071 if (Err)
8072 return std::move(Err);
8073
8074 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8075 E->hasStoredFPFeatures());
8076 UO->setType(ToType);
8077 UO->setSubExpr(ToSubExpr);
8078 UO->setOpcode(E->getOpcode());
8079 UO->setOperatorLoc(ToOperatorLoc);
8080 UO->setCanOverflow(E->canOverflow());
8081 if (E->hasStoredFPFeatures())
8082 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8083
8084 return UO;
8085}
8086
8088
8090 Error Err = Error::success();
8091 auto ToType = importChecked(Err, E->getType());
8092 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8093 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8094 if (Err)
8095 return std::move(Err);
8096
8097 if (E->isArgumentType()) {
8098 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8099 import(E->getArgumentTypeInfo());
8100 if (!ToArgumentTypeInfoOrErr)
8101 return ToArgumentTypeInfoOrErr.takeError();
8102
8103 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8104 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8105 ToRParenLoc);
8106 }
8107
8108 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8109 if (!ToArgumentExprOrErr)
8110 return ToArgumentExprOrErr.takeError();
8111
8112 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8113 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8114}
8115
8117 Error Err = Error::success();
8118 auto ToLHS = importChecked(Err, E->getLHS());
8119 auto ToRHS = importChecked(Err, E->getRHS());
8120 auto ToType = importChecked(Err, E->getType());
8121 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8122 if (Err)
8123 return std::move(Err);
8124
8126 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8127 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8128 E->getFPFeatures());
8129}
8130
8132 Error Err = Error::success();
8133 auto ToCond = importChecked(Err, E->getCond());
8134 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8135 auto ToLHS = importChecked(Err, E->getLHS());
8136 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8137 auto ToRHS = importChecked(Err, E->getRHS());
8138 auto ToType = importChecked(Err, E->getType());
8139 if (Err)
8140 return std::move(Err);
8141
8142 return new (Importer.getToContext()) ConditionalOperator(
8143 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8144 E->getValueKind(), E->getObjectKind());
8145}
8146
8149 Error Err = Error::success();
8150 auto ToCommon = importChecked(Err, E->getCommon());
8151 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8152 auto ToCond = importChecked(Err, E->getCond());
8153 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8154 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8155 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8156 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8157 auto ToType = importChecked(Err, E->getType());
8158 if (Err)
8159 return std::move(Err);
8160
8161 return new (Importer.getToContext()) BinaryConditionalOperator(
8162 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8163 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8164 E->getObjectKind());
8165}
8166
8169 Error Err = Error::success();
8170 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8171 if (Err)
8172 return std::move(Err);
8173
8174 return new (Importer.getToContext())
8175 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8176}
8177
8179 Error Err = Error::success();
8180 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8181 auto ToQueriedTypeSourceInfo =
8183 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8184 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8185 auto ToType = importChecked(Err, E->getType());
8186 if (Err)
8187 return std::move(Err);
8188
8189 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8190 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8191 ToDimensionExpression, ToEndLoc, ToType);
8192}
8193
8195 Error Err = Error::success();
8196 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8197 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8198 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8199 auto ToType = importChecked(Err, E->getType());
8200 if (Err)
8201 return std::move(Err);
8202
8203 return new (Importer.getToContext()) ExpressionTraitExpr(
8204 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8205 ToEndLoc, ToType);
8206}
8207
8209 Error Err = Error::success();
8210 auto ToLocation = importChecked(Err, E->getLocation());
8211 auto ToType = importChecked(Err, E->getType());
8212 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8213 if (Err)
8214 return std::move(Err);
8215
8216 return new (Importer.getToContext()) OpaqueValueExpr(
8217 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8218}
8219
8221 Error Err = Error::success();
8222 auto ToLHS = importChecked(Err, E->getLHS());
8223 auto ToRHS = importChecked(Err, E->getRHS());
8224 auto ToType = importChecked(Err, E->getType());
8225 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8226 if (Err)
8227 return std::move(Err);
8228
8229 return new (Importer.getToContext()) ArraySubscriptExpr(
8230 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8231 ToRBracketLoc);
8232}
8233
8236 Error Err = Error::success();
8237 auto ToLHS = importChecked(Err, E->getLHS());
8238 auto ToRHS = importChecked(Err, E->getRHS());
8239 auto ToType = importChecked(Err, E->getType());
8240 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8241 auto ToComputationResultType =
8243 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8244 if (Err)
8245 return std::move(Err);
8246
8248 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8249 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8250 E->getFPFeatures(),
8251 ToComputationLHSType, ToComputationResultType);
8252}
8253
8256 CXXCastPath Path;
8257 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8258 if (auto SpecOrErr = import(*I))
8259 Path.push_back(*SpecOrErr);
8260 else
8261 return SpecOrErr.takeError();
8262 }
8263 return Path;
8264}
8265
8267 ExpectedType ToTypeOrErr = import(E->getType());
8268 if (!ToTypeOrErr)
8269 return ToTypeOrErr.takeError();
8270
8271 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8272 if (!ToSubExprOrErr)
8273 return ToSubExprOrErr.takeError();
8274
8275 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8276 if (!ToBasePathOrErr)
8277 return ToBasePathOrErr.takeError();
8278
8280 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8281 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8282}
8283
8285 Error Err = Error::success();
8286 auto ToType = importChecked(Err, E->getType());
8287 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8288 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8289 if (Err)
8290 return std::move(Err);
8291
8292 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8293 if (!ToBasePathOrErr)
8294 return ToBasePathOrErr.takeError();
8295 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8296
8297 switch (E->getStmtClass()) {
8298 case Stmt::CStyleCastExprClass: {
8299 auto *CCE = cast<CStyleCastExpr>(E);
8300 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8301 if (!ToLParenLocOrErr)
8302 return ToLParenLocOrErr.takeError();
8303 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8304 if (!ToRParenLocOrErr)
8305 return ToRParenLocOrErr.takeError();
8307 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8308 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8309 *ToLParenLocOrErr, *ToRParenLocOrErr);
8310 }
8311
8312 case Stmt::CXXFunctionalCastExprClass: {
8313 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8314 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8315 if (!ToLParenLocOrErr)
8316 return ToLParenLocOrErr.takeError();
8317 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8318 if (!ToRParenLocOrErr)
8319 return ToRParenLocOrErr.takeError();
8321 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8322 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8323 *ToLParenLocOrErr, *ToRParenLocOrErr);
8324 }
8325
8326 case Stmt::ObjCBridgedCastExprClass: {
8327 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8328 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8329 if (!ToLParenLocOrErr)
8330 return ToLParenLocOrErr.takeError();
8331 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8332 if (!ToBridgeKeywordLocOrErr)
8333 return ToBridgeKeywordLocOrErr.takeError();
8334 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8335 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8336 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8337 }
8338 case Stmt::BuiltinBitCastExprClass: {
8339 auto *BBC = cast<BuiltinBitCastExpr>(E);
8340 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8341 if (!ToKWLocOrErr)
8342 return ToKWLocOrErr.takeError();
8343 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8344 if (!ToRParenLocOrErr)
8345 return ToRParenLocOrErr.takeError();
8346 return new (Importer.getToContext()) BuiltinBitCastExpr(
8347 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8348 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8349 }
8350 default:
8351 llvm_unreachable("Cast expression of unsupported type!");
8352 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8353 }
8354}
8355
8358 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8359 const OffsetOfNode &FromNode = E->getComponent(I);
8360
8361 SourceLocation ToBeginLoc, ToEndLoc;
8362
8363 if (FromNode.getKind() != OffsetOfNode::Base) {
8364 Error Err = Error::success();
8365 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8366 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8367 if (Err)
8368 return std::move(Err);
8369 }
8370
8371 switch (FromNode.getKind()) {
8373 ToNodes.push_back(
8374 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8375 break;
8376 case OffsetOfNode::Base: {
8377 auto ToBSOrErr = import(FromNode.getBase());
8378 if (!ToBSOrErr)
8379 return ToBSOrErr.takeError();
8380 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8381 break;
8382 }
8383 case OffsetOfNode::Field: {
8384 auto ToFieldOrErr = import(FromNode.getField());
8385 if (!ToFieldOrErr)
8386 return ToFieldOrErr.takeError();
8387 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8388 break;
8389 }
8391 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8392 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8393 break;
8394 }
8395 }
8396 }
8397
8399 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8400 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8401 if (!ToIndexExprOrErr)
8402 return ToIndexExprOrErr.takeError();
8403 ToExprs[I] = *ToIndexExprOrErr;
8404 }
8405
8406 Error Err = Error::success();
8407 auto ToType = importChecked(Err, E->getType());
8408 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8409 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8410 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8411 if (Err)
8412 return std::move(Err);
8413
8414 return OffsetOfExpr::Create(
8415 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8416 ToExprs, ToRParenLoc);
8417}
8418
8420 Error Err = Error::success();
8421 auto ToType = importChecked(Err, E->getType());
8422 auto ToOperand = importChecked(Err, E->getOperand());
8423 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8424 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8425 if (Err)
8426 return std::move(Err);
8427
8428 CanThrowResult ToCanThrow;
8429 if (E->isValueDependent())
8430 ToCanThrow = CT_Dependent;
8431 else
8432 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8433
8434 return new (Importer.getToContext()) CXXNoexceptExpr(
8435 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8436}
8437
8439 Error Err = Error::success();
8440 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8441 auto ToType = importChecked(Err, E->getType());
8442 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8443 if (Err)
8444 return std::move(Err);
8445
8446 return new (Importer.getToContext()) CXXThrowExpr(
8447 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8448}
8449
8451 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8452 if (!ToUsedLocOrErr)
8453 return ToUsedLocOrErr.takeError();
8454
8455 auto ToParamOrErr = import(E->getParam());
8456 if (!ToParamOrErr)
8457 return ToParamOrErr.takeError();
8458
8459 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8460 if (!UsedContextOrErr)
8461 return UsedContextOrErr.takeError();
8462
8463 // Import the default arg if it was not imported yet.
8464 // This is needed because it can happen that during the import of the
8465 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8466 // encountered here. The default argument for a ParmVarDecl is set in the
8467 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8468 // see VisitParmVarDecl).
8469 ParmVarDecl *ToParam = *ToParamOrErr;
8470 if (!ToParam->getDefaultArg()) {
8471 std::optional<ParmVarDecl *> FromParam =
8472 Importer.getImportedFromDecl(ToParam);
8473 assert(FromParam && "ParmVarDecl was not imported?");
8474
8475 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8476 return std::move(Err);
8477 }
8478 Expr *RewrittenInit = nullptr;
8479 if (E->hasRewrittenInit()) {
8480 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8481 if (!ExprOrErr)
8482 return ExprOrErr.takeError();
8483 RewrittenInit = ExprOrErr.get();
8484 }
8485 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8486 *ToParamOrErr, RewrittenInit,
8487 *UsedContextOrErr);
8488}
8489
8492 Error Err = Error::success();
8493 auto ToType = importChecked(Err, E->getType());
8494 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8495 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8496 if (Err)
8497 return std::move(Err);
8498
8499 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8500 ToType, ToTypeSourceInfo, ToRParenLoc);
8501}
8502
8505 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8506 if (!ToSubExprOrErr)
8507 return ToSubExprOrErr.takeError();
8508
8509 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8510 if (!ToDtorOrErr)
8511 return ToDtorOrErr.takeError();
8512
8513 ASTContext &ToCtx = Importer.getToContext();
8514 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8515 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8516}
8517
8519
8521 Error Err = Error::success();
8522 auto ToConstructor = importChecked(Err, E->getConstructor());
8523 auto ToType = importChecked(Err, E->getType());
8524 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8525 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8526 if (Err)
8527 return std::move(Err);
8528
8530 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8531 return std::move(Err);
8532
8534 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8535 ToParenOrBraceRange, E->hadMultipleCandidates(),
8538}
8539
8542 DeclContext *DC, *LexicalDC;
8543 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8544 return std::move(Err);
8545
8546 Error Err = Error::success();
8547 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8548 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8549 if (Err)
8550 return std::move(Err);
8551 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8552
8554 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8555 D->getManglingNumber()))
8556 return To;
8557
8558 To->setLexicalDeclContext(LexicalDC);
8559 LexicalDC->addDeclInternal(To);
8560 return To;
8561}
8562
8565 Error Err = Error::success();
8566 auto ToType = importChecked(Err, E->getType());
8567 Expr *ToTemporaryExpr = importChecked(
8568 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8569 auto ToMaterializedDecl =
8571 if (Err)
8572 return std::move(Err);
8573
8574 if (!ToTemporaryExpr)
8575 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8576
8577 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8578 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8579 ToMaterializedDecl);
8580
8581 return ToMTE;
8582}
8583
8585 Error Err = Error::success();
8586 auto *ToPattern = importChecked(Err, E->getPattern());
8587 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8588 if (Err)
8589 return std::move(Err);
8590
8591 return new (Importer.getToContext())
8592 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8593}
8594
8596 Error Err = Error::success();
8597 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8598 auto ToPack = importChecked(Err, E->getPack());
8599 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8600 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8601 if (Err)
8602 return std::move(Err);
8603
8604 UnsignedOrNone Length = std::nullopt;
8605 if (!E->isValueDependent())
8606 Length = E->getPackLength();
8607
8608 SmallVector<TemplateArgument, 8> ToPartialArguments;
8609 if (E->isPartiallySubstituted()) {
8611 ToPartialArguments))
8612 return std::move(Err);
8613 }
8614
8616 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8617 Length, ToPartialArguments);
8618}
8619
8620
8622 Error Err = Error::success();
8623 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8624 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8625 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8626 auto ToArraySize = importChecked(Err, E->getArraySize());
8627 auto ToInitializer = importChecked(Err, E->getInitializer());
8628 auto ToType = importChecked(Err, E->getType());
8629 auto ToAllocatedTypeSourceInfo =
8631 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8632 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8633 if (Err)
8634 return std::move(Err);
8635
8636 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8637 if (Error Err =
8638 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8639 return std::move(Err);
8640
8641 return CXXNewExpr::Create(
8642 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8643 ToOperatorDelete, E->implicitAllocationParameters(),
8644 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8645 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8646 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8647}
8648
8650 Error Err = Error::success();
8651 auto ToType = importChecked(Err, E->getType());
8652 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8653 auto ToArgument = importChecked(Err, E->getArgument());
8654 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8655 if (Err)
8656 return std::move(Err);
8657
8658 return new (Importer.getToContext()) CXXDeleteExpr(
8659 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8660 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8661 ToBeginLoc);
8662}
8663
8665 Error Err = Error::success();
8666 auto ToType = importChecked(Err, E->getType());
8667 auto ToLocation = importChecked(Err, E->getLocation());
8668 auto ToConstructor = importChecked(Err, E->getConstructor());
8669 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8670 if (Err)
8671 return std::move(Err);
8672
8674 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8675 return std::move(Err);
8676
8678 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8679 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8682 ToParenOrBraceRange);
8684 return ToE;
8685}
8686
8688 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8689 if (!ToSubExprOrErr)
8690 return ToSubExprOrErr.takeError();
8691
8693 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8694 return std::move(Err);
8695
8697 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8698 ToObjects);
8699}
8700
8702 Error Err = Error::success();
8703 auto ToCallee = importChecked(Err, E->getCallee());
8704 auto ToType = importChecked(Err, E->getType());
8705 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8706 if (Err)
8707 return std::move(Err);
8708
8710 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8711 return std::move(Err);
8712
8713 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8714 ToType, E->getValueKind(), ToRParenLoc,
8715 E->getFPFeatures());
8716}
8717
8719 ExpectedType ToTypeOrErr = import(E->getType());
8720 if (!ToTypeOrErr)
8721 return ToTypeOrErr.takeError();
8722
8723 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8724 if (!ToLocationOrErr)
8725 return ToLocationOrErr.takeError();
8726
8727 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8728 *ToTypeOrErr, E->isImplicit());
8729}
8730
8732 ExpectedType ToTypeOrErr = import(E->getType());
8733 if (!ToTypeOrErr)
8734 return ToTypeOrErr.takeError();
8735
8736 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8737 if (!ToLocationOrErr)
8738 return ToLocationOrErr.takeError();
8739
8740 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8741 *ToTypeOrErr, *ToLocationOrErr);
8742}
8743
8745 Error Err = Error::success();
8746 auto ToBase = importChecked(Err, E->getBase());
8747 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8748 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8749 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8750 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8751 auto ToType = importChecked(Err, E->getType());
8752 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8753 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8754 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8755 if (Err)
8756 return std::move(Err);
8757
8758 DeclAccessPair ToFoundDecl =
8760
8761 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8762
8763 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8764 if (E->hasExplicitTemplateArgs()) {
8765 if (Error Err =
8767 E->template_arguments(), ToTAInfo))
8768 return std::move(Err);
8769 ResInfo = &ToTAInfo;
8770 }
8771
8772 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8773 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8774 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8775 ResInfo, ToType, E->getValueKind(),
8776 E->getObjectKind(), E->isNonOdrUse());
8777}
8778
8781 Error Err = Error::success();
8782 auto ToBase = importChecked(Err, E->getBase());
8783 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8784 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8785 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8786 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8787 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8788 if (Err)
8789 return std::move(Err);
8790
8792 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8793 const IdentifierInfo *ToII = Importer.Import(FromII);
8794 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8795 if (!ToDestroyedTypeLocOrErr)
8796 return ToDestroyedTypeLocOrErr.takeError();
8797 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8798 } else {
8799 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8800 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8801 else
8802 return ToTIOrErr.takeError();
8803 }
8804
8805 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8806 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8807 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8808}
8809
8812 Error Err = Error::success();
8813 auto ToType = importChecked(Err, E->getType());
8814 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8815 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8816 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8817 auto ToFirstQualifierFoundInScope =
8819 if (Err)
8820 return std::move(Err);
8821
8822 Expr *ToBase = nullptr;
8823 if (!E->isImplicitAccess()) {
8824 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8825 ToBase = *ToBaseOrErr;
8826 else
8827 return ToBaseOrErr.takeError();
8828 }
8829
8830 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8831
8832 if (E->hasExplicitTemplateArgs()) {
8833 if (Error Err =
8835 E->template_arguments(), ToTAInfo))
8836 return std::move(Err);
8837 ResInfo = &ToTAInfo;
8838 }
8839 auto ToMember = importChecked(Err, E->getMember());
8840 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8841 if (Err)
8842 return std::move(Err);
8843 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8844
8845 // Import additional name location/type info.
8846 if (Error Err =
8847 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8848 return std::move(Err);
8849
8851 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8852 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8853 ToMemberNameInfo, ResInfo);
8854}
8855
8858 Error Err = Error::success();
8859 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8860 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8861 auto ToDeclName = importChecked(Err, E->getDeclName());
8862 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8863 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8864 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8865 if (Err)
8866 return std::move(Err);
8867
8868 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8869 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8870 return std::move(Err);
8871
8872 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8873 TemplateArgumentListInfo *ResInfo = nullptr;
8874 if (E->hasExplicitTemplateArgs()) {
8875 if (Error Err =
8877 return std::move(Err);
8878 ResInfo = &ToTAInfo;
8879 }
8880
8882 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8883 ToNameInfo, ResInfo);
8884}
8885
8888 Error Err = Error::success();
8889 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8890 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8891 auto ToType = importChecked(Err, E->getType());
8892 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8893 if (Err)
8894 return std::move(Err);
8895
8897 if (Error Err =
8898 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8899 return std::move(Err);
8900
8902 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8903 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8904}
8905
8908 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8909 if (!ToNamingClassOrErr)
8910 return ToNamingClassOrErr.takeError();
8911
8912 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8913 if (!ToQualifierLocOrErr)
8914 return ToQualifierLocOrErr.takeError();
8915
8916 Error Err = Error::success();
8917 auto ToName = importChecked(Err, E->getName());
8918 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8919 if (Err)
8920 return std::move(Err);
8921 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8922
8923 // Import additional name location/type info.
8924 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8925 return std::move(Err);
8926
8927 UnresolvedSet<8> ToDecls;
8928 for (auto *D : E->decls())
8929 if (auto ToDOrErr = import(D))
8930 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8931 else
8932 return ToDOrErr.takeError();
8933
8934 if (E->hasExplicitTemplateArgs()) {
8935 TemplateArgumentListInfo ToTAInfo;
8938 ToTAInfo))
8939 return std::move(Err);
8940
8941 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8942 if (!ToTemplateKeywordLocOrErr)
8943 return ToTemplateKeywordLocOrErr.takeError();
8944
8945 const bool KnownDependent =
8946 (E->getDependence() & ExprDependence::TypeValue) ==
8947 ExprDependence::TypeValue;
8949 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8950 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8951 ToDecls.begin(), ToDecls.end(), KnownDependent,
8952 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8953 }
8954
8956 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8957 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8958 /*KnownDependent=*/E->isTypeDependent(),
8959 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8960}
8961
8964 Error Err = Error::success();
8965 auto ToType = importChecked(Err, E->getType());
8966 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8967 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8968 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8969 auto ToName = importChecked(Err, E->getName());
8970 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8971 if (Err)
8972 return std::move(Err);
8973
8974 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8975 // Import additional name location/type info.
8976 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8977 return std::move(Err);
8978
8979 UnresolvedSet<8> ToDecls;
8980 for (Decl *D : E->decls())
8981 if (auto ToDOrErr = import(D))
8982 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8983 else
8984 return ToDOrErr.takeError();
8985
8986 TemplateArgumentListInfo ToTAInfo;
8987 TemplateArgumentListInfo *ResInfo = nullptr;
8988 if (E->hasExplicitTemplateArgs()) {
8989 TemplateArgumentListInfo FromTAInfo;
8990 E->copyTemplateArgumentsInto(FromTAInfo);
8991 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8992 return std::move(Err);
8993 ResInfo = &ToTAInfo;
8994 }
8995
8996 Expr *ToBase = nullptr;
8997 if (!E->isImplicitAccess()) {
8998 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8999 ToBase = *ToBaseOrErr;
9000 else
9001 return ToBaseOrErr.takeError();
9002 }
9003
9005 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
9006 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
9007 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
9008}
9009
9011 Error Err = Error::success();
9012 auto ToCallee = importChecked(Err, E->getCallee());
9013 auto ToType = importChecked(Err, E->getType());
9014 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9015 if (Err)
9016 return std::move(Err);
9017
9018 unsigned NumArgs = E->getNumArgs();
9019 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
9020 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
9021 return std::move(Err);
9022
9023 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
9025 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
9026 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
9027 OCE->getADLCallKind());
9028 }
9029
9030 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
9031 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
9032 /*MinNumArgs=*/0, E->getADLCallKind());
9033}
9034
9036 CXXRecordDecl *FromClass = E->getLambdaClass();
9037 auto ToClassOrErr = import(FromClass);
9038 if (!ToClassOrErr)
9039 return ToClassOrErr.takeError();
9040 CXXRecordDecl *ToClass = *ToClassOrErr;
9041
9042 auto ToCallOpOrErr = import(E->getCallOperator());
9043 if (!ToCallOpOrErr)
9044 return ToCallOpOrErr.takeError();
9045
9046 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
9047 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
9048 return std::move(Err);
9049
9050 Error Err = Error::success();
9051 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
9052 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
9053 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9054 if (Err)
9055 return std::move(Err);
9056
9057 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
9058 E->getCaptureDefault(), ToCaptureDefaultLoc,
9060 E->hasExplicitResultType(), ToCaptureInits,
9061 ToEndLoc, E->containsUnexpandedParameterPack());
9062}
9063
9064
9066 Error Err = Error::success();
9067 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9068 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9069 auto ToType = importChecked(Err, E->getType());
9070 if (Err)
9071 return std::move(Err);
9072
9073 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9074 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9075 return std::move(Err);
9076
9077 ASTContext &ToCtx = Importer.getToContext();
9078 InitListExpr *To = new (ToCtx)
9079 InitListExpr(ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc, E->isExplicit());
9080 To->setType(ToType);
9081
9082 if (E->hasArrayFiller()) {
9083 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9084 To->setArrayFiller(*ToFillerOrErr);
9085 else
9086 return ToFillerOrErr.takeError();
9087 }
9088
9089 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9090 if (auto ToFDOrErr = import(FromFD))
9091 To->setInitializedFieldInUnion(*ToFDOrErr);
9092 else
9093 return ToFDOrErr.takeError();
9094 }
9095
9096 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9097 if (auto ToSyntFormOrErr = import(SyntForm))
9098 To->setSyntacticForm(*ToSyntFormOrErr);
9099 else
9100 return ToSyntFormOrErr.takeError();
9101 }
9102
9103 // Copy InitListExprBitfields, which are not handled in the ctor of
9104 // InitListExpr.
9106
9107 return To;
9108}
9109
9112 ExpectedType ToTypeOrErr = import(E->getType());
9113 if (!ToTypeOrErr)
9114 return ToTypeOrErr.takeError();
9115
9116 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9117 if (!ToSubExprOrErr)
9118 return ToSubExprOrErr.takeError();
9119
9120 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9121 *ToTypeOrErr, *ToSubExprOrErr);
9122}
9123
9126 Error Err = Error::success();
9127 auto ToLocation = importChecked(Err, E->getLocation());
9128 auto ToType = importChecked(Err, E->getType());
9129 auto ToConstructor = importChecked(Err, E->getConstructor());
9130 if (Err)
9131 return std::move(Err);
9132
9133 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9134 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9135 E->inheritedFromVBase());
9136}
9137
9139 Error Err = Error::success();
9140 auto ToType = importChecked(Err, E->getType());
9141 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9142 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9143 if (Err)
9144 return std::move(Err);
9145
9146 return new (Importer.getToContext()) ArrayInitLoopExpr(
9147 ToType, ToCommonExpr, ToSubExpr);
9148}
9149
9151 ExpectedType ToTypeOrErr = import(E->getType());
9152 if (!ToTypeOrErr)
9153 return ToTypeOrErr.takeError();
9154 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9155}
9156
9158 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9159 if (!ToBeginLocOrErr)
9160 return ToBeginLocOrErr.takeError();
9161
9162 auto ToFieldOrErr = import(E->getField());
9163 if (!ToFieldOrErr)
9164 return ToFieldOrErr.takeError();
9165
9166 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9167 if (!UsedContextOrErr)
9168 return UsedContextOrErr.takeError();
9169
9170 FieldDecl *ToField = *ToFieldOrErr;
9171 assert(ToField->hasInClassInitializer() &&
9172 "Field should have in-class initializer if there is a default init "
9173 "expression that uses it.");
9174 if (!ToField->getInClassInitializer()) {
9175 // The in-class initializer may be not yet set in "To" AST even if the
9176 // field is already there. This must be set here to make construction of
9177 // CXXDefaultInitExpr work.
9178 auto ToInClassInitializerOrErr =
9179 import(E->getField()->getInClassInitializer());
9180 if (!ToInClassInitializerOrErr)
9181 return ToInClassInitializerOrErr.takeError();
9182 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9183 }
9184
9185 Expr *RewrittenInit = nullptr;
9186 if (E->hasRewrittenInit()) {
9187 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9188 if (!ExprOrErr)
9189 return ExprOrErr.takeError();
9190 RewrittenInit = ExprOrErr.get();
9191 }
9192
9193 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9194 ToField, *UsedContextOrErr, RewrittenInit);
9195}
9196
9198 Error Err = Error::success();
9199 auto ToType = importChecked(Err, E->getType());
9200 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9201 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9202 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9203 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9204 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9205 if (Err)
9206 return std::move(Err);
9207
9209 CastKind CK = E->getCastKind();
9210 auto ToBasePathOrErr = ImportCastPath(E);
9211 if (!ToBasePathOrErr)
9212 return ToBasePathOrErr.takeError();
9213
9214 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9216 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9217 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9218 ToAngleBrackets);
9219 } else if (isa<CXXDynamicCastExpr>(E)) {
9221 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9222 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9223 } else if (isa<CXXReinterpretCastExpr>(E)) {
9225 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9226 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9227 } else if (isa<CXXConstCastExpr>(E)) {
9229 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9230 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9231 } else {
9232 llvm_unreachable("Unknown cast type");
9233 return make_error<ASTImportError>();
9234 }
9235}
9236
9239 Error Err = Error::success();
9240 auto ToType = importChecked(Err, E->getType());
9241 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9242 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9243 auto ToParamType = importChecked(Err, E->getParameterType());
9244 auto ToReplacement = importChecked(Err, E->getReplacement());
9245 if (Err)
9246 return std::move(Err);
9247
9248 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9249 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9250 ToParamType, E->getIndex(), E->getPackIndex(), E->getFinal());
9251}
9252
9254 Error Err = Error::success();
9255 auto ToType = importChecked(Err, E->getType());
9256 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9257 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9258 if (Err)
9259 return std::move(Err);
9260
9262 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9263 return std::move(Err);
9264
9265 if (E->isStoredAsBoolean()) {
9266 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9267 // Value is always false.
9268 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9269 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9270 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9271 }
9272 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9273 E->getTrait(), ToArgs, ToEndLoc,
9274 E->getAPValue());
9275}
9276
9278 ExpectedType ToTypeOrErr = import(E->getType());
9279 if (!ToTypeOrErr)
9280 return ToTypeOrErr.takeError();
9281
9282 auto ToSourceRangeOrErr = import(E->getSourceRange());
9283 if (!ToSourceRangeOrErr)
9284 return ToSourceRangeOrErr.takeError();
9285
9286 if (E->isTypeOperand()) {
9287 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9288 return new (Importer.getToContext()) CXXTypeidExpr(
9289 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9290 else
9291 return ToTSIOrErr.takeError();
9292 }
9293
9294 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9295 if (!ToExprOperandOrErr)
9296 return ToExprOperandOrErr.takeError();
9297
9298 return new (Importer.getToContext()) CXXTypeidExpr(
9299 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9300}
9301
9303 Error Err = Error::success();
9304
9305 QualType ToType = importChecked(Err, E->getType());
9306 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9307 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9308 Expr *ToLHS = importChecked(Err, E->getLHS());
9309 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9310 Expr *ToRHS = importChecked(Err, E->getRHS());
9311 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9312
9313 if (Err)
9314 return std::move(Err);
9315
9316 return new (Importer.getToContext())
9317 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9318 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9319}
9320
9322 Error Err = Error::success();
9323 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9324 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9325 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9326
9327 auto Body = importChecked(Err, E->getBody());
9328 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9329 if (Err)
9330 return std::move(Err);
9331 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9332 if (Error Err =
9333 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9334 return std::move(Err);
9336 E->getRequirements().size());
9337 if (Error Err =
9338 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9339 return std::move(Err);
9340 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9341 LParenLoc, LocalParameters, RParenLoc,
9342 Requirements, RBraceLoc);
9343}
9344
9347 Error Err = Error::success();
9348 auto CL = importChecked(Err, E->getConceptReference());
9349 auto CSD = importChecked(Err, E->getSpecializationDecl());
9350 if (Err)
9351 return std::move(Err);
9352 if (E->isValueDependent())
9354 Importer.getToContext(), CL,
9355 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9356 ConstraintSatisfaction Satisfaction;
9357 if (Error Err =
9359 return std::move(Err);
9361 Importer.getToContext(), CL,
9362 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9363}
9364
9367 Error Err = Error::success();
9368 auto ToType = importChecked(Err, E->getType());
9369 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9370 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9371 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9372 if (Err)
9373 return std::move(Err);
9374
9375 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9376 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9377 E->getIndex(), E->getFinal());
9378}
9379
9382 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9383 return std::move(Err);
9384 auto ToSyntOrErr = import(E->getSyntacticForm());
9385 if (!ToSyntOrErr)
9386 return ToSyntOrErr.takeError();
9387 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9388 ToSemantics, E->getResultExprIndex());
9389}
9390
9393 Error Err = Error::success();
9394 auto ToType = importChecked(Err, E->getType());
9395 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9396 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9397 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9398 if (Err)
9399 return std::move(Err);
9400
9401 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9402 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9403 return std::move(Err);
9404 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9405 E->getUserSpecifiedInitExprs().size(),
9406 ToInitLoc, ToBeginLoc, ToEndLoc);
9407}
9408
9410 CXXMethodDecl *FromMethod) {
9411 Error ImportErrors = Error::success();
9412 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9413 if (auto ImportedOrErr = import(FromOverriddenMethod))
9415 (*ImportedOrErr)->getCanonicalDecl()));
9416 else
9417 ImportErrors =
9418 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9419 }
9420 return ImportErrors;
9421}
9422
9424 ASTContext &FromContext, FileManager &FromFileManager,
9425 bool MinimalImport,
9426 std::shared_ptr<ASTImporterSharedState> SharedState)
9427 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9428 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9429 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9430
9431 // Create a default state without the lookup table: LLDB case.
9432 if (!SharedState) {
9433 this->SharedState = std::make_shared<ASTImporterSharedState>();
9434 }
9435
9436 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9437 ToContext.getTranslationUnitDecl();
9438}
9439
9440ASTImporter::~ASTImporter() = default;
9441
9443 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9444 "Try to get field index for non-field.");
9445
9446 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9447 if (!Owner)
9448 return std::nullopt;
9449
9450 unsigned Index = 0;
9451 for (const auto *D : Owner->decls()) {
9452 if (D == F)
9453 return Index;
9454
9456 ++Index;
9457 }
9458
9459 llvm_unreachable("Field was not found in its parent context.");
9460
9461 return std::nullopt;
9462}
9463
9464ASTImporter::FoundDeclsTy
9465ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9466 // We search in the redecl context because of transparent contexts.
9467 // E.g. a simple C language enum is a transparent context:
9468 // enum E { A, B };
9469 // Now if we had a global variable in the TU
9470 // int A;
9471 // then the enum constant 'A' and the variable 'A' violates ODR.
9472 // We can diagnose this only if we search in the redecl context.
9473 DeclContext *ReDC = DC->getRedeclContext();
9474 if (SharedState->getLookupTable()) {
9475 if (ReDC->isNamespace()) {
9476 // Namespaces can be reopened.
9477 // Lookup table does not handle this, we must search here in all linked
9478 // namespaces.
9479 FoundDeclsTy Result;
9480 SmallVector<Decl *, 2> NSChain =
9482 dyn_cast<NamespaceDecl>(ReDC));
9483 for (auto *D : NSChain) {
9485 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9486 Name);
9488 }
9489 return Result;
9490 } else {
9492 SharedState->getLookupTable()->lookup(ReDC, Name);
9493 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9494 }
9495 } else {
9496 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9497 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9498 // We must search by the slow case of localUncachedLookup because that is
9499 // working even if there is no LookupPtr for the DC. We could use
9500 // DC::buildLookup() to create the LookupPtr, but that would load external
9501 // decls again, we must avoid that case.
9502 // Also, even if we had the LookupPtr, we must find Decls which are not
9503 // in the LookupPtr, so we need the slow case.
9504 // These cases are handled in ASTImporterLookupTable, but we cannot use
9505 // that with LLDB since that traverses through the AST which initiates the
9506 // load of external decls again via DC::decls(). And again, we must avoid
9507 // loading external decls during the import.
9508 if (Result.empty())
9509 ReDC->localUncachedLookup(Name, Result);
9510 return Result;
9511 }
9512}
9513
9514void ASTImporter::AddToLookupTable(Decl *ToD) {
9515 SharedState->addDeclToLookup(ToD);
9516}
9517
9519 // Import the decl using ASTNodeImporter.
9520 ASTNodeImporter Importer(*this);
9521 return Importer.Visit(FromD);
9522}
9523
9525 MapImported(FromD, ToD);
9526}
9527
9530 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9531 if (Expected<Expr *> R = Import(CLE))
9533 }
9534
9535 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9536 // ASTNodeImporter.
9537 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9538}
9539
9541 if (!FromT)
9542 return FromT;
9543
9544 // Check whether we've already imported this type.
9545 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9546 ImportedTypes.find(FromT);
9547 if (Pos != ImportedTypes.end())
9548 return Pos->second;
9549
9550 // Import the type.
9551 ASTNodeImporter Importer(*this);
9552 ExpectedType ToTOrErr = Importer.Visit(FromT);
9553 if (!ToTOrErr)
9554 return ToTOrErr.takeError();
9555
9556 // Record the imported type.
9557 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9558
9559 return ToTOrErr->getTypePtr();
9560}
9561
9563 if (FromT.isNull())
9564 return QualType{};
9565
9566 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9567 if (!ToTyOrErr)
9568 return ToTyOrErr.takeError();
9569
9570 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9571}
9572
9574 if (!FromTSI)
9575 return FromTSI;
9576
9577 // FIXME: For now we just create a "trivial" type source info based
9578 // on the type and a single location. Implement a real version of this.
9579 ExpectedType TOrErr = Import(FromTSI->getType());
9580 if (!TOrErr)
9581 return TOrErr.takeError();
9582 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9583 if (!BeginLocOrErr)
9584 return BeginLocOrErr.takeError();
9585
9586 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9587}
9588
9589namespace {
9590// To use this object, it should be created before the new attribute is created,
9591// and destructed after it is created. The construction already performs the
9592// import of the data.
9593template <typename T> struct AttrArgImporter {
9594 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9595 AttrArgImporter(AttrArgImporter<T> &&) = default;
9596 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9597 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9598
9599 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9600 : To(I.importChecked(Err, From)) {}
9601
9602 const T &value() { return To; }
9603
9604private:
9605 T To;
9606};
9607
9608// To use this object, it should be created before the new attribute is created,
9609// and destructed after it is created. The construction already performs the
9610// import of the data. The array data is accessible in a pointer form, this form
9611// is used by the attribute classes. This object should be created once for the
9612// array data to be imported (the array size is not imported, just copied).
9613template <typename T> struct AttrArgArrayImporter {
9614 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9615 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9616 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9617 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9618
9619 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9620 const llvm::iterator_range<T *> &From,
9621 unsigned ArraySize) {
9622 if (Err)
9623 return;
9624 To.reserve(ArraySize);
9625 Err = I.ImportContainerChecked(From, To);
9626 }
9627
9628 T *value() { return To.data(); }
9629
9630private:
9631 llvm::SmallVector<T, 2> To;
9632};
9633
9634class AttrImporter {
9635 Error Err{Error::success()};
9636 Attr *ToAttr = nullptr;
9637 ASTImporter &Importer;
9638 ASTNodeImporter NImporter;
9639
9640public:
9641 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9642
9643 // Create an "importer" for an attribute parameter.
9644 // Result of the 'value()' of that object is to be passed to the function
9645 // 'importAttr', in the order that is expected by the attribute class.
9646 template <class T> AttrArgImporter<T> importArg(const T &From) {
9647 return AttrArgImporter<T>(NImporter, Err, From);
9648 }
9649
9650 // Create an "importer" for an attribute parameter that has array type.
9651 // Result of the 'value()' of that object is to be passed to the function
9652 // 'importAttr', then the size of the array as next argument.
9653 template <typename T>
9654 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9655 unsigned ArraySize) {
9656 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9657 }
9658
9659 // Create an attribute object with the specified arguments.
9660 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9661 // should be values that are passed to the 'Create' function of the attribute.
9662 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9663 // used here.) As much data is copied or imported from the old attribute
9664 // as possible. The passed arguments should be already imported.
9665 // If an import error happens, the internal error is set to it, and any
9666 // further import attempt is ignored.
9667 template <typename T, typename... Arg>
9668 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9669 static_assert(std::is_base_of<Attr, T>::value,
9670 "T should be subclass of Attr.");
9671 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9672
9673 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9674 const IdentifierInfo *ToScopeName =
9675 Importer.Import(FromAttr->getScopeName());
9676 SourceRange ToAttrRange =
9677 NImporter.importChecked(Err, FromAttr->getRange());
9678 SourceLocation ToScopeLoc =
9679 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9680
9681 if (Err)
9682 return;
9683
9684 AttributeCommonInfo ToI(
9685 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9686 FromAttr->getParsedKind(), FromAttr->getForm());
9687 // The "SemanticSpelling" is not needed to be passed to the constructor.
9688 // That value is recalculated from the SpellingListIndex if needed.
9689 ToAttr = T::Create(Importer.getToContext(),
9690 std::forward<Arg>(ImportedArg)..., ToI);
9691
9692 ToAttr->setImplicit(FromAttr->isImplicit());
9693 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9694 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9695 ToInheritableAttr->setInherited(FromAttr->isInherited());
9696 }
9697
9698 // Create a clone of the 'FromAttr' and import its source range only.
9699 // This causes objects with invalid references to be created if the 'FromAttr'
9700 // contains other data that should be imported.
9701 void cloneAttr(const Attr *FromAttr) {
9702 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9703
9704 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9705 if (Err)
9706 return;
9707
9708 ToAttr = FromAttr->clone(Importer.getToContext());
9709 ToAttr->setRange(ToRange);
9710 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9711 }
9712
9713 // Get the result of the previous import attempt (can be used only once).
9714 llvm::Expected<Attr *> getResult() && {
9715 if (Err)
9716 return std::move(Err);
9717 assert(ToAttr && "Attribute should be created.");
9718 return ToAttr;
9719 }
9720};
9721} // namespace
9722
9724 AttrImporter AI(*this);
9725
9726 // FIXME: Is there some kind of AttrVisitor to use here?
9727 switch (FromAttr->getKind()) {
9728 case attr::Aligned: {
9729 auto *From = cast<AlignedAttr>(FromAttr);
9730 if (From->isAlignmentExpr())
9731 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9732 else
9733 AI.importAttr(From, false,
9734 AI.importArg(From->getAlignmentType()).value());
9735 break;
9736 }
9737
9738 case attr::AlignValue: {
9739 auto *From = cast<AlignValueAttr>(FromAttr);
9740 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9741 break;
9742 }
9743
9744 case attr::Format: {
9745 const auto *From = cast<FormatAttr>(FromAttr);
9746 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9747 From->getFirstArg());
9748 break;
9749 }
9750
9751 case attr::EnableIf: {
9752 const auto *From = cast<EnableIfAttr>(FromAttr);
9753 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9754 From->getMessage());
9755 break;
9756 }
9757
9758 case attr::AssertCapability: {
9759 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9760 AI.importAttr(From,
9761 AI.importArrayArg(From->args(), From->args_size()).value(),
9762 From->args_size());
9763 break;
9764 }
9765 case attr::AcquireCapability: {
9766 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9767 AI.importAttr(From,
9768 AI.importArrayArg(From->args(), From->args_size()).value(),
9769 From->args_size());
9770 break;
9771 }
9772 case attr::TryAcquireCapability: {
9773 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9774 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9775 AI.importArrayArg(From->args(), From->args_size()).value(),
9776 From->args_size());
9777 break;
9778 }
9779 case attr::ReleaseCapability: {
9780 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9781 AI.importAttr(From,
9782 AI.importArrayArg(From->args(), From->args_size()).value(),
9783 From->args_size());
9784 break;
9785 }
9786 case attr::RequiresCapability: {
9787 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9788 AI.importAttr(From,
9789 AI.importArrayArg(From->args(), From->args_size()).value(),
9790 From->args_size());
9791 break;
9792 }
9793 case attr::GuardedBy: {
9794 const auto *From = cast<GuardedByAttr>(FromAttr);
9795 AI.importAttr(From,
9796 AI.importArrayArg(From->args(), From->args_size()).value(),
9797 From->args_size());
9798 break;
9799 }
9800 case attr::PtGuardedBy: {
9801 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9802 AI.importAttr(From,
9803 AI.importArrayArg(From->args(), From->args_size()).value(),
9804 From->args_size());
9805 break;
9806 }
9807 case attr::AcquiredAfter: {
9808 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9809 AI.importAttr(From,
9810 AI.importArrayArg(From->args(), From->args_size()).value(),
9811 From->args_size());
9812 break;
9813 }
9814 case attr::AcquiredBefore: {
9815 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9816 AI.importAttr(From,
9817 AI.importArrayArg(From->args(), From->args_size()).value(),
9818 From->args_size());
9819 break;
9820 }
9821 case attr::LockReturned: {
9822 const auto *From = cast<LockReturnedAttr>(FromAttr);
9823 AI.importAttr(From, AI.importArg(From->getArg()).value());
9824 break;
9825 }
9826 case attr::LocksExcluded: {
9827 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9828 AI.importAttr(From,
9829 AI.importArrayArg(From->args(), From->args_size()).value(),
9830 From->args_size());
9831 break;
9832 }
9833 default: {
9834 // The default branch works for attributes that have no arguments to import.
9835 // FIXME: Handle every attribute type that has arguments of type to import
9836 // (most often Expr* or Decl* or type) in the switch above.
9837 AI.cloneAttr(FromAttr);
9838 break;
9839 }
9840 }
9841
9842 return std::move(AI).getResult();
9843}
9844
9846 return ImportedDecls.lookup(FromD);
9847}
9848
9850 auto FromDPos = ImportedFromDecls.find(ToD);
9851 if (FromDPos == ImportedFromDecls.end())
9852 return nullptr;
9853 return FromDPos->second->getTranslationUnitDecl();
9854}
9855
9857 if (!FromD)
9858 return nullptr;
9859
9860 // Push FromD to the stack, and remove that when we return.
9861 ImportPath.push(FromD);
9862 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9863
9864 // Check whether there was a previous failed import.
9865 // If yes return the existing error.
9866 if (auto Error = getImportDeclErrorIfAny(FromD))
9867 return make_error<ASTImportError>(*Error);
9868
9869 // Check whether we've already imported this declaration.
9870 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9871 if (ToD) {
9872 // Already imported (possibly from another TU) and with an error.
9873 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9874 setImportDeclError(FromD, *Error);
9875 return make_error<ASTImportError>(*Error);
9876 }
9877
9878 // If FromD has some updated flags after last import, apply it.
9879 updateFlags(FromD, ToD);
9880 // If we encounter a cycle during an import then we save the relevant part
9881 // of the import path associated to the Decl.
9882 if (ImportPath.hasCycleAtBack())
9883 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9884 return ToD;
9885 }
9886
9887 // Import the declaration.
9888 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9889 if (!ToDOrErr) {
9890 // Failed to import.
9891
9892 auto Pos = ImportedDecls.find(FromD);
9893 bool ToDWasCreated = Pos != ImportedDecls.end();
9894 // Capture the mapped decl before erasing: the iterator is invalidated by
9895 // the erase below under backward-shift deletion, but it is still needed
9896 // further down to record the import error.
9897 Decl *CreatedToD = ToDWasCreated ? Pos->second : nullptr;
9898 if (ToDWasCreated) {
9899 // Import failed after the object was created.
9900 // Remove all references to it.
9901 auto *ToD = CreatedToD;
9902 ImportedDecls.erase(Pos);
9903
9904 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9905 // (e.g. with namespaces) that several decls from the 'from' context are
9906 // mapped to the same decl in the 'to' context. If we removed entries
9907 // from the LookupTable here then we may end up removing them multiple
9908 // times.
9909
9910 // The Lookuptable contains decls only which are in the 'to' context.
9911 // Remove from the Lookuptable only if it is *imported* into the 'to'
9912 // context (and do not remove it if it was added during the initial
9913 // traverse of the 'to' context).
9914 auto PosF = ImportedFromDecls.find(ToD);
9915 if (PosF != ImportedFromDecls.end()) {
9916 // In the case of TypedefNameDecl we create the Decl first and only
9917 // then we import and set its DeclContext. So, the DC might not be set
9918 // when we reach here.
9919 if (ToD->getDeclContext())
9920 SharedState->removeDeclFromLookup(ToD);
9921 ImportedFromDecls.erase(PosF);
9922 }
9923
9924 // FIXME: AST may contain remaining references to the failed object.
9925 // However, the ImportDeclErrors in the shared state contains all the
9926 // failed objects together with their error.
9927 }
9928
9929 // Error encountered for the first time.
9930 // After takeError the error is not usable any more in ToDOrErr.
9931 // Get a copy of the error object (any more simple solution for this?).
9932 ASTImportError ErrOut;
9933 handleAllErrors(ToDOrErr.takeError(),
9934 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9935 setImportDeclError(FromD, ErrOut);
9936 // Set the error for the mapped to Decl, which is in the "to" context.
9937 if (ToDWasCreated)
9938 SharedState->setImportDeclError(CreatedToD, ErrOut);
9939
9940 // Set the error for all nodes which have been created before we
9941 // recognized the error.
9942 for (const auto &Path : SavedImportPaths[FromD]) {
9943 // The import path contains import-dependency nodes first.
9944 // Save the node that was imported as dependency of the current node.
9945 Decl *PrevFromDi = FromD;
9946 for (Decl *FromDi : Path) {
9947 // Begin and end of the path equals 'FromD', skip it.
9948 if (FromDi == FromD)
9949 continue;
9950 // We should not set import error on a node and all following nodes in
9951 // the path if child import errors are ignored.
9952 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9953 PrevFromDi))
9954 break;
9955 PrevFromDi = FromDi;
9956 setImportDeclError(FromDi, ErrOut);
9957 //FIXME Should we remove these Decls from ImportedDecls?
9958 // Set the error for the mapped to Decl, which is in the "to" context.
9959 auto Ii = ImportedDecls.find(FromDi);
9960 if (Ii != ImportedDecls.end())
9961 SharedState->setImportDeclError(Ii->second, ErrOut);
9962 // FIXME Should we remove these Decls from the LookupTable,
9963 // and from ImportedFromDecls?
9964 }
9965 }
9966 SavedImportPaths.erase(FromD);
9967
9968 // Do not return ToDOrErr, error was taken out of it.
9969 return make_error<ASTImportError>(ErrOut);
9970 }
9971
9972 ToD = *ToDOrErr;
9973
9974 // FIXME: Handle the "already imported with error" case. We can get here
9975 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9976 // previously failed create was requested).
9977 // Later GetImportedOrCreateDecl can be updated to return the error.
9978 if (!ToD) {
9979 auto Err = getImportDeclErrorIfAny(FromD);
9980 assert(Err);
9981 return make_error<ASTImportError>(*Err);
9982 }
9983
9984 // We could import from the current TU without error. But previously we
9985 // already had imported a Decl as `ToD` from another TU (with another
9986 // ASTImporter object) and with an error.
9987 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9988 setImportDeclError(FromD, *Error);
9989 return make_error<ASTImportError>(*Error);
9990 }
9991 // Make sure that ImportImpl registered the imported decl.
9992 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9993
9994 if (FromD->hasAttrs())
9995 for (const Attr *FromAttr : FromD->getAttrs()) {
9996 auto ToAttrOrErr = Import(FromAttr);
9997 if (ToAttrOrErr)
9998 ToD->addAttr(*ToAttrOrErr);
9999 else
10000 return ToAttrOrErr.takeError();
10001 }
10002
10003 // Notify subclasses.
10004 Imported(FromD, ToD);
10005
10006 updateFlags(FromD, ToD);
10007 SavedImportPaths.erase(FromD);
10008 return ToDOrErr;
10009}
10010
10013 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
10014}
10015
10017 if (!FromDC)
10018 return FromDC;
10019
10020 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
10021 if (!ToDCOrErr)
10022 return ToDCOrErr.takeError();
10023 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
10024
10025 // When we're using a record/enum/Objective-C class/protocol as a context, we
10026 // need it to have a definition.
10027 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
10028 auto *FromRecord = cast<RecordDecl>(FromDC);
10029 if (ToRecord->isCompleteDefinition())
10030 return ToDC;
10031
10032 // If FromRecord is not defined we need to force it to be.
10033 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
10034 // it will start the definition but we never finish it.
10035 // If there are base classes they won't be imported and we will
10036 // be missing anything that we inherit from those bases.
10037 if (FromRecord->getASTContext().getExternalSource() &&
10038 !FromRecord->isCompleteDefinition())
10039 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
10040
10041 if (FromRecord->isCompleteDefinition())
10042 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10043 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
10044 return std::move(Err);
10045 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
10046 auto *FromEnum = cast<EnumDecl>(FromDC);
10047 if (ToEnum->isCompleteDefinition()) {
10048 // Do nothing.
10049 } else if (FromEnum->isCompleteDefinition()) {
10050 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10051 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
10052 return std::move(Err);
10053 } else {
10054 CompleteDecl(ToEnum);
10055 }
10056 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
10057 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
10058 if (ToClass->getDefinition()) {
10059 // Do nothing.
10060 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
10061 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10062 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10063 return std::move(Err);
10064 } else {
10065 CompleteDecl(ToClass);
10066 }
10067 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10068 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10069 if (ToProto->getDefinition()) {
10070 // Do nothing.
10071 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10072 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10073 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10074 return std::move(Err);
10075 } else {
10076 CompleteDecl(ToProto);
10077 }
10078 }
10079
10080 return ToDC;
10081}
10082
10084 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10085 return cast_or_null<Expr>(*ToSOrErr);
10086 else
10087 return ToSOrErr.takeError();
10088}
10089
10091 if (!FromS)
10092 return nullptr;
10093
10094 // Check whether we've already imported this statement.
10095 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10096 if (Pos != ImportedStmts.end())
10097 return Pos->second;
10098
10099 // Import the statement.
10100 ASTNodeImporter Importer(*this);
10101 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10102 if (!ToSOrErr)
10103 return ToSOrErr;
10104
10105 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10106 auto *FromE = cast<Expr>(FromS);
10107 // Copy ExprBitfields, which may not be handled in Expr subclasses
10108 // constructors.
10109 ToE->setValueKind(FromE->getValueKind());
10110 ToE->setObjectKind(FromE->getObjectKind());
10111 ToE->setDependence(FromE->getDependence());
10112 }
10113
10114 // Record the imported statement object.
10115 ImportedStmts[FromS] = *ToSOrErr;
10116 return ToSOrErr;
10117}
10118
10120 switch (FromNNS.getKind()) {
10123 return FromNNS;
10125 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10126 auto NSOrErr = Import(Namespace);
10127 if (!NSOrErr)
10128 return NSOrErr.takeError();
10129 auto PrefixOrErr = Import(Prefix);
10130 if (!PrefixOrErr)
10131 return PrefixOrErr.takeError();
10132 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10133 *PrefixOrErr);
10134 }
10136 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10137 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10138 else
10139 return RDOrErr.takeError();
10141 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10142 return NestedNameSpecifier(*TyOrErr);
10143 } else {
10144 return TyOrErr.takeError();
10145 }
10146 }
10147 llvm_unreachable("Invalid nested name specifier kind");
10148}
10149
10152 // Copied from NestedNameSpecifier mostly.
10154 NestedNameSpecifierLoc NNS = FromNNS;
10155
10156 // Push each of the nested-name-specifiers's onto a stack for
10157 // serialization in reverse order.
10158 while (NNS) {
10159 NestedNames.push_back(NNS);
10160 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10161 }
10162
10164
10165 while (!NestedNames.empty()) {
10166 NNS = NestedNames.pop_back_val();
10167 NestedNameSpecifier Spec = std::nullopt;
10168 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10169 return std::move(Err);
10170
10171 NestedNameSpecifier::Kind Kind = Spec.getKind();
10172
10173 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10175 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10176 return std::move(Err);
10177
10179 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10180 return std::move(Err);
10181 }
10182
10183 switch (Kind) {
10185 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10186 ToLocalBeginLoc, ToLocalEndLoc);
10187 break;
10188
10190 SourceLocation ToTLoc;
10191 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10192 return std::move(Err);
10194 QualType(Spec.getAsType(), 0), ToTLoc);
10195 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10196 break;
10197 }
10198
10200 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10201 break;
10202
10204 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10205 if (!ToSourceRangeOrErr)
10206 return ToSourceRangeOrErr.takeError();
10207
10208 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10209 ToSourceRangeOrErr->getBegin(),
10210 ToSourceRangeOrErr->getEnd());
10211 break;
10212 }
10214 llvm_unreachable("unexpected null nested name specifier");
10215 }
10216 }
10217
10218 return Builder.getWithLocInContext(getToContext());
10219}
10220
10222 switch (From.getKind()) {
10224 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10225 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10226 else
10227 return ToTemplateOrErr.takeError();
10228
10231 UnresolvedSet<2> ToTemplates;
10232 for (auto *I : *FromStorage) {
10233 if (auto ToOrErr = Import(I))
10234 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10235 else
10236 return ToOrErr.takeError();
10237 }
10238 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10239 ToTemplates.end());
10240 }
10241
10244 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10245 if (!DeclNameOrErr)
10246 return DeclNameOrErr.takeError();
10247 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10248 }
10249
10252 auto QualifierOrErr = Import(QTN->getQualifier());
10253 if (!QualifierOrErr)
10254 return QualifierOrErr.takeError();
10255 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10256 if (!TNOrErr)
10257 return TNOrErr.takeError();
10258 return ToContext.getQualifiedTemplateName(
10259 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10260 }
10261
10264 auto QualifierOrErr = Import(DTN->getQualifier());
10265 if (!QualifierOrErr)
10266 return QualifierOrErr.takeError();
10267 return ToContext.getDependentTemplateName(
10268 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10269 }
10270
10274 auto ReplacementOrErr = Import(Subst->getReplacement());
10275 if (!ReplacementOrErr)
10276 return ReplacementOrErr.takeError();
10277
10278 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10279 if (!AssociatedDeclOrErr)
10280 return AssociatedDeclOrErr.takeError();
10281
10282 return ToContext.getSubstTemplateTemplateParm(
10283 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10284 Subst->getPackIndex(), Subst->getFinal());
10285 }
10286
10290 ASTNodeImporter Importer(*this);
10291 auto ArgPackOrErr =
10292 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10293 if (!ArgPackOrErr)
10294 return ArgPackOrErr.takeError();
10295
10296 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10297 if (!AssociatedDeclOrErr)
10298 return AssociatedDeclOrErr.takeError();
10299
10300 return ToContext.getSubstTemplateTemplateParmPack(
10301 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10302 SubstPack->getFinal());
10303 }
10305 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10306 if (!UsingOrError)
10307 return UsingOrError.takeError();
10308 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10309 }
10311 llvm_unreachable("Unexpected DeducedTemplate");
10312 }
10313
10314 llvm_unreachable("Invalid template name kind");
10315}
10316
10318 if (FromLoc.isInvalid())
10319 return SourceLocation{};
10320
10321 SourceManager &FromSM = FromContext.getSourceManager();
10322 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10323
10324 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10325 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10326 if (!ToFileIDOrErr)
10327 return ToFileIDOrErr.takeError();
10328 SourceManager &ToSM = ToContext.getSourceManager();
10329 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10330}
10331
10333 SourceLocation ToBegin, ToEnd;
10334 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10335 return std::move(Err);
10336 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10337 return std::move(Err);
10338
10339 return SourceRange(ToBegin, ToEnd);
10340}
10341
10343 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10344 if (Pos != ImportedFileIDs.end())
10345 return Pos->second;
10346
10347 SourceManager &FromSM = FromContext.getSourceManager();
10348 SourceManager &ToSM = ToContext.getSourceManager();
10349 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10350
10351 // Map the FromID to the "to" source manager.
10352 FileID ToID;
10353 if (FromSLoc.isExpansion()) {
10354 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10355 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10356 if (!ToSpLoc)
10357 return ToSpLoc.takeError();
10358 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10359 if (!ToExLocS)
10360 return ToExLocS.takeError();
10361 unsigned ExLength = FromSM.getFileIDSize(FromID);
10362 SourceLocation MLoc;
10363 if (FromEx.isMacroArgExpansion()) {
10364 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10365 } else {
10366 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10367 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10368 FromEx.isExpansionTokenRange());
10369 else
10370 return ToExLocE.takeError();
10371 }
10372 ToID = ToSM.getFileID(MLoc);
10373 } else {
10374 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10375
10376 if (!IsBuiltin && !Cache->BufferOverridden) {
10377 // Include location of this file.
10378 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10379 if (!ToIncludeLoc)
10380 return ToIncludeLoc.takeError();
10381
10382 // Every FileID that is not the main FileID needs to have a valid include
10383 // location so that the include chain points to the main FileID. When
10384 // importing the main FileID (which has no include location), we need to
10385 // create a fake include location in the main file to keep this property
10386 // intact.
10387 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10388 if (FromID == FromSM.getMainFileID())
10389 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10390
10391 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10392 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10393 // the disk again
10394 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10395 // than mmap the files several times.
10396 auto Entry =
10397 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10398 // FIXME: The filename may be a virtual name that does probably not
10399 // point to a valid file and we get no Entry here. In this case try with
10400 // the memory buffer below.
10401 if (Entry)
10402 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10403 FromSLoc.getFile().getFileCharacteristic());
10404 }
10405 }
10406
10407 if (ToID.isInvalid() || IsBuiltin) {
10408 // FIXME: We want to re-use the existing MemoryBuffer!
10409 std::optional<llvm::MemoryBufferRef> FromBuf =
10410 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10411 FromSM.getFileManager(), SourceLocation{});
10412 if (!FromBuf)
10413 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10414
10415 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10416 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10417 FromBuf->getBufferIdentifier());
10418 ToID = ToSM.createFileID(std::move(ToBuf),
10419 FromSLoc.getFile().getFileCharacteristic());
10420 }
10421 }
10422
10423 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10424
10425 ImportedFileIDs[FromID] = ToID;
10426 return ToID;
10427}
10428
10430 ExpectedExpr ToExprOrErr = Import(From->getInit());
10431 if (!ToExprOrErr)
10432 return ToExprOrErr.takeError();
10433
10434 auto LParenLocOrErr = Import(From->getLParenLoc());
10435 if (!LParenLocOrErr)
10436 return LParenLocOrErr.takeError();
10437
10438 auto RParenLocOrErr = Import(From->getRParenLoc());
10439 if (!RParenLocOrErr)
10440 return RParenLocOrErr.takeError();
10441
10442 if (From->isBaseInitializer()) {
10443 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10444 if (!ToTInfoOrErr)
10445 return ToTInfoOrErr.takeError();
10446
10447 SourceLocation EllipsisLoc;
10448 if (From->isPackExpansion())
10449 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10450 return std::move(Err);
10451
10452 return new (ToContext) CXXCtorInitializer(
10453 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10454 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10455 } else if (From->isMemberInitializer()) {
10456 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10457 if (!ToFieldOrErr)
10458 return ToFieldOrErr.takeError();
10459
10460 auto MemberLocOrErr = Import(From->getMemberLocation());
10461 if (!MemberLocOrErr)
10462 return MemberLocOrErr.takeError();
10463
10464 return new (ToContext) CXXCtorInitializer(
10465 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10466 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10467 } else if (From->isIndirectMemberInitializer()) {
10468 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10469 if (!ToIFieldOrErr)
10470 return ToIFieldOrErr.takeError();
10471
10472 auto MemberLocOrErr = Import(From->getMemberLocation());
10473 if (!MemberLocOrErr)
10474 return MemberLocOrErr.takeError();
10475
10476 return new (ToContext) CXXCtorInitializer(
10477 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10478 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10479 } else if (From->isDelegatingInitializer()) {
10480 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10481 if (!ToTInfoOrErr)
10482 return ToTInfoOrErr.takeError();
10483
10484 return new (ToContext)
10485 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10486 *ToExprOrErr, *RParenLocOrErr);
10487 } else {
10488 // FIXME: assert?
10489 return make_error<ASTImportError>();
10490 }
10491}
10492
10495 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10496 if (Pos != ImportedCXXBaseSpecifiers.end())
10497 return Pos->second;
10498
10499 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10500 if (!ToSourceRange)
10501 return ToSourceRange.takeError();
10503 if (!ToTSI)
10504 return ToTSI.takeError();
10505 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10506 if (!ToEllipsisLoc)
10507 return ToEllipsisLoc.takeError();
10508 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10509 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10510 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10511 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10512 return Imported;
10513}
10514
10516 ASTNodeImporter Importer(*this);
10517 return Importer.ImportAPValue(FromValue);
10518}
10519
10521 ExpectedDecl ToOrErr = Import(From);
10522 if (!ToOrErr)
10523 return ToOrErr.takeError();
10524 Decl *To = *ToOrErr;
10525
10526 auto *FromDC = cast<DeclContext>(From);
10527 ASTNodeImporter Importer(*this);
10528
10529 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10530 if (!ToRecord->getDefinition()) {
10531 return Importer.ImportDefinition(
10532 cast<RecordDecl>(FromDC), ToRecord,
10534 }
10535 }
10536
10537 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10538 if (!ToEnum->getDefinition()) {
10539 return Importer.ImportDefinition(
10541 }
10542 }
10543
10544 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10545 if (!ToIFace->getDefinition()) {
10546 return Importer.ImportDefinition(
10547 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10549 }
10550 }
10551
10552 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10553 if (!ToProto->getDefinition()) {
10554 return Importer.ImportDefinition(
10555 cast<ObjCProtocolDecl>(FromDC), ToProto,
10557 }
10558 }
10559
10560 return Importer.ImportDeclContext(FromDC, true);
10561}
10562
10564 if (!FromName)
10565 return DeclarationName{};
10566
10567 switch (FromName.getNameKind()) {
10569 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10570
10574 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10575 return DeclarationName(*ToSelOrErr);
10576 else
10577 return ToSelOrErr.takeError();
10578
10580 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10581 return ToContext.DeclarationNames.getCXXConstructorName(
10582 ToContext.getCanonicalType(*ToTyOrErr));
10583 else
10584 return ToTyOrErr.takeError();
10585 }
10586
10588 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10589 return ToContext.DeclarationNames.getCXXDestructorName(
10590 ToContext.getCanonicalType(*ToTyOrErr));
10591 else
10592 return ToTyOrErr.takeError();
10593 }
10594
10596 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10597 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10598 cast<TemplateDecl>(*ToTemplateOrErr));
10599 else
10600 return ToTemplateOrErr.takeError();
10601 }
10602
10604 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10605 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10606 ToContext.getCanonicalType(*ToTyOrErr));
10607 else
10608 return ToTyOrErr.takeError();
10609 }
10610
10612 return ToContext.DeclarationNames.getCXXOperatorName(
10613 FromName.getCXXOverloadedOperator());
10614
10616 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10617 Import(FromName.getCXXLiteralIdentifier()));
10618
10620 // FIXME: STATICS!
10622 }
10623
10624 llvm_unreachable("Invalid DeclarationName Kind!");
10625}
10626
10628 if (!FromId)
10629 return nullptr;
10630
10631 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10632
10633 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10634 ToId->setBuiltinID(FromId->getBuiltinID());
10635
10636 return ToId;
10637}
10638
10641 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10642 return Import(FromII);
10643 return FromIO.getOperator();
10644}
10645
10647 if (FromSel.isNull())
10648 return Selector{};
10649
10651 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10652 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10653 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10654 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10655}
10656
10660 llvm::Error Err = llvm::Error::success();
10661 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10662 for (unsigned Idx = 0; Idx < Size; Idx++) {
10663 APValue Tmp = importChecked(Err, From[Idx]);
10664 To[Idx] = Tmp;
10665 }
10666 };
10667 switch (FromValue.getKind()) {
10668 case APValue::None:
10670 case APValue::Int:
10671 case APValue::Float:
10675 Result = FromValue;
10676 break;
10677 case APValue::Vector: {
10678 Result.MakeVector();
10680 Result.setVectorUninit(FromValue.getVectorLength());
10681 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10682 Elts.data(), FromValue.getVectorLength());
10683 break;
10684 }
10685 case APValue::Matrix:
10686 // Matrix values cannot currently arise in APValue import contexts.
10687 llvm_unreachable("Matrix APValue import not yet supported");
10688 case APValue::Array:
10689 Result.MakeArray(FromValue.getArrayInitializedElts(),
10690 FromValue.getArraySize());
10691 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10692 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10693 FromValue.getArrayInitializedElts());
10694 break;
10695 case APValue::Struct:
10696 Result.MakeStruct(FromValue.getStructNumBases(),
10697 FromValue.getStructNumFields());
10698 ImportLoop(
10699 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10700 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10701 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10702 break;
10703 case APValue::Union: {
10704 Result.MakeUnion();
10705 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10706 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10707 if (Err)
10708 return std::move(Err);
10709 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10710 break;
10711 }
10713 Result.MakeAddrLabelDiff();
10714 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10715 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10716 if (Err)
10717 return std::move(Err);
10718 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10719 cast<AddrLabelExpr>(ImpRHS));
10720 break;
10721 }
10723 const Decl *ImpMemPtrDecl =
10724 importChecked(Err, FromValue.getMemberPointerDecl());
10725 if (Err)
10726 return std::move(Err);
10728 Result.setMemberPointerUninit(
10729 cast<const ValueDecl>(ImpMemPtrDecl),
10731 FromValue.getMemberPointerPath().size());
10732 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10733 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10734 Idx++) {
10735 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10736 if (Err)
10737 return std::move(Err);
10738 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10739 }
10740 break;
10741 }
10742 case APValue::LValue:
10744 QualType FromElemTy;
10745 if (FromValue.getLValueBase()) {
10746 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10747 "in C++20 dynamic allocation are transient so they shouldn't "
10748 "appear in the AST");
10749 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10750 if (const auto *E =
10751 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10752 FromElemTy = E->getType();
10753 const Expr *ImpExpr = importChecked(Err, E);
10754 if (Err)
10755 return std::move(Err);
10756 Base = APValue::LValueBase(ImpExpr,
10757 FromValue.getLValueBase().getCallIndex(),
10758 FromValue.getLValueBase().getVersion());
10759 } else {
10760 FromElemTy =
10761 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10762 const Decl *ImpDecl = importChecked(
10763 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10764 if (Err)
10765 return std::move(Err);
10767 FromValue.getLValueBase().getCallIndex(),
10768 FromValue.getLValueBase().getVersion());
10769 }
10770 } else {
10771 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10772 const Type *ImpTypeInfo = importChecked(
10773 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10774 QualType ImpType =
10775 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10776 if (Err)
10777 return std::move(Err);
10779 ImpType);
10780 }
10781 }
10782 CharUnits Offset = FromValue.getLValueOffset();
10783 unsigned PathLength = FromValue.getLValuePath().size();
10784 Result.MakeLValue();
10785 if (FromValue.hasLValuePath()) {
10786 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10787 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10788 FromValue.isNullPointer());
10790 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10791 if (FromElemTy->isRecordType()) {
10792 const Decl *FromDecl =
10793 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10794 const Decl *ImpDecl = importChecked(Err, FromDecl);
10795 if (Err)
10796 return std::move(Err);
10797 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10798 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10799 else
10800 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10802 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10803 } else {
10804 FromElemTy =
10805 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10806 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10807 FromPath[LoopIdx].getAsArrayIndex());
10808 }
10809 }
10810 } else
10811 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10812 FromValue.isNullPointer());
10813 }
10814 if (Err)
10815 return std::move(Err);
10816 return Result;
10817}
10818
10820 DeclContext *DC,
10821 unsigned IDNS,
10822 NamedDecl **Decls,
10823 unsigned NumDecls) {
10824 if (ODRHandling == ODRHandlingType::Conservative)
10825 // Report error at any name conflict.
10826 return make_error<ASTImportError>(ASTImportError::NameConflict);
10827 else
10828 // Allow to create the new Decl with the same name.
10829 return Name;
10830}
10831
10833 if (LastDiagFromFrom)
10834 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10835 FromContext.getDiagnostics());
10836 LastDiagFromFrom = false;
10837 return ToContext.getDiagnostics().Report(Loc, DiagID);
10838}
10839
10841 if (!LastDiagFromFrom)
10842 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10843 ToContext.getDiagnostics());
10844 LastDiagFromFrom = true;
10845 return FromContext.getDiagnostics().Report(Loc, DiagID);
10846}
10847
10849 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10850 if (!ID->getDefinition())
10851 ID->startDefinition();
10852 }
10853 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10854 if (!PD->getDefinition())
10855 PD->startDefinition();
10856 }
10857 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10858 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10859 TD->startDefinition();
10860 TD->setCompleteDefinition(true);
10861 }
10862 }
10863 else {
10864 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10865 }
10866}
10867
10869 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10870 assert((Inserted || Pos->second == To) &&
10871 "Try to import an already imported Decl");
10872 if (!Inserted)
10873 return Pos->second;
10874 // This mapping should be maintained only in this function. Therefore do not
10875 // check for additional consistency.
10876 ImportedFromDecls[To] = From;
10877 // In the case of TypedefNameDecl we create the Decl first and only then we
10878 // import and set its DeclContext. So, the DC is still not set when we reach
10879 // here from GetImportedOrCreateDecl.
10880 if (To->getDeclContext())
10881 AddToLookupTable(To);
10882 return To;
10883}
10884
10885std::optional<ASTImportError>
10887 auto Pos = ImportDeclErrors.find(FromD);
10888 if (Pos != ImportDeclErrors.end())
10889 return Pos->second;
10890 else
10891 return std::nullopt;
10892}
10893
10895 auto InsertRes = ImportDeclErrors.insert({From, Error});
10896 (void)InsertRes;
10897 // Either we set the error for the first time, or we already had set one and
10898 // now we want to set the same error.
10899 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10900}
10901
10903 bool Complain) {
10904 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10905 ImportedTypes.find(From.getTypePtr());
10906 if (Pos != ImportedTypes.end()) {
10907 if (ExpectedType ToFromOrErr = Import(From)) {
10908 if (ToContext.hasSameType(*ToFromOrErr, To))
10909 return true;
10910 } else {
10911 llvm::consumeError(ToFromOrErr.takeError());
10912 }
10913 }
10914
10916 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10917 getStructuralEquivalenceKind(*this), false, Complain);
10918 return Ctx.IsEquivalent(From, To);
10919}
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:1001
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1021
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:1006
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1091
unsigned getArrayInitializedElts() const
Definition APValue.h:645
unsigned getStructNumBases() const
Definition APValue.h:654
bool hasLValuePath() const
Definition APValue.cpp:1016
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1084
APValue & getUnionValue()
Definition APValue.h:683
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:699
CharUnits & getLValueOffset()
Definition APValue.cpp:1011
unsigned getVectorLength() const
Definition APValue.h:590
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1098
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:1037
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:223
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
Definition ASTContext.h:962
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)
ExpectedDecl VisitFileScopeAsmDecl(FileScopeAsmDecl *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:4387
SourceLocation getQuestionLoc() const
Definition Expr.h:4386
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:4556
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4571
SourceLocation getLabelLoc() const
Definition Expr.h:4573
LabelDecl * getLabel() const
Definition Expr.h:4579
QualType getAdjustedType() const
Definition TypeBase.h:3569
QualType getOriginalType() const
Definition TypeBase.h:3568
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6024
Represents a loop initializing the elements of an array.
Definition Expr.h:5971
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5986
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5991
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2727
SourceLocation getRBracketLoc() const
Definition Expr.h:2775
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2756
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:3786
ArraySizeModifier getSizeModifier() const
Definition TypeBase.h:3800
QualType getElementType() const
Definition TypeBase.h:3798
unsigned getIndexTypeCVRQualifiers() const
Definition TypeBase.h:3808
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:6931
Expr ** getSubExprs()
Definition Expr.h:7006
SourceLocation getRParenLoc() const
Definition Expr.h:7060
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5278
AtomicOp getOp() const
Definition Expr.h:6994
SourceLocation getBuiltinLoc() const
Definition Expr.h:7059
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:3517
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3514
shadow_range shadows() const
Definition DeclCXX.h:3583
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4459
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4513
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4497
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4501
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4506
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4494
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4044
Expr * getLHS() const
Definition Expr.h:4094
SourceLocation getOperatorLoc() const
Definition Expr.h:4086
Expr * getRHS() const
Definition Expr.h:4096
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:5104
Opcode getOpcode() const
Definition Expr.h:4089
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4264
A binding in a decomposition declaration.
Definition DeclCXX.h:4206
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4239
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4232
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:4244
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4250
bool isUnsigned() const
Definition TypeBase.h:8309
unsigned getNumBits() const
Definition TypeBase.h:8311
QualType getPointeeType() const
Definition TypeBase.h:3618
decl_range dependent_decls() const
Definition TypeBase.h:3472
QualType desugar() const
Definition TypeBase.h:3462
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:3228
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:2111
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:2633
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2968
Represents a C++ base or member initializer.
Definition DeclCXX.h:2398
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2538
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2498
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2600
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2597
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2508
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2596
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2503
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2532
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2476
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2470
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2482
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2558
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2552
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2524
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1996
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2079
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:2898
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3170
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:2145
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2803
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2826
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2254
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:1998
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:142
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:2949
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:1523
ADLCallKind getADLCallKind() const
Definition Expr.h:3100
Expr * getCallee()
Definition Expr.h:3096
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3248
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3140
arg_range arguments()
Definition Expr.h:3201
SourceLocation getRParenLoc() const
Definition Expr.h:3280
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:3682
path_iterator path_begin()
Definition Expr.h:3752
CastKind getCastKind() const
Definition Expr.h:3726
path_iterator path_end()
Definition Expr.h:3753
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3802
Expr * getSubExpr()
Definition Expr.h:3732
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1627
unsigned getValue() const
Definition Expr.h:1635
CharacterLiteralKind getKind() const
Definition Expr.h:1628
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:4854
SourceLocation getBuiltinLoc() const
Definition Expr.h:4901
Expr * getLHS() const
Definition Expr.h:4896
bool isConditionDependent() const
Definition Expr.h:4884
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4877
Expr * getRHS() const
Definition Expr.h:4898
SourceLocation getRParenLoc() const
Definition Expr.h:4904
Expr * getCond() const
Definition Expr.h:4894
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:3349
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4306
QualType getComputationLHSType() const
Definition Expr.h:4340
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:5126
QualType getComputationResultType() const
Definition Expr.h:4343
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3611
SourceLocation getLParenLoc() const
Definition Expr.h:3646
bool isFileScope() const
Definition Expr.h:3643
const Expr * getInitializer() const
Definition Expr.h:3639
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3649
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:4397
Expr * getLHS() const
Definition Expr.h:4431
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4420
Expr * getRHS() const
Definition Expr.h:4432
const Expr * getSizeExpr() const
Return a pointer to the size expression.
Definition TypeBase.h:3920
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition TypeBase.h:3880
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1088
APValue getAPValueResult() const
Definition Expr.cpp:419
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:356
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition TypeBase.h:4470
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition TypeBase.h:4467
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:3698
ContinueStmt - This represents a continue.
Definition Stmt.h:3129
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4725
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4793
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4829
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:5691
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4826
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4818
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4815
bool isCountInBytes() const
Definition TypeBase.h:3527
Expr * getCountExpr() const
Definition TypeBase.h:3526
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:1399
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2126
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h:2594
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2215
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:2206
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:2705
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:2390
bool isFunctionOrMethod() const
Definition DeclBase.h:2178
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:1276
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1387
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1431
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1480
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1403
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:494
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1411
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1369
ValueDecl * getDecl()
Definition Expr.h:1344
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1457
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1474
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1463
SourceLocation getLocation() const
Definition Expr.h:1352
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1419
bool isImmediateEscalating() const
Definition Expr.h:1484
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:1243
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:1234
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:1197
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:935
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:386
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:995
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:4270
SourceLocation getDefaultLoc() const
Definition Stmt.h:2095
Stmt * getSubStmt()
Definition Stmt.h:2091
QualType getPointeeType() const
Definition TypeBase.h:4137
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4138
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:4181
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4551
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:4302
VectorKind getVectorKind() const
Definition TypeBase.h:4305
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4304
QualType getElementType() const
Definition TypeBase.h:4303
Represents a single C99 designator.
Definition Expr.h:5597
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5724
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5678
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5714
SourceLocation getFieldLoc() const
Definition Expr.h:5705
SourceLocation getRBracketLoc() const
Definition Expr.h:5753
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4795
SourceLocation getEllipsisLoc() const
Definition Expr.h:5747
SourceLocation getDotLoc() const
Definition Expr.h:5700
SourceLocation getLBracketLoc() const
Definition Expr.h:5741
Represents a C99 designated initializer expression.
Definition Expr.h:5554
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5836
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5818
MutableArrayRef< Designator > designators()
Definition Expr.h:5787
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5822
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5784
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5809
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5834
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4836
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:5214
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3458
llvm::APSInt getInitVal() const
Definition Decl.h:3478
const Expr * getInitExpr() const
Definition Decl.h:3476
Represents an enum.
Definition Decl.h:4046
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4318
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4264
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4256
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4267
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4228
EnumDecl * getMostRecentDecl()
Definition Decl.h:4151
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4273
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5091
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4219
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5151
EnumDecl * getDefinition() const
Definition Decl.h:4158
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4245
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4211
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3934
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3956
Store information needed for an explicit specifier.
Definition DeclCXX.h:1944
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1952
const Expr * getExpr() const
Definition DeclCXX.h:1953
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:3195
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3295
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4722
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3375
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3369
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4732
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3311
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3419
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4832
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:52
SourceLocation getAsmLoc() const
Definition Decl.h:4648
const Expr * getAsmStringExpr() const
Definition Decl.h:4655
SourceLocation getRParenLoc() const
Definition Decl.h:4649
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1587
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1581
SourceLocation getLocation() const
Definition Expr.h:1713
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1082
llvm::APFloat getValue() const
Definition Expr.h:1672
bool isExact() const
Definition Expr.h:1705
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:1068
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3117
Represents a function declaration or definition.
Definition Decl.h:2027
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3256
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2503
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4175
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4170
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3275
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3137
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2732
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3528
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2789
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:2940
SourceLocation getDefaultLoc() const
Definition Decl.h:2425
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2805
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2416
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2404
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2475
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4149
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4300
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2429
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2353
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4366
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2043
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2046
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2919
void setTrivial(bool IT)
Definition Decl.h:2405
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2738
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4121
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4188
bool isDeletedAsWritten() const
Definition Decl.h:2571
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:4355
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2380
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:2376
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3532
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2309
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3536
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3540
void setRangeEnd(SourceLocation E)
Definition Decl.h:2245
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2412
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4194
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4394
void setDefaulted(bool D=true)
Definition Decl.h:2413
void setBody(Stmt *B)
Definition Decl.cpp:3268
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2371
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3146
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2421
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4142
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2238
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3176
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:2930
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5371
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5660
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5825
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5811
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:4923
QualType getReturnType() const
Definition TypeBase.h:4907
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:4929
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4946
Represents a C11 generic selection.
Definition Expr.h:6185
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6462
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6482
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6443
SourceLocation getGenericLoc() const
Definition Expr.h:6540
SourceLocation getRParenLoc() const
Definition Expr.h:6544
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6432
SourceLocation getDefaultLoc() const
Definition Expr.h:6543
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:4725
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6439
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6450
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6487
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:1737
const Expr * getSubExpr() const
Definition Expr.h:1749
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3859
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2079
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1807
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6060
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5088
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3502
unsigned getChainingSize() const
Definition Decl.h:3527
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3523
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:2604
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2617
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2616
Describes an C or C++ initializer list.
Definition Expr.h:5305
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5418
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5479
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5432
unsigned getNumInits() const
Definition Expr.h:5338
SourceLocation getLBraceLoc() const
Definition Expr.h:5463
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2447
InitListExpr * getSyntacticForm() const
Definition Expr.h:5475
bool hadArrayRangeDesignator() const
Definition Expr.h:5486
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5408
bool isExplicit() const
Definition Expr.h:5448
SourceLocation getRBraceLoc() const
Definition Expr.h:5465
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5438
ArrayRef< Expr * > inits() const
Definition Expr.h:5358
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5489
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:981
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1542
ElaboratedTypeKeyword getKeyword() const
Definition TypeBase.h:6048
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:3329
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3375
Represents a linkage specification.
Definition DeclCXX.h:3036
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3078
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3059
SourceLocation getExternLoc() const
Definition DeclCXX.h:3075
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3076
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3070
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:6266
const IdentifierInfo * getMacroIdentifier() const
Definition TypeBase.h:6265
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:4415
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3370
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3542
SourceLocation getOperatorLoc() const
Definition Expr.h:3552
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3487
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3472
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3453
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3514
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3594
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:1756
Expr * getBase() const
Definition Expr.h:3447
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3503
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3495
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3547
bool isArrow() const
Definition Expr.h:3554
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3457
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:3749
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
Definition Type.cpp:5646
QualType getPointeeType() const
Definition TypeBase.h:3735
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:3222
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3283
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3305
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3308
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3311
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3292
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:8077
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:3573
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:2533
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2592
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2566
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2580
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1659
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2573
unsigned getNumExpressions() const
Definition Expr.h:2604
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2570
unsigned getNumComponents() const
Definition Expr.h:2588
Helper class for OffsetOfExpr.
Definition Expr.h:2427
const IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1694
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2485
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2491
@ Array
An index into an array.
Definition Expr.h:2432
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2436
@ Field
A field.
Definition Expr.h:2434
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2439
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2513
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2481
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2514
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2501
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1184
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1234
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1206
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:2188
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2213
const Expr * getSubExpr() const
Definition Expr.h:2205
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2217
ArrayRef< Expr * > exprs() const
Definition Expr.h:6130
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4976
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6113
SourceLocation getLParenLoc() const
Definition Expr.h:6132
SourceLocation getRParenLoc() const
Definition Expr.h:6133
QualType getInnerType() const
Definition TypeBase.h:3375
Represents a parameter to a function.
Definition Decl.h:1817
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1898
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1877
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1885
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:2999
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1913
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1958
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1946
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3024
bool isObjCMethodParameter() const
Definition Decl.h:1860
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1881
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1850
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1950
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1845
bool hasInheritedDefaultArg() const
Definition Decl.h:1962
void setKNRPromoted(bool promoted)
Definition Decl.h:1901
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1909
Expr * getDefaultArg()
Definition Decl.cpp:2987
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3029
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3035
unsigned getFunctionScopeDepth() const
Definition Decl.h:1867
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1966
QualType getElementType() const
Definition TypeBase.h:8276
bool isReadOnly() const
Definition TypeBase.h:8295
QualType getPointeeType() const
Definition TypeBase.h:3402
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2011
SourceLocation getBeginLoc() const
Definition Expr.h:2076
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:639
bool isTransparent() const
Definition Expr.h:2050
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2046
StringLiteral * getFunctionName()
Definition Expr.h:2055
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:6807
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6849
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5198
ArrayRef< Expr * > semantics()
Definition Expr.h:6879
unsigned getNumSemanticExprs() const
Definition Expr.h:6864
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6844
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:8447
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:8479
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:4360
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5243
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4416
field_range fields() const
Definition Decl.h:4563
RecordDecl * getMostRecentDecl()
Definition Decl.h:4386
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5288
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4544
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4412
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:5365
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3653
Represents the body of a requires-expression.
Definition DeclCXX.h:2114
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:4649
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4685
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4682
SourceLocation getRParenLoc() const
Definition Expr.h:4669
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4672
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:5023
SourceLocation getBeginLoc() const
Definition Expr.h:5068
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5064
SourceLocation getEndLoc() const
Definition Expr.h:5069
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5043
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:4157
bool isFailed() const
Definition DeclCXX.h:4186
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4188
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4601
CompoundStmt * getSubStmt()
Definition Expr.h:4618
unsigned getTemplateDepth() const
Definition Expr.h:4630
SourceLocation getRParenLoc() const
Definition Expr.h:4627
SourceLocation getLParenLoc() const
Definition Expr.h:4625
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:1805
bool isPascal() const
Definition Expr.h:1928
tokloc_iterator tokloc_begin() const
Definition Expr.h:1971
tokloc_iterator tokloc_end() const
Definition Expr.h:1975
StringLiteralKind getKind() const
Definition Expr.h:1918
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:1194
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1881
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1946
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:4717
QualType getParameterType() const
Determine the substituted type of the template parameter.
Definition ExprCXX.h:4728
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4715
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:1792
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:3752
SourceRange getBraceRange() const
Definition Decl.h:3829
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3873
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4926
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3848
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3853
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4006
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3989
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4903
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4898
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4940
TagKind getTagKind() const
Definition Decl.h:3952
void setBraceRange(SourceRange R)
Definition Decl.h:3830
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3856
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:3723
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3741
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:3582
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:6296
Expr * getUnderlyingExpr() const
Definition TypeBase.h:6293
A container of type source information.
Definition TypeBase.h:8418
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:8429
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:1907
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:8783
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9230
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2531
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:9277
bool isRecordType() const
Definition TypeBase.h:8811
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3702
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3597
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3647
QualType getUnderlyingType() const
Definition Decl.h:3652
TypedefNameDecl * getDecl() const
Definition TypeBase.h:6216
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6211
bool typeMatchesDecl() const
Definition TypeBase.h:6224
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2631
SourceLocation getRParenLoc() const
Definition Expr.h:2707
SourceLocation getOperatorLoc() const
Definition Expr.h:2704
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2677
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2663
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2250
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2295
Expr * getSubExpr() const
Definition Expr.h:2291
Opcode getOpcode() const
Definition Expr.h:2286
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2387
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2390
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5140
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2304
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:6113
UnresolvedUsingTypenameDecl * getDecl() const
Definition TypeBase.h:6119
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4058
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4088
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4092
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4085
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4109
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3961
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3992
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4002
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:4009
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4019
Represents a C++ using-declaration.
Definition DeclCXX.h:3612
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3661
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3646
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3653
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3639
Represents C++ using-directive.
Definition DeclCXX.h:3117
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3188
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3355
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3184
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3192
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3195
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3162
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3813
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3837
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3849
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3833
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3894
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3923
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3927
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3420
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3484
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3485
UsingShadowDecl * getDecl() const
Definition TypeBase.h:6159
QualType desugar() const
Definition TypeBase.h:6161
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6155
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4963
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:4987
SourceLocation getBuiltinLoc() const
Definition Expr.h:4990
SourceLocation getRParenLoc() const
Definition Expr.h:4993
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4984
const Expr * getSubExpr() const
Definition Expr.h:4979
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:932
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2771
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1591
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2896
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:1576
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:1580
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2733
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1363
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1179
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1573
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1183
const Expr * getInit() const
Definition Decl.h:1389
void setConstexpr(bool IC)
Definition Decl.h:1594
void setInit(Expr *I)
Definition Decl.cpp:2456
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2776
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
void setImplicitlyInline()
Definition Decl.h:1585
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:1379
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2859
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:4044
unsigned getNumElements() const
Definition TypeBase.h:4254
VectorKind getVectorKind() const
Definition TypeBase.h:4259
QualType getElementType() const
Definition TypeBase.h:4253
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:147
llvm::Expected< Expr * > ExpectedExpr
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition DeclBase.h:1305
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)
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 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
unsigned HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:899
unsigned HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:907
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5440
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5444
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5430
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5433
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5436
Extra information about a function prototype.
Definition TypeBase.h:5456
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