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