clang 22.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 if (auto *VD = dyn_cast<VarDecl>(D))
125 if (auto *TD = dyn_cast<TagDecl>(D))
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 // Use this to import pointers of specific type.
189 template <typename ImportT>
190 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
191 auto ToOrErr = Importer.Import(From);
192 if (ToOrErr)
193 To = cast_or_null<ImportT>(*ToOrErr);
194 return ToOrErr.takeError();
195 }
196
197 // Call the import function of ASTImporter for a baseclass of type `T` and
198 // cast the return value to `T`.
199 template <typename T>
200 auto import(T *From)
201 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203 auto ToOrErr = Importer.Import(From);
204 if (!ToOrErr)
205 return ToOrErr.takeError();
206 return cast_or_null<T>(*ToOrErr);
207 }
208
209 template <typename T>
210 auto import(const T *From) {
211 return import(const_cast<T *>(From));
212 }
213
214 // Call the import function of ASTImporter for type `T`.
215 template <typename T>
216 Expected<T> import(const T &From) {
217 return Importer.Import(From);
218 }
219
220 // Import an std::optional<T> by importing the contained T, if any.
221 template <typename T>
222 Expected<std::optional<T>> import(std::optional<T> From) {
223 if (!From)
224 return std::nullopt;
225 return import(*From);
226 }
227
228 ExplicitSpecifier importExplicitSpecifier(Error &Err,
229 ExplicitSpecifier ESpec);
230
231 // Wrapper for an overload set.
232 template <typename ToDeclT> struct CallOverloadedCreateFun {
233 template <typename... Args> decltype(auto) operator()(Args &&... args) {
234 return ToDeclT::Create(std::forward<Args>(args)...);
235 }
236 };
237
238 // Always use these functions to create a Decl during import. There are
239 // certain tasks which must be done after the Decl was created, e.g. we
240 // must immediately register that as an imported Decl. The parameter `ToD`
241 // will be set to the newly created Decl or if had been imported before
242 // then to the already imported Decl. Returns a bool value set to true if
243 // the `FromD` had been imported before.
244 template <typename ToDeclT, typename FromDeclT, typename... Args>
245 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
246 Args &&...args) {
247 // There may be several overloads of ToDeclT::Create. We must make sure
248 // to call the one which would be chosen by the arguments, thus we use a
249 // wrapper for the overload set.
250 CallOverloadedCreateFun<ToDeclT> OC;
251 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
252 std::forward<Args>(args)...);
253 }
254 // Use this overload if a special Type is needed to be created. E.g if we
255 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
256 // then:
257 // TypedefNameDecl *ToTypedef;
258 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
259 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
260 typename... Args>
261 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
262 Args &&...args) {
263 CallOverloadedCreateFun<NewDeclT> OC;
264 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
265 std::forward<Args>(args)...);
266 }
267 // Use this version if a special create function must be
268 // used, e.g. CXXRecordDecl::CreateLambda .
269 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
270 typename... Args>
271 [[nodiscard]] bool
272 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
273 FromDeclT *FromD, Args &&...args) {
274 if (Importer.getImportDeclErrorIfAny(FromD)) {
275 ToD = nullptr;
276 return true; // Already imported but with error.
277 }
278 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
279 if (ToD)
280 return true; // Already imported.
281 ToD = CreateFun(std::forward<Args>(args)...);
282 // Keep track of imported Decls.
283 Importer.RegisterImportedDecl(FromD, ToD);
284 Importer.SharedState->markAsNewDecl(ToD);
285 InitializeImportedDecl(FromD, ToD);
286 return false; // A new Decl is created.
287 }
288
289 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
290 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
291 if (FromD->isUsed())
292 ToD->setIsUsed();
293 if (FromD->isImplicit())
294 ToD->setImplicit();
295 }
296
297 // Check if we have found an existing definition. Returns with that
298 // definition if yes, otherwise returns null.
299 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
300 const FunctionDecl *Definition = nullptr;
302 FoundFunction->hasBody(Definition))
303 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
304 return nullptr;
305 }
306
307 void addDeclToContexts(Decl *FromD, Decl *ToD) {
308 if (Importer.isMinimalImport()) {
309 // In minimal import case the decl must be added even if it is not
310 // contained in original context, for LLDB compatibility.
311 // FIXME: Check if a better solution is possible.
312 if (!FromD->getDescribedTemplate() &&
313 FromD->getFriendObjectKind() == Decl::FOK_None)
315 return;
316 }
317
318 DeclContext *FromDC = FromD->getDeclContext();
319 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
320 DeclContext *ToDC = ToD->getDeclContext();
321 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
322
323 bool Visible = false;
324 if (FromDC->containsDeclAndLoad(FromD)) {
325 ToDC->addDeclInternal(ToD);
326 Visible = true;
327 }
328 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
329 ToLexicalDC->addDeclInternal(ToD);
330 Visible = true;
331 }
332
333 // If the Decl was added to any context, it was made already visible.
334 // Otherwise it is still possible that it should be visible.
335 if (!Visible) {
336 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
337 auto *ToNamed = cast<NamedDecl>(ToD);
338 DeclContextLookupResult FromLookup =
339 FromDC->lookup(FromNamed->getDeclName());
340 if (llvm::is_contained(FromLookup, FromNamed))
341 ToDC->makeDeclVisibleInContext(ToNamed);
342 }
343 }
344 }
345
346 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
347 DeclContext *OldDC) {
348 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
349 if (!LT)
350 return;
351
352 for (NamedDecl *TP : Params)
353 LT->update(TP, OldDC);
354 }
355
356 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
357 updateLookupTableForTemplateParameters(
358 Params, Importer.getToContext().getTranslationUnitDecl());
359 }
360
361 template <typename TemplateParmDeclT>
362 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
363 TemplateParmDeclT *ToD) {
364 if (D->hasDefaultArgument()) {
365 if (D->defaultArgumentWasInherited()) {
366 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
367 import(D->getDefaultArgStorage().getInheritedFrom());
368 if (!ToInheritedFromOrErr)
369 return ToInheritedFromOrErr.takeError();
370 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
371 if (!ToInheritedFrom->hasDefaultArgument()) {
372 // Resolve possible circular dependency between default value of the
373 // template argument and the template declaration.
374 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
375 import(D->getDefaultArgStorage()
376 .getInheritedFrom()
377 ->getDefaultArgument());
378 if (!ToInheritedDefaultArgOrErr)
379 return ToInheritedDefaultArgOrErr.takeError();
380 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
381 *ToInheritedDefaultArgOrErr);
382 }
383 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
384 ToInheritedFrom);
385 } else {
386 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
387 import(D->getDefaultArgument());
388 if (!ToDefaultArgOrErr)
389 return ToDefaultArgOrErr.takeError();
390 // Default argument could have been set in the
391 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
392 if (!ToD->hasDefaultArgument())
393 ToD->setDefaultArgument(Importer.getToContext(),
394 *ToDefaultArgOrErr);
395 }
396 }
397 return Error::success();
398 }
399
400 public:
401 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
402
406
407 // Importing types
409#define TYPE(Class, Base) \
410 ExpectedType Visit##Class##Type(const Class##Type *T);
411#include "clang/AST/TypeNodes.inc"
412
413 // Importing declarations
415 SourceLocation &Loc);
417 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
418 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
419 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
422 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
424 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
426
427 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
429 Expected<APValue> ImportAPValue(const APValue &FromValue);
430
432
433 /// What we should import from the definition.
435 /// Import the default subset of the definition, which might be
436 /// nothing (if minimal import is set) or might be everything (if minimal
437 /// import is not set).
439 /// Import everything.
441 /// Import only the bare bones needed to establish a valid
442 /// DeclContext.
444 };
445
447 return IDK == IDK_Everything ||
448 (IDK == IDK_Default && !Importer.isMinimalImport());
449 }
450
453 RecordDecl *From, RecordDecl *To,
456 EnumDecl *From, EnumDecl *To,
468
469 template <typename InContainerTy>
471 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
472
473 template<typename InContainerTy>
475 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
476 const InContainerTy &Container, TemplateArgumentListInfo &Result);
477
480 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
483 FunctionDecl *FromFD);
484
485 template <typename DeclTy>
486 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
487
489
491
493 ParmVarDecl *ToParam);
494
497
498 // Use for allocating string for newly imported object.
499 StringRef ImportASTStringRef(StringRef FromStr);
508
509 template <typename T>
511
512 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
513 bool IgnoreTemplateParmDepth = false);
560
563
581
582 // Importing statements
602 // FIXME: MSAsmStmt
603 // FIXME: SEHExceptStmt
604 // FIXME: SEHFinallyStmt
605 // FIXME: SEHTryStmt
606 // FIXME: SEHLeaveStmt
607 // FIXME: CapturedStmt
611 // FIXME: MSDependentExistsStmt
619
620 // Importing expressions
699
700 // Helper for chaining together multiple imports. If an error is detected,
701 // subsequent imports will return default constructed nodes, so that failure
702 // can be detected with a single conditional branch after a sequence of
703 // imports.
704 template <typename T> T importChecked(Error &Err, const T &From) {
705 // Don't attempt to import nodes if we hit an error earlier.
706 if (Err)
707 return T{};
708 Expected<T> MaybeVal = import(From);
709 if (!MaybeVal) {
710 Err = MaybeVal.takeError();
711 return T{};
712 }
713 return *MaybeVal;
714 }
715
716 template<typename IIter, typename OIter>
717 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
718 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
719 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
720 Expected<ItemT> ToOrErr = import(*Ibegin);
721 if (!ToOrErr)
722 return ToOrErr.takeError();
723 *Obegin = *ToOrErr;
724 }
725 return Error::success();
726 }
727
728 // Import every item from a container structure into an output container.
729 // If error occurs, stops at first error and returns the error.
730 // The output container should have space for all needed elements (it is not
731 // expanded, new items are put into from the beginning).
732 template<typename InContainerTy, typename OutContainerTy>
734 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
735 return ImportArrayChecked(
736 InContainer.begin(), InContainer.end(), OutContainer.begin());
737 }
738
739 template<typename InContainerTy, typename OIter>
740 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
741 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
742 }
743
745 CXXMethodDecl *FromMethod);
746
748 FunctionDecl *FromFD);
749
750 // Returns true if the given function has a placeholder return type and
751 // that type is declared inside the body of the function.
752 // E.g. auto f() { struct X{}; return X(); }
754 };
755
756template <typename InContainerTy>
758 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
759 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
760 auto ToLAngleLocOrErr = import(FromLAngleLoc);
761 if (!ToLAngleLocOrErr)
762 return ToLAngleLocOrErr.takeError();
763 auto ToRAngleLocOrErr = import(FromRAngleLoc);
764 if (!ToRAngleLocOrErr)
765 return ToRAngleLocOrErr.takeError();
766
767 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
768 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
769 return Err;
770 Result = ToTAInfo;
771 return Error::success();
772}
773
774template <>
780
781template <>
789
792 FunctionDecl *FromFD) {
793 assert(FromFD->getTemplatedKind() ==
795
797
798 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
799 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
800 return std::move(Err);
801
802 // Import template arguments.
803 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
804 std::get<1>(Result)))
805 return std::move(Err);
806
807 return Result;
808}
809
810template <>
812ASTNodeImporter::import(TemplateParameterList *From) {
814 if (Error Err = ImportContainerChecked(*From, To))
815 return std::move(Err);
816
817 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
818 if (!ToRequiresClause)
819 return ToRequiresClause.takeError();
820
821 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
822 if (!ToTemplateLocOrErr)
823 return ToTemplateLocOrErr.takeError();
824 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
825 if (!ToLAngleLocOrErr)
826 return ToLAngleLocOrErr.takeError();
827 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
828 if (!ToRAngleLocOrErr)
829 return ToRAngleLocOrErr.takeError();
830
832 Importer.getToContext(),
833 *ToTemplateLocOrErr,
834 *ToLAngleLocOrErr,
835 To,
836 *ToRAngleLocOrErr,
837 *ToRequiresClause);
838}
839
840template <>
842ASTNodeImporter::import(const TemplateArgument &From) {
843 switch (From.getKind()) {
845 return TemplateArgument();
846
848 ExpectedType ToTypeOrErr = import(From.getAsType());
849 if (!ToTypeOrErr)
850 return ToTypeOrErr.takeError();
851 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
852 From.getIsDefaulted());
853 }
854
856 ExpectedType ToTypeOrErr = import(From.getIntegralType());
857 if (!ToTypeOrErr)
858 return ToTypeOrErr.takeError();
859 return TemplateArgument(From, *ToTypeOrErr);
860 }
861
863 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
864 if (!ToOrErr)
865 return ToOrErr.takeError();
866 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
867 if (!ToTypeOrErr)
868 return ToTypeOrErr.takeError();
869 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
870 *ToTypeOrErr, From.getIsDefaulted());
871 }
872
874 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
875 if (!ToTypeOrErr)
876 return ToTypeOrErr.takeError();
877 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
878 From.getIsDefaulted());
879 }
880
882 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
883 if (!ToTypeOrErr)
884 return ToTypeOrErr.takeError();
885 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
886 if (!ToValueOrErr)
887 return ToValueOrErr.takeError();
888 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
889 *ToValueOrErr);
890 }
891
893 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
894 if (!ToTemplateOrErr)
895 return ToTemplateOrErr.takeError();
896
897 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
898 }
899
901 Expected<TemplateName> ToTemplateOrErr =
902 import(From.getAsTemplateOrTemplatePattern());
903 if (!ToTemplateOrErr)
904 return ToTemplateOrErr.takeError();
905
906 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
907 From.getIsDefaulted());
908 }
909
911 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
912 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
913 From.getIsDefaulted());
914 else
915 return ToExpr.takeError();
916
919 ToPack.reserve(From.pack_size());
920 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
921 return std::move(Err);
922
923 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
924 }
925 }
926
927 llvm_unreachable("Invalid template argument kind");
928}
929
930template <>
932ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
933 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
934 if (!ArgOrErr)
935 return ArgOrErr.takeError();
936 TemplateArgument Arg = *ArgOrErr;
937
938 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
939
942 ExpectedExpr E = import(FromInfo.getAsExpr());
943 if (!E)
944 return E.takeError();
945 ToInfo = TemplateArgumentLocInfo(*E);
946 } else if (Arg.getKind() == TemplateArgument::Type) {
947 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
948 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
949 else
950 return TSIOrErr.takeError();
951 } else {
952 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
953 if (!ToTemplateKWLocOrErr)
954 return ToTemplateKWLocOrErr.takeError();
955 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
956 if (!ToTemplateQualifierLocOrErr)
957 return ToTemplateQualifierLocOrErr.takeError();
958 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
959 if (!ToTemplateNameLocOrErr)
960 return ToTemplateNameLocOrErr.takeError();
961 auto ToTemplateEllipsisLocOrErr =
962 import(FromInfo.getTemplateEllipsisLoc());
963 if (!ToTemplateEllipsisLocOrErr)
964 return ToTemplateEllipsisLocOrErr.takeError();
966 Importer.getToContext(), *ToTemplateKWLocOrErr,
967 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
968 *ToTemplateEllipsisLocOrErr);
969 }
970
971 return TemplateArgumentLoc(Arg, ToInfo);
972}
973
974template <>
975Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
976 if (DG.isNull())
977 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
978 size_t NumDecls = DG.end() - DG.begin();
980 ToDecls.reserve(NumDecls);
981 for (Decl *FromD : DG) {
982 if (auto ToDOrErr = import(FromD))
983 ToDecls.push_back(*ToDOrErr);
984 else
985 return ToDOrErr.takeError();
986 }
987 return DeclGroupRef::Create(Importer.getToContext(),
988 ToDecls.begin(),
989 NumDecls);
990}
991
992template <>
994ASTNodeImporter::import(const Designator &D) {
995 if (D.isFieldDesignator()) {
996 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
997
998 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
999 if (!ToDotLocOrErr)
1000 return ToDotLocOrErr.takeError();
1001
1002 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1003 if (!ToFieldLocOrErr)
1004 return ToFieldLocOrErr.takeError();
1005
1007 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1008 }
1009
1010 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1011 if (!ToLBracketLocOrErr)
1012 return ToLBracketLocOrErr.takeError();
1013
1014 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1015 if (!ToRBracketLocOrErr)
1016 return ToRBracketLocOrErr.takeError();
1017
1018 if (D.isArrayDesignator())
1020 *ToLBracketLocOrErr,
1021 *ToRBracketLocOrErr);
1022
1023 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1024 if (!ToEllipsisLocOrErr)
1025 return ToEllipsisLocOrErr.takeError();
1026
1027 assert(D.isArrayRangeDesignator());
1029 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1030 *ToRBracketLocOrErr);
1031}
1032
1033template <>
1034Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1035 Error Err = Error::success();
1036 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1037 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1038 auto ToConceptNameLoc =
1039 importChecked(Err, From->getConceptNameInfo().getLoc());
1040 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1041 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1042 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1043 if (Err)
1044 return std::move(Err);
1045 TemplateArgumentListInfo ToTAInfo;
1046 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1047 if (ASTTemplateArgs)
1048 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1049 return std::move(Err);
1050 auto *ConceptRef = ConceptReference::Create(
1051 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1052 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1053 ToNamedConcept,
1054 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1055 Importer.getToContext(), ToTAInfo)
1056 : nullptr);
1057 return ConceptRef;
1058}
1059
1060StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1061 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1062 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1063 return StringRef(ToStore, FromStr.size());
1064}
1065
1067 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1068 ToSat.IsSatisfied = FromSat.IsSatisfied;
1069 ToSat.ContainsErrors = FromSat.ContainsErrors;
1070 if (!ToSat.IsSatisfied) {
1071 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1072 if (const Expr *E = Record->dyn_cast<const Expr *>()) {
1073 ExpectedExpr ToSecondExpr = import(E);
1074 if (!ToSecondExpr)
1075 return ToSecondExpr.takeError();
1076 ToSat.Details.emplace_back(ToSecondExpr.get());
1077 } else {
1078 auto Pair =
1079 Record->dyn_cast<const ConstraintSubstitutionDiagnostic *>();
1080
1081 ExpectedSLoc ToPairFirst = import(Pair->first);
1082 if (!ToPairFirst)
1083 return ToPairFirst.takeError();
1084 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1085 ToSat.Details.emplace_back(new (Importer.getToContext())
1087 ToPairFirst.get(), ToPairSecond});
1088 }
1089 }
1090 }
1091 return Error::success();
1092}
1093
1094template <>
1096ASTNodeImporter::import(
1098 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1099 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1100 if (!ToLoc)
1101 return ToLoc.takeError();
1102 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1103 return new (Importer.getToContext())
1105 ToDiagMessage};
1106}
1107
1110 using namespace concepts;
1111
1112 if (From->isSubstitutionFailure()) {
1113 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1114 if (!DiagOrErr)
1115 return DiagOrErr.takeError();
1116 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1117 } else {
1118 Expected<TypeSourceInfo *> ToType = import(From->getType());
1119 if (!ToType)
1120 return ToType.takeError();
1121 return new (Importer.getToContext()) TypeRequirement(*ToType);
1122 }
1123}
1124
1127 using namespace concepts;
1128
1129 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1130 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1131
1132 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1133 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1134
1135 if (IsRKSimple) {
1136 Req.emplace();
1137 } else {
1138 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1140
1141 if (FromTypeRequirement.isTypeConstraint()) {
1142 const bool IsDependent = FromTypeRequirement.isDependent();
1143 auto ParamsOrErr =
1144 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1145 if (!ParamsOrErr)
1146 return ParamsOrErr.takeError();
1147 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1148 auto SubstConstraintExprOrErr =
1150 if (!SubstConstraintExprOrErr)
1151 return SubstConstraintExprOrErr.takeError();
1152 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1153 }
1154 Req.emplace(ParamsOrErr.get(), IsDependent);
1155 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1156 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1157 if (!DiagOrErr)
1158 return DiagOrErr.takeError();
1159 Req.emplace(DiagOrErr.get());
1160 } else {
1161 Req.emplace();
1162 }
1163 }
1164
1165 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1166 if (!NoexceptLocOrErr)
1167 return NoexceptLocOrErr.takeError();
1168
1169 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1170 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1171 if (!DiagOrErr)
1172 return DiagOrErr.takeError();
1173 return new (Importer.getToContext()) ExprRequirement(
1174 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1175 } else {
1176 Expected<Expr *> ExprOrErr = import(From->getExpr());
1177 if (!ExprOrErr)
1178 return ExprOrErr.takeError();
1179 return new (Importer.getToContext()) concepts::ExprRequirement(
1180 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1181 SubstitutedConstraintExpr);
1182 }
1183}
1184
1187 using namespace concepts;
1188
1189 const ASTConstraintSatisfaction &FromSatisfaction =
1191 if (From->hasInvalidConstraint()) {
1192 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1193 ASTConstraintSatisfaction *ToSatisfaction =
1194 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1195 FromSatisfaction);
1196 return new (Importer.getToContext())
1197 NestedRequirement(ToEntity, ToSatisfaction);
1198 } else {
1199 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1200 if (!ToExpr)
1201 return ToExpr.takeError();
1202 if (ToExpr.get()->isInstantiationDependent()) {
1203 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1204 } else {
1205 ConstraintSatisfaction Satisfaction;
1206 if (Error Err =
1207 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1208 return std::move(Err);
1209 return new (Importer.getToContext()) NestedRequirement(
1210 Importer.getToContext(), ToExpr.get(), Satisfaction);
1211 }
1212 }
1213}
1214
1215template <>
1217ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1218 switch (FromRequire->getKind()) {
1227 }
1228 llvm_unreachable("Unhandled requirement kind");
1229}
1230
1231template <>
1232Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1233 ValueDecl *Var = nullptr;
1234 if (From.capturesVariable()) {
1235 if (auto VarOrErr = import(From.getCapturedVar()))
1236 Var = *VarOrErr;
1237 else
1238 return VarOrErr.takeError();
1239 }
1240
1241 auto LocationOrErr = import(From.getLocation());
1242 if (!LocationOrErr)
1243 return LocationOrErr.takeError();
1244
1245 SourceLocation EllipsisLoc;
1246 if (From.isPackExpansion())
1247 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1248 return std::move(Err);
1249
1250 return LambdaCapture(
1251 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1252 EllipsisLoc);
1253}
1254
1255template <typename T>
1257 if (Found->getLinkageInternal() != From->getLinkageInternal())
1258 return false;
1259
1260 if (From->hasExternalFormalLinkage())
1261 return Found->hasExternalFormalLinkage();
1262 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1263 return false;
1264 if (From->isInAnonymousNamespace())
1265 return Found->isInAnonymousNamespace();
1266 else
1267 return !Found->isInAnonymousNamespace() &&
1268 !Found->hasExternalFormalLinkage();
1269}
1270
1271template <>
1273 TypedefNameDecl *From) {
1274 if (Found->getLinkageInternal() != From->getLinkageInternal())
1275 return false;
1276
1277 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1278 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1279 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1280}
1281
1282} // namespace clang
1283
1284//----------------------------------------------------------------------------
1285// Import Types
1286//----------------------------------------------------------------------------
1287
1288using namespace clang;
1289
1291 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1292 << T->getTypeClassName();
1293 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1294}
1295
1296ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1297 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1298 if (!UnderlyingTypeOrErr)
1299 return UnderlyingTypeOrErr.takeError();
1300
1301 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1302}
1303
1304ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1305 switch (T->getKind()) {
1306#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1307 case BuiltinType::Id: \
1308 return Importer.getToContext().SingletonId;
1309#include "clang/Basic/OpenCLImageTypes.def"
1310#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1311 case BuiltinType::Id: \
1312 return Importer.getToContext().Id##Ty;
1313#include "clang/Basic/OpenCLExtensionTypes.def"
1314#define SVE_TYPE(Name, Id, SingletonId) \
1315 case BuiltinType::Id: \
1316 return Importer.getToContext().SingletonId;
1317#include "clang/Basic/AArch64ACLETypes.def"
1318#define PPC_VECTOR_TYPE(Name, Id, Size) \
1319 case BuiltinType::Id: \
1320 return Importer.getToContext().Id##Ty;
1321#include "clang/Basic/PPCTypes.def"
1322#define RVV_TYPE(Name, Id, SingletonId) \
1323 case BuiltinType::Id: \
1324 return Importer.getToContext().SingletonId;
1325#include "clang/Basic/RISCVVTypes.def"
1326#define WASM_TYPE(Name, Id, SingletonId) \
1327 case BuiltinType::Id: \
1328 return Importer.getToContext().SingletonId;
1329#include "clang/Basic/WebAssemblyReferenceTypes.def"
1330#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1331 case BuiltinType::Id: \
1332 return Importer.getToContext().SingletonId;
1333#include "clang/Basic/AMDGPUTypes.def"
1334#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1335 case BuiltinType::Id: \
1336 return Importer.getToContext().SingletonId;
1337#include "clang/Basic/HLSLIntangibleTypes.def"
1338#define SHARED_SINGLETON_TYPE(Expansion)
1339#define BUILTIN_TYPE(Id, SingletonId) \
1340 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1341#include "clang/AST/BuiltinTypes.def"
1342
1343 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1344 // context supports C++.
1345
1346 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1347 // context supports ObjC.
1348
1349 case BuiltinType::Char_U:
1350 // The context we're importing from has an unsigned 'char'. If we're
1351 // importing into a context with a signed 'char', translate to
1352 // 'unsigned char' instead.
1353 if (Importer.getToContext().getLangOpts().CharIsSigned)
1354 return Importer.getToContext().UnsignedCharTy;
1355
1356 return Importer.getToContext().CharTy;
1357
1358 case BuiltinType::Char_S:
1359 // The context we're importing from has an unsigned 'char'. If we're
1360 // importing into a context with a signed 'char', translate to
1361 // 'unsigned char' instead.
1362 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1363 return Importer.getToContext().SignedCharTy;
1364
1365 return Importer.getToContext().CharTy;
1366
1367 case BuiltinType::WChar_S:
1368 case BuiltinType::WChar_U:
1369 // FIXME: If not in C++, shall we translate to the C equivalent of
1370 // wchar_t?
1371 return Importer.getToContext().WCharTy;
1372 }
1373
1374 llvm_unreachable("Invalid BuiltinType Kind!");
1375}
1376
1377ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1378 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1379 if (!ToOriginalTypeOrErr)
1380 return ToOriginalTypeOrErr.takeError();
1381
1382 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1383}
1384
1385ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1386 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1387 if (!ToElementTypeOrErr)
1388 return ToElementTypeOrErr.takeError();
1389
1390 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1391}
1392
1393ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1394 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1395 if (!ToPointeeTypeOrErr)
1396 return ToPointeeTypeOrErr.takeError();
1397
1398 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1399}
1400
1401ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1402 // FIXME: Check for blocks support in "to" context.
1403 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1404 if (!ToPointeeTypeOrErr)
1405 return ToPointeeTypeOrErr.takeError();
1406
1407 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1408}
1409
1411ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1412 // FIXME: Check for C++ support in "to" context.
1413 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1414 if (!ToPointeeTypeOrErr)
1415 return ToPointeeTypeOrErr.takeError();
1416
1417 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1418}
1419
1421ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1422 // FIXME: Check for C++0x support in "to" context.
1423 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1424 if (!ToPointeeTypeOrErr)
1425 return ToPointeeTypeOrErr.takeError();
1426
1427 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1428}
1429
1431ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1432 // FIXME: Check for C++ support in "to" context.
1433 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1434 if (!ToPointeeTypeOrErr)
1435 return ToPointeeTypeOrErr.takeError();
1436
1437 auto QualifierOrErr = import(T->getQualifier());
1438 if (!QualifierOrErr)
1439 return QualifierOrErr.takeError();
1440
1441 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1442 if (!ClsOrErr)
1443 return ClsOrErr.takeError();
1444
1445 return Importer.getToContext().getMemberPointerType(
1446 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1447}
1448
1450ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1451 Error Err = Error::success();
1452 auto ToElementType = importChecked(Err, T->getElementType());
1453 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1454 if (Err)
1455 return std::move(Err);
1456
1457 return Importer.getToContext().getConstantArrayType(
1458 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1459 T->getIndexTypeCVRQualifiers());
1460}
1461
1463ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1464 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1465 if (!ToArrayTypeOrErr)
1466 return ToArrayTypeOrErr.takeError();
1467
1468 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1469}
1470
1472ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1473 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1474 if (!ToElementTypeOrErr)
1475 return ToElementTypeOrErr.takeError();
1476
1477 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1478 T->getSizeModifier(),
1479 T->getIndexTypeCVRQualifiers());
1480}
1481
1483ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1484 Error Err = Error::success();
1485 QualType ToElementType = importChecked(Err, T->getElementType());
1486 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1487 if (Err)
1488 return std::move(Err);
1489 return Importer.getToContext().getVariableArrayType(
1490 ToElementType, ToSizeExpr, T->getSizeModifier(),
1491 T->getIndexTypeCVRQualifiers());
1492}
1493
1494ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1495 const DependentSizedArrayType *T) {
1496 Error Err = Error::success();
1497 QualType ToElementType = importChecked(Err, T->getElementType());
1498 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1499 if (Err)
1500 return std::move(Err);
1501 // SizeExpr may be null if size is not specified directly.
1502 // For example, 'int a[]'.
1503
1504 return Importer.getToContext().getDependentSizedArrayType(
1505 ToElementType, ToSizeExpr, T->getSizeModifier(),
1506 T->getIndexTypeCVRQualifiers());
1507}
1508
1509ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1511 Error Err = Error::success();
1512 QualType ToElementType = importChecked(Err, T->getElementType());
1513 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1514 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1515 if (Err)
1516 return std::move(Err);
1517 return Importer.getToContext().getDependentSizedExtVectorType(
1518 ToElementType, ToSizeExpr, ToAttrLoc);
1519}
1520
1521ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1522 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1523 if (!ToElementTypeOrErr)
1524 return ToElementTypeOrErr.takeError();
1525
1526 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1527 T->getNumElements(),
1528 T->getVectorKind());
1529}
1530
1531ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1532 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1533 if (!ToElementTypeOrErr)
1534 return ToElementTypeOrErr.takeError();
1535
1536 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1537 T->getNumElements());
1538}
1539
1541ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1542 // FIXME: What happens if we're importing a function without a prototype
1543 // into C++? Should we make it variadic?
1544 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1545 if (!ToReturnTypeOrErr)
1546 return ToReturnTypeOrErr.takeError();
1547
1548 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1549 T->getExtInfo());
1550}
1551
1553ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1554 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1555 if (!ToReturnTypeOrErr)
1556 return ToReturnTypeOrErr.takeError();
1557
1558 // Import argument types
1559 SmallVector<QualType, 4> ArgTypes;
1560 for (const auto &A : T->param_types()) {
1561 ExpectedType TyOrErr = import(A);
1562 if (!TyOrErr)
1563 return TyOrErr.takeError();
1564 ArgTypes.push_back(*TyOrErr);
1565 }
1566
1567 // Import exception types
1568 SmallVector<QualType, 4> ExceptionTypes;
1569 for (const auto &E : T->exceptions()) {
1570 ExpectedType TyOrErr = import(E);
1571 if (!TyOrErr)
1572 return TyOrErr.takeError();
1573 ExceptionTypes.push_back(*TyOrErr);
1574 }
1575
1576 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
1577 Error Err = Error::success();
1578 FunctionProtoType::ExtProtoInfo ToEPI;
1579 ToEPI.ExtInfo = FromEPI.ExtInfo;
1580 ToEPI.Variadic = FromEPI.Variadic;
1581 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1582 ToEPI.TypeQuals = FromEPI.TypeQuals;
1583 ToEPI.RefQualifier = FromEPI.RefQualifier;
1584 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1591 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1592
1593 if (Err)
1594 return std::move(Err);
1595
1596 return Importer.getToContext().getFunctionType(
1597 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1598}
1599
1600ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1601 const UnresolvedUsingType *T) {
1602 Error Err = Error::success();
1603 auto ToQualifier = importChecked(Err, T->getQualifier());
1604 auto *ToD = importChecked(Err, T->getDecl());
1605 if (Err)
1606 return std::move(Err);
1607
1609 return Importer.getToContext().getCanonicalUnresolvedUsingType(ToD);
1610 return Importer.getToContext().getUnresolvedUsingType(T->getKeyword(),
1611 ToQualifier, ToD);
1612}
1613
1614ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1615 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1616 if (!ToInnerTypeOrErr)
1617 return ToInnerTypeOrErr.takeError();
1618
1619 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1620}
1621
1623ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1624
1625 ExpectedType Pattern = import(T->getPattern());
1626 if (!Pattern)
1627 return Pattern.takeError();
1628 ExpectedExpr Index = import(T->getIndexExpr());
1629 if (!Index)
1630 return Index.takeError();
1631 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1632}
1633
1634ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1635 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1636 if (!ToDeclOrErr)
1637 return ToDeclOrErr.takeError();
1638
1639 auto ToQualifierOrErr = import(T->getQualifier());
1640 if (!ToQualifierOrErr)
1641 return ToQualifierOrErr.takeError();
1642
1643 ExpectedType ToUnderlyingTypeOrErr =
1644 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1645 if (!ToUnderlyingTypeOrErr)
1646 return ToUnderlyingTypeOrErr.takeError();
1647
1648 return Importer.getToContext().getTypedefType(
1649 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1650}
1651
1652ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1653 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1654 if (!ToExprOrErr)
1655 return ToExprOrErr.takeError();
1656 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1657}
1658
1659ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1660 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1661 if (!ToUnderlyingTypeOrErr)
1662 return ToUnderlyingTypeOrErr.takeError();
1663 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1664 T->getKind());
1665}
1666
1667ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1668 Error Err = Error::success();
1669 auto ToQualifier = importChecked(Err, T->getQualifier());
1670 auto *ToD = importChecked(Err, T->getDecl());
1671 QualType ToT = importChecked(Err, T->desugar());
1672 if (Err)
1673 return std::move(Err);
1674 return Importer.getToContext().getUsingType(T->getKeyword(), ToQualifier, ToD,
1675 ToT);
1676}
1677
1678ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1679 // FIXME: Make sure that the "to" context supports C++0x!
1680 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1681 if (!ToExprOrErr)
1682 return ToExprOrErr.takeError();
1683
1684 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1685 if (!ToUnderlyingTypeOrErr)
1686 return ToUnderlyingTypeOrErr.takeError();
1687
1688 return Importer.getToContext().getDecltypeType(
1689 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1690}
1691
1693ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1694 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1695 if (!ToBaseTypeOrErr)
1696 return ToBaseTypeOrErr.takeError();
1697
1698 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1699 if (!ToUnderlyingTypeOrErr)
1700 return ToUnderlyingTypeOrErr.takeError();
1701
1702 return Importer.getToContext().getUnaryTransformType(
1703 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1704}
1705
1706ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1707 // FIXME: Make sure that the "to" context supports C++11!
1708 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1709 if (!ToDeducedTypeOrErr)
1710 return ToDeducedTypeOrErr.takeError();
1711
1712 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1713 if (!ToTypeConstraintConcept)
1714 return ToTypeConstraintConcept.takeError();
1715
1716 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1717 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1718 ToTemplateArgs))
1719 return std::move(Err);
1720
1721 return Importer.getToContext().getAutoType(
1722 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1723 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1724 ToTemplateArgs);
1725}
1726
1727ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1728 const DeducedTemplateSpecializationType *T) {
1729 // FIXME: Make sure that the "to" context supports C++17!
1730 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1731 if (!ToTemplateNameOrErr)
1732 return ToTemplateNameOrErr.takeError();
1733 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1734 if (!ToDeducedTypeOrErr)
1735 return ToDeducedTypeOrErr.takeError();
1736
1737 return Importer.getToContext().getDeducedTemplateSpecializationType(
1738 T->getKeyword(), *ToTemplateNameOrErr, *ToDeducedTypeOrErr,
1739 T->isDependentType());
1740}
1741
1742ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1743 TagDecl *DeclForType = T->getDecl();
1744 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1745 if (!ToDeclOrErr)
1746 return ToDeclOrErr.takeError();
1747
1748 // If there is a definition of the 'OriginalDecl', it should be imported to
1749 // have all information for the type in the "To" AST. (In some cases no
1750 // other reference may exist to the definition decl and it would not be
1751 // imported otherwise.)
1752 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1753 if (!ToDefDeclOrErr)
1754 return ToDefDeclOrErr.takeError();
1755
1757 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1758
1759 auto ToQualifierOrErr = import(T->getQualifier());
1760 if (!ToQualifierOrErr)
1761 return ToQualifierOrErr.takeError();
1762
1763 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1764 *ToDeclOrErr, T->isTagOwned());
1765}
1766
1767ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1768 return VisitTagType(T);
1769}
1770
1771ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1772 return VisitTagType(T);
1773}
1774
1776ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1777 return VisitTagType(T);
1778}
1779
1780ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1781 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1782 if (!ToModifiedTypeOrErr)
1783 return ToModifiedTypeOrErr.takeError();
1784 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1785 if (!ToEquivalentTypeOrErr)
1786 return ToEquivalentTypeOrErr.takeError();
1787
1788 return Importer.getToContext().getAttributedType(
1789 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1790 T->getAttr());
1791}
1792
1794ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1795 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1796 if (!ToWrappedTypeOrErr)
1797 return ToWrappedTypeOrErr.takeError();
1798
1799 Error Err = Error::success();
1800 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1801
1802 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1803 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1804 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1805 if (!ToDeclOrErr)
1806 return ToDeclOrErr.takeError();
1807 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1808 }
1809
1810 return Importer.getToContext().getCountAttributedType(
1811 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1812 ArrayRef(CoupledDecls));
1813}
1814
1815ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1816 const TemplateTypeParmType *T) {
1817 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1818 if (!ToDeclOrErr)
1819 return ToDeclOrErr.takeError();
1820
1821 return Importer.getToContext().getTemplateTypeParmType(
1822 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1823}
1824
1825ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1826 const SubstTemplateTypeParmType *T) {
1827 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1828 if (!ReplacedOrErr)
1829 return ReplacedOrErr.takeError();
1830
1831 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1832 if (!ToReplacementTypeOrErr)
1833 return ToReplacementTypeOrErr.takeError();
1834
1835 return Importer.getToContext().getSubstTemplateTypeParmType(
1836 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1837 T->getFinal());
1838}
1839
1840ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1841 const SubstTemplateTypeParmPackType *T) {
1842 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1843 if (!ReplacedOrErr)
1844 return ReplacedOrErr.takeError();
1845
1846 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1847 if (!ToArgumentPack)
1848 return ToArgumentPack.takeError();
1849
1850 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1851 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1852}
1853
1854ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1855 const SubstBuiltinTemplatePackType *T) {
1856 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1857 if (!ToArgumentPack)
1858 return ToArgumentPack.takeError();
1859 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1860}
1861
1862ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1863 const TemplateSpecializationType *T) {
1864 auto ToTemplateOrErr = import(T->getTemplateName());
1865 if (!ToTemplateOrErr)
1866 return ToTemplateOrErr.takeError();
1867
1868 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1869 if (Error Err =
1870 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1871 return std::move(Err);
1872
1873 ExpectedType ToUnderlyingOrErr =
1874 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1875 if (!ToUnderlyingOrErr)
1876 return ToUnderlyingOrErr.takeError();
1877 return Importer.getToContext().getTemplateSpecializationType(
1878 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1879 *ToUnderlyingOrErr);
1880}
1881
1883ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1884 ExpectedType ToPatternOrErr = import(T->getPattern());
1885 if (!ToPatternOrErr)
1886 return ToPatternOrErr.takeError();
1887
1888 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1889 T->getNumExpansions(),
1890 /*ExpactPack=*/false);
1891}
1892
1894ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1895 auto ToQualifierOrErr = import(T->getQualifier());
1896 if (!ToQualifierOrErr)
1897 return ToQualifierOrErr.takeError();
1898
1899 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1900 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1901 *ToQualifierOrErr, Name);
1902}
1903
1905ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1906 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1907 if (!ToDeclOrErr)
1908 return ToDeclOrErr.takeError();
1909
1910 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1911}
1912
1913ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1914 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1915 if (!ToBaseTypeOrErr)
1916 return ToBaseTypeOrErr.takeError();
1917
1918 SmallVector<QualType, 4> TypeArgs;
1919 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1920 if (ExpectedType TyOrErr = import(TypeArg))
1921 TypeArgs.push_back(*TyOrErr);
1922 else
1923 return TyOrErr.takeError();
1924 }
1925
1926 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1927 for (auto *P : T->quals()) {
1928 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1929 Protocols.push_back(*ProtocolOrErr);
1930 else
1931 return ProtocolOrErr.takeError();
1932
1933 }
1934
1935 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1936 Protocols,
1937 T->isKindOfTypeAsWritten());
1938}
1939
1941ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1942 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1943 if (!ToPointeeTypeOrErr)
1944 return ToPointeeTypeOrErr.takeError();
1945
1946 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1947}
1948
1950ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1951 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1952 if (!ToUnderlyingTypeOrErr)
1953 return ToUnderlyingTypeOrErr.takeError();
1954
1955 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1956 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1957 ToIdentifier);
1958}
1959
1960ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1961 Error Err = Error::success();
1962 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1963 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1964 if (Err)
1965 return std::move(Err);
1966
1967 return Importer.getToContext().getAdjustedType(ToOriginalType,
1968 ToAdjustedType);
1969}
1970
1971ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1972 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1973 T->getNumBits());
1974}
1975
1976ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1977 const clang::BTFTagAttributedType *T) {
1978 Error Err = Error::success();
1979 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1980 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1981 if (Err)
1982 return std::move(Err);
1983
1984 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1985 ToWrappedType);
1986}
1987
1988ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
1989 const clang::HLSLAttributedResourceType *T) {
1990 Error Err = Error::success();
1991 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
1992 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1993 QualType ToContainedType = importChecked(Err, T->getContainedType());
1994 if (Err)
1995 return std::move(Err);
1996
1997 return Importer.getToContext().getHLSLAttributedResourceType(
1998 ToWrappedType, ToContainedType, ToAttrs);
1999}
2000
2001ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2002 const clang::HLSLInlineSpirvType *T) {
2003 Error Err = Error::success();
2004
2005 uint32_t ToOpcode = T->getOpcode();
2006 uint32_t ToSize = T->getSize();
2007 uint32_t ToAlignment = T->getAlignment();
2008
2010
2011 for (auto &Operand : T->getOperands()) {
2012 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2013
2014 switch (Operand.getKind()) {
2015 case SpirvOperandKind::ConstantId:
2016 ToOperands.push_back(SpirvOperand::createConstant(
2017 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2018 break;
2019 case SpirvOperandKind::Literal:
2020 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2021 break;
2022 case SpirvOperandKind::TypeId:
2023 ToOperands.push_back(SpirvOperand::createType(
2024 importChecked(Err, Operand.getResultType())));
2025 break;
2026 default:
2027 llvm_unreachable("Invalid SpirvOperand kind");
2028 }
2029
2030 if (Err)
2031 return std::move(Err);
2032 }
2033
2034 return Importer.getToContext().getHLSLInlineSpirvType(
2035 ToOpcode, ToSize, ToAlignment, ToOperands);
2036}
2037
2038ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2039 const clang::ConstantMatrixType *T) {
2040 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2041 if (!ToElementTypeOrErr)
2042 return ToElementTypeOrErr.takeError();
2043
2044 return Importer.getToContext().getConstantMatrixType(
2045 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2046}
2047
2048ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2049 const clang::DependentAddressSpaceType *T) {
2050 Error Err = Error::success();
2051 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2052 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2053 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2054 if (Err)
2055 return std::move(Err);
2056
2057 return Importer.getToContext().getDependentAddressSpaceType(
2058 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2059}
2060
2061ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2062 const clang::DependentBitIntType *T) {
2063 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2064 if (!ToNumBitsExprOrErr)
2065 return ToNumBitsExprOrErr.takeError();
2066 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2067 *ToNumBitsExprOrErr);
2068}
2069
2070ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2071 const clang::PredefinedSugarType *T) {
2072 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2073}
2074
2075ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2076 const clang::DependentSizedMatrixType *T) {
2077 Error Err = Error::success();
2078 QualType ToElementType = importChecked(Err, T->getElementType());
2079 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2080 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2081 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2082 if (Err)
2083 return std::move(Err);
2084
2085 return Importer.getToContext().getDependentSizedMatrixType(
2086 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2087}
2088
2089ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2090 const clang::DependentVectorType *T) {
2091 Error Err = Error::success();
2092 QualType ToElementType = importChecked(Err, T->getElementType());
2093 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2094 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2095 if (Err)
2096 return std::move(Err);
2097
2098 return Importer.getToContext().getDependentVectorType(
2099 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2100}
2101
2102ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2103 const clang::ObjCTypeParamType *T) {
2104 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2105 if (!ToDeclOrErr)
2106 return ToDeclOrErr.takeError();
2107
2109 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2110 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2111 if (!ToProtocolOrErr)
2112 return ToProtocolOrErr.takeError();
2113 ToProtocols.push_back(*ToProtocolOrErr);
2114 }
2115
2116 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2117 ToProtocols);
2118}
2119
2120ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2121 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2122 if (!ToElementTypeOrErr)
2123 return ToElementTypeOrErr.takeError();
2124
2125 ASTContext &ToCtx = Importer.getToContext();
2126 if (T->isReadOnly())
2127 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2128 else
2129 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2130}
2131
2132//----------------------------------------------------------------------------
2133// Import Declarations
2134//----------------------------------------------------------------------------
2136 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2137 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2138 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2139 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2140 // FIXME: We could support these constructs by importing a different type of
2141 // this parameter and by importing the original type of the parameter only
2142 // after the FunctionDecl is created. See
2143 // VisitFunctionDecl::UsedDifferentProtoType.
2144 DeclContext *OrigDC = D->getDeclContext();
2145 FunctionDecl *FunDecl;
2146 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2147 FunDecl->hasBody()) {
2148 auto getLeafPointeeType = [](const Type *T) {
2149 while (T->isPointerType() || T->isArrayType()) {
2150 T = T->getPointeeOrArrayElementType();
2151 }
2152 return T;
2153 };
2154 for (const ParmVarDecl *P : FunDecl->parameters()) {
2155 const Type *LeafT =
2156 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2157 auto *RT = dyn_cast<RecordType>(LeafT);
2158 if (RT && RT->getDecl() == D) {
2159 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2160 << D->getDeclKindName();
2161 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2162 }
2163 }
2164 }
2165
2166 // Import the context of this declaration.
2167 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2168 return Err;
2169
2170 // Import the name of this declaration.
2171 if (Error Err = importInto(Name, D->getDeclName()))
2172 return Err;
2173
2174 // Import the location of this declaration.
2175 if (Error Err = importInto(Loc, D->getLocation()))
2176 return Err;
2177
2178 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2179 if (ToD)
2180 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2181 return Err;
2182
2183 return Error::success();
2184}
2185
2187 NamedDecl *&ToD, SourceLocation &Loc) {
2188
2189 // Import the name of this declaration.
2190 if (Error Err = importInto(Name, D->getDeclName()))
2191 return Err;
2192
2193 // Import the location of this declaration.
2194 if (Error Err = importInto(Loc, D->getLocation()))
2195 return Err;
2196
2197 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2198 if (ToD)
2199 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2200 return Err;
2201
2202 return Error::success();
2203}
2204
2206 if (!FromD)
2207 return Error::success();
2208
2209 if (!ToD)
2210 if (Error Err = importInto(ToD, FromD))
2211 return Err;
2212
2213 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2214 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2215 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2216 !ToRecord->getDefinition()) {
2217 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2218 return Err;
2219 }
2220 }
2221 return Error::success();
2222 }
2223
2224 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2225 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2226 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2227 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2228 return Err;
2229 }
2230 }
2231 return Error::success();
2232 }
2233
2234 return Error::success();
2235}
2236
2237Error
2239 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2240 // NOTE: To.Name and To.Loc are already imported.
2241 // We only have to import To.LocInfo.
2242 switch (To.getName().getNameKind()) {
2249 return Error::success();
2250
2252 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2253 To.setCXXOperatorNameRange(*ToRangeOrErr);
2254 else
2255 return ToRangeOrErr.takeError();
2256 return Error::success();
2257 }
2259 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2260 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2261 else
2262 return LocOrErr.takeError();
2263 return Error::success();
2264 }
2268 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2269 To.setNamedTypeInfo(*ToTInfoOrErr);
2270 else
2271 return ToTInfoOrErr.takeError();
2272 return Error::success();
2273 }
2274 }
2275 llvm_unreachable("Unknown name kind.");
2276}
2277
2278Error
2280 if (Importer.isMinimalImport() && !ForceImport) {
2281 auto ToDCOrErr = Importer.ImportContext(FromDC);
2282 return ToDCOrErr.takeError();
2283 }
2284
2285 // We use strict error handling in case of records and enums, but not
2286 // with e.g. namespaces.
2287 //
2288 // FIXME Clients of the ASTImporter should be able to choose an
2289 // appropriate error handling strategy for their needs. For instance,
2290 // they may not want to mark an entire namespace as erroneous merely
2291 // because there is an ODR error with two typedefs. As another example,
2292 // the client may allow EnumConstantDecls with same names but with
2293 // different values in two distinct translation units.
2294 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2295
2296 auto MightNeedReordering = [](const Decl *D) {
2298 };
2299
2300 // Import everything that might need reordering first.
2301 Error ChildErrors = Error::success();
2302 for (auto *From : FromDC->decls()) {
2303 if (!MightNeedReordering(From))
2304 continue;
2305
2306 ExpectedDecl ImportedOrErr = import(From);
2307
2308 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2309 // want to make sure that we are also completing each FieldDecl. There
2310 // are currently cases where this does not happen and this is correctness
2311 // fix since operations such as code generation will expect this to be so.
2312 if (!ImportedOrErr) {
2313 HandleChildErrors.handleChildImportResult(ChildErrors,
2314 ImportedOrErr.takeError());
2315 continue;
2316 }
2317 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2318 Decl *ImportedDecl = *ImportedOrErr;
2319 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2320 if (FieldFrom && FieldTo) {
2321 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2322 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2323 }
2324 }
2325
2326 // We reorder declarations in RecordDecls because they may have another order
2327 // in the "to" context than they have in the "from" context. This may happen
2328 // e.g when we import a class like this:
2329 // struct declToImport {
2330 // int a = c + b;
2331 // int b = 1;
2332 // int c = 2;
2333 // };
2334 // During the import of `a` we import first the dependencies in sequence,
2335 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2336 // first removing the already imported members and then adding them in the
2337 // order as they appear in the "from" context.
2338 //
2339 // Keeping field order is vital because it determines structure layout.
2340 //
2341 // Here and below, we cannot call field_begin() method and its callers on
2342 // ToDC if it has an external storage. Calling field_begin() will
2343 // automatically load all the fields by calling
2344 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2345 // call ASTImporter::Import(). This is because the ExternalASTSource
2346 // interface in LLDB is implemented by the means of the ASTImporter. However,
2347 // calling an import at this point would result in an uncontrolled import, we
2348 // must avoid that.
2349
2350 auto ToDCOrErr = Importer.ImportContext(FromDC);
2351 if (!ToDCOrErr) {
2352 consumeError(std::move(ChildErrors));
2353 return ToDCOrErr.takeError();
2354 }
2355
2356 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2357 DeclContext *ToDC = *ToDCOrErr;
2358 // Remove all declarations, which may be in wrong order in the
2359 // lexical DeclContext and then add them in the proper order.
2360 for (auto *D : FromRD->decls()) {
2361 if (!MightNeedReordering(D))
2362 continue;
2363
2364 assert(D && "DC contains a null decl");
2365 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2366 // Remove only the decls which we successfully imported.
2367 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2368 // Remove the decl from its wrong place in the linked list.
2369 ToDC->removeDecl(ToD);
2370 // Add the decl to the end of the linked list.
2371 // This time it will be at the proper place because the enclosing for
2372 // loop iterates in the original (good) order of the decls.
2373 ToDC->addDeclInternal(ToD);
2374 }
2375 }
2376 }
2377
2378 // Import everything else.
2379 for (auto *From : FromDC->decls()) {
2380 if (MightNeedReordering(From))
2381 continue;
2382
2383 ExpectedDecl ImportedOrErr = import(From);
2384 if (!ImportedOrErr)
2385 HandleChildErrors.handleChildImportResult(ChildErrors,
2386 ImportedOrErr.takeError());
2387 }
2388
2389 return ChildErrors;
2390}
2391
2393 const FieldDecl *To) {
2394 RecordDecl *FromRecordDecl = nullptr;
2395 RecordDecl *ToRecordDecl = nullptr;
2396 // If we have a field that is an ArrayType we need to check if the array
2397 // element is a RecordDecl and if so we need to import the definition.
2398 QualType FromType = From->getType();
2399 QualType ToType = To->getType();
2400 if (FromType->isArrayType()) {
2401 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2402 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2403 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2404 }
2405
2406 if (!FromRecordDecl || !ToRecordDecl) {
2407 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2408 const RecordType *RecordTo = ToType->getAs<RecordType>();
2409
2410 if (RecordFrom && RecordTo) {
2411 FromRecordDecl = RecordFrom->getDecl();
2412 ToRecordDecl = RecordTo->getDecl();
2413 }
2414 }
2415
2416 if (FromRecordDecl && ToRecordDecl) {
2417 if (FromRecordDecl->isCompleteDefinition() &&
2418 !ToRecordDecl->isCompleteDefinition())
2419 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2420 }
2421
2422 return Error::success();
2423}
2424
2426 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2427 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2428 if (!ToDCOrErr)
2429 return ToDCOrErr.takeError();
2430 ToDC = *ToDCOrErr;
2431
2432 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2433 auto ToLexicalDCOrErr = Importer.ImportContext(
2434 FromD->getLexicalDeclContext());
2435 if (!ToLexicalDCOrErr)
2436 return ToLexicalDCOrErr.takeError();
2437 ToLexicalDC = *ToLexicalDCOrErr;
2438 } else
2439 ToLexicalDC = ToDC;
2440
2441 return Error::success();
2442}
2443
2445 const CXXRecordDecl *From, CXXRecordDecl *To) {
2446 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2447 "Import implicit methods to or from non-definition");
2448
2449 for (CXXMethodDecl *FromM : From->methods())
2450 if (FromM->isImplicit()) {
2451 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2452 if (!ToMOrErr)
2453 return ToMOrErr.takeError();
2454 }
2455
2456 return Error::success();
2457}
2458
2460 ASTImporter &Importer) {
2461 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2462 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2464 else
2465 return ToTypedefOrErr.takeError();
2466 }
2467 return Error::success();
2468}
2469
2471 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2472 auto DefinitionCompleter = [To]() {
2473 // There are cases in LLDB when we first import a class without its
2474 // members. The class will have DefinitionData, but no members. Then,
2475 // importDefinition is called from LLDB, which tries to get the members, so
2476 // when we get here, the class already has the DefinitionData set, so we
2477 // must unset the CompleteDefinition here to be able to complete again the
2478 // definition.
2479 To->setCompleteDefinition(false);
2480 To->completeDefinition();
2481 };
2482
2483 if (To->getDefinition() || To->isBeingDefined()) {
2484 if (Kind == IDK_Everything ||
2485 // In case of lambdas, the class already has a definition ptr set, but
2486 // the contained decls are not imported yet. Also, isBeingDefined was
2487 // set in CXXRecordDecl::CreateLambda. We must import the contained
2488 // decls here and finish the definition.
2489 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2490 if (To->isLambda()) {
2491 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2493 ToCaptures.reserve(FromCXXRD->capture_size());
2494 for (const auto &FromCapture : FromCXXRD->captures()) {
2495 if (auto ToCaptureOrErr = import(FromCapture))
2496 ToCaptures.push_back(*ToCaptureOrErr);
2497 else
2498 return ToCaptureOrErr.takeError();
2499 }
2500 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2501 ToCaptures);
2502 }
2503
2504 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2505 // Finish the definition of the lambda, set isBeingDefined to false.
2506 if (To->isLambda())
2507 DefinitionCompleter();
2508 return Result;
2509 }
2510
2511 return Error::success();
2512 }
2513
2514 To->startDefinition();
2515 // Set the definition to complete even if it is really not complete during
2516 // import. Some AST constructs (expressions) require the record layout
2517 // to be calculated (see 'clang::computeDependence') at the time they are
2518 // constructed. Import of such AST node is possible during import of the
2519 // same record, there is no way to have a completely defined record (all
2520 // fields imported) at that time without multiple AST import passes.
2521 if (!Importer.isMinimalImport())
2522 To->setCompleteDefinition(true);
2523 // Complete the definition even if error is returned.
2524 // The RecordDecl may be already part of the AST so it is better to
2525 // have it in complete state even if something is wrong with it.
2526 auto DefinitionCompleterScopeExit =
2527 llvm::make_scope_exit(DefinitionCompleter);
2528
2529 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2530 return Err;
2531
2532 // Add base classes.
2533 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2534 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2535 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2536
2537 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2538 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2539
2540 #define FIELD(Name, Width, Merge) \
2541 ToData.Name = FromData.Name;
2542 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2543
2544 // Copy over the data stored in RecordDeclBits
2545 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2546
2548 for (const auto &Base1 : FromCXX->bases()) {
2549 ExpectedType TyOrErr = import(Base1.getType());
2550 if (!TyOrErr)
2551 return TyOrErr.takeError();
2552
2553 SourceLocation EllipsisLoc;
2554 if (Base1.isPackExpansion()) {
2555 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2556 EllipsisLoc = *LocOrErr;
2557 else
2558 return LocOrErr.takeError();
2559 }
2560
2561 // Ensure that we have a definition for the base.
2562 if (Error Err =
2563 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2564 return Err;
2565
2566 auto RangeOrErr = import(Base1.getSourceRange());
2567 if (!RangeOrErr)
2568 return RangeOrErr.takeError();
2569
2570 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2571 if (!TSIOrErr)
2572 return TSIOrErr.takeError();
2573
2574 Bases.push_back(
2575 new (Importer.getToContext()) CXXBaseSpecifier(
2576 *RangeOrErr,
2577 Base1.isVirtual(),
2578 Base1.isBaseOfClass(),
2579 Base1.getAccessSpecifierAsWritten(),
2580 *TSIOrErr,
2581 EllipsisLoc));
2582 }
2583 if (!Bases.empty())
2584 ToCXX->setBases(Bases.data(), Bases.size());
2585 }
2586
2587 if (shouldForceImportDeclContext(Kind)) {
2588 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2589 return Err;
2590 }
2591
2592 return Error::success();
2593}
2594
2596 if (To->getAnyInitializer())
2597 return Error::success();
2598
2599 Expr *FromInit = From->getInit();
2600 if (!FromInit)
2601 return Error::success();
2602
2603 ExpectedExpr ToInitOrErr = import(FromInit);
2604 if (!ToInitOrErr)
2605 return ToInitOrErr.takeError();
2606
2607 To->setInit(*ToInitOrErr);
2608 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2609 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2610 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2611 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2612 // FIXME: Also import the initializer value.
2613 }
2614
2615 // FIXME: Other bits to merge?
2616 return Error::success();
2617}
2618
2620 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2621 if (To->getDefinition() || To->isBeingDefined()) {
2622 if (Kind == IDK_Everything)
2623 return ImportDeclContext(From, /*ForceImport=*/true);
2624 return Error::success();
2625 }
2626
2627 To->startDefinition();
2628
2629 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2630 return Err;
2631
2632 ExpectedType ToTypeOrErr =
2633 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2634 if (!ToTypeOrErr)
2635 return ToTypeOrErr.takeError();
2636
2637 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2638 if (!ToPromotionTypeOrErr)
2639 return ToPromotionTypeOrErr.takeError();
2640
2642 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2643 return Err;
2644
2645 // FIXME: we might need to merge the number of positive or negative bits
2646 // if the enumerator lists don't match.
2647 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2648 From->getNumPositiveBits(),
2649 From->getNumNegativeBits());
2650 return Error::success();
2651}
2652
2656 for (const auto &Arg : FromArgs) {
2657 if (auto ToOrErr = import(Arg))
2658 ToArgs.push_back(*ToOrErr);
2659 else
2660 return ToOrErr.takeError();
2661 }
2662
2663 return Error::success();
2664}
2665
2666// FIXME: Do not forget to remove this and use only 'import'.
2669 return import(From);
2670}
2671
2672template <typename InContainerTy>
2674 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2675 for (const auto &FromLoc : Container) {
2676 if (auto ToLocOrErr = import(FromLoc))
2677 ToTAInfo.addArgument(*ToLocOrErr);
2678 else
2679 return ToLocOrErr.takeError();
2680 }
2681 return Error::success();
2682}
2683
2689
2690bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2691 bool IgnoreTemplateParmDepth) {
2692 // Eliminate a potential failure point where we attempt to re-import
2693 // something we're trying to import while completing ToRecord.
2694 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2695 if (ToOrigin) {
2696 To = ToOrigin;
2697 }
2698
2700 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2701 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2703 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2704 IgnoreTemplateParmDepth);
2705 return Ctx.IsEquivalent(From, To);
2706}
2707
2709 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2710 << D->getDeclKindName();
2711 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2712}
2713
2715 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2716 << D->getDeclKindName();
2717 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2718}
2719
2721 // Import the context of this declaration.
2722 DeclContext *DC, *LexicalDC;
2723 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2724 return std::move(Err);
2725
2726 // Import the location of this declaration.
2727 ExpectedSLoc LocOrErr = import(D->getLocation());
2728 if (!LocOrErr)
2729 return LocOrErr.takeError();
2730
2731 EmptyDecl *ToD;
2732 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2733 return ToD;
2734
2735 ToD->setLexicalDeclContext(LexicalDC);
2736 LexicalDC->addDeclInternal(ToD);
2737 return ToD;
2738}
2739
2741 TranslationUnitDecl *ToD =
2742 Importer.getToContext().getTranslationUnitDecl();
2743
2744 Importer.MapImported(D, ToD);
2745
2746 return ToD;
2747}
2748
2750 DeclContext *DC, *LexicalDC;
2751 DeclarationName Name;
2752 SourceLocation Loc;
2753 NamedDecl *ToND;
2754 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2755 return std::move(Err);
2756 if (ToND)
2757 return ToND;
2758
2759 BindingDecl *ToD;
2760 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2761 Name.getAsIdentifierInfo(), D->getType()))
2762 return ToD;
2763
2764 Error Err = Error::success();
2765 QualType ToType = importChecked(Err, D->getType());
2766 Expr *ToBinding = importChecked(Err, D->getBinding());
2767 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2768 if (Err)
2769 return std::move(Err);
2770
2771 ToD->setBinding(ToType, ToBinding);
2772 ToD->setDecomposedDecl(ToDecomposedDecl);
2773 addDeclToContexts(D, ToD);
2774
2775 return ToD;
2776}
2777
2779 ExpectedSLoc LocOrErr = import(D->getLocation());
2780 if (!LocOrErr)
2781 return LocOrErr.takeError();
2782 auto ColonLocOrErr = import(D->getColonLoc());
2783 if (!ColonLocOrErr)
2784 return ColonLocOrErr.takeError();
2785
2786 // Import the context of this declaration.
2787 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2788 if (!DCOrErr)
2789 return DCOrErr.takeError();
2790 DeclContext *DC = *DCOrErr;
2791
2792 AccessSpecDecl *ToD;
2793 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2794 DC, *LocOrErr, *ColonLocOrErr))
2795 return ToD;
2796
2797 // Lexical DeclContext and Semantic DeclContext
2798 // is always the same for the accessSpec.
2799 ToD->setLexicalDeclContext(DC);
2800 DC->addDeclInternal(ToD);
2801
2802 return ToD;
2803}
2804
2806 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2807 if (!DCOrErr)
2808 return DCOrErr.takeError();
2809 DeclContext *DC = *DCOrErr;
2810 DeclContext *LexicalDC = DC;
2811
2812 Error Err = Error::success();
2813 auto ToLocation = importChecked(Err, D->getLocation());
2814 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2815 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2816 auto ToMessage = importChecked(Err, D->getMessage());
2817 if (Err)
2818 return std::move(Err);
2819
2820 StaticAssertDecl *ToD;
2821 if (GetImportedOrCreateDecl(
2822 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2823 ToRParenLoc, D->isFailed()))
2824 return ToD;
2825
2826 ToD->setLexicalDeclContext(LexicalDC);
2827 LexicalDC->addDeclInternal(ToD);
2828 return ToD;
2829}
2830
2832 // Import the major distinguishing characteristics of this namespace.
2833 DeclContext *DC, *LexicalDC;
2834 DeclarationName Name;
2835 SourceLocation Loc;
2836 NamedDecl *ToD;
2837 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2838 return std::move(Err);
2839 if (ToD)
2840 return ToD;
2841
2842 NamespaceDecl *MergeWithNamespace = nullptr;
2843 if (!Name) {
2844 // This is an anonymous namespace. Adopt an existing anonymous
2845 // namespace if we can.
2846 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2847 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2848 MergeWithNamespace = TU->getAnonymousNamespace();
2849 else
2850 MergeWithNamespace =
2851 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2852 } else {
2853 SmallVector<NamedDecl *, 4> ConflictingDecls;
2854 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2855 for (auto *FoundDecl : FoundDecls) {
2856 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2857 continue;
2858
2859 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2860 MergeWithNamespace = FoundNS;
2861 ConflictingDecls.clear();
2862 break;
2863 }
2864
2865 ConflictingDecls.push_back(FoundDecl);
2866 }
2867
2868 if (!ConflictingDecls.empty()) {
2869 ExpectedName NameOrErr = Importer.HandleNameConflict(
2870 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2871 ConflictingDecls.size());
2872 if (NameOrErr)
2873 Name = NameOrErr.get();
2874 else
2875 return NameOrErr.takeError();
2876 }
2877 }
2878
2879 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2880 if (!BeginLocOrErr)
2881 return BeginLocOrErr.takeError();
2882 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2883 if (!RBraceLocOrErr)
2884 return RBraceLocOrErr.takeError();
2885
2886 // Create the "to" namespace, if needed.
2887 NamespaceDecl *ToNamespace = MergeWithNamespace;
2888 if (!ToNamespace) {
2889 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2890 D->isInline(), *BeginLocOrErr, Loc,
2891 Name.getAsIdentifierInfo(),
2892 /*PrevDecl=*/nullptr, D->isNested()))
2893 return ToNamespace;
2894 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2895 ToNamespace->setLexicalDeclContext(LexicalDC);
2896 LexicalDC->addDeclInternal(ToNamespace);
2897
2898 // If this is an anonymous namespace, register it as the anonymous
2899 // namespace within its context.
2900 if (!Name) {
2901 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2902 TU->setAnonymousNamespace(ToNamespace);
2903 else
2904 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2905 }
2906 }
2907 Importer.MapImported(D, ToNamespace);
2908
2909 if (Error Err = ImportDeclContext(D))
2910 return std::move(Err);
2911
2912 return ToNamespace;
2913}
2914
2916 // Import the major distinguishing characteristics of this namespace.
2917 DeclContext *DC, *LexicalDC;
2918 DeclarationName Name;
2919 SourceLocation Loc;
2920 NamedDecl *LookupD;
2921 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2922 return std::move(Err);
2923 if (LookupD)
2924 return LookupD;
2925
2926 // NOTE: No conflict resolution is done for namespace aliases now.
2927
2928 Error Err = Error::success();
2929 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2930 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2931 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2932 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2933 auto ToNamespace = importChecked(Err, D->getNamespace());
2934 if (Err)
2935 return std::move(Err);
2936
2937 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2938
2939 NamespaceAliasDecl *ToD;
2940 if (GetImportedOrCreateDecl(
2941 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2942 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2943 return ToD;
2944
2945 ToD->setLexicalDeclContext(LexicalDC);
2946 LexicalDC->addDeclInternal(ToD);
2947
2948 return ToD;
2949}
2950
2953 // Import the major distinguishing characteristics of this typedef.
2954 DeclarationName Name;
2955 SourceLocation Loc;
2956 NamedDecl *ToD;
2957 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2958 // is created.
2959 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2960 return std::move(Err);
2961 if (ToD)
2962 return ToD;
2963
2964 DeclContext *DC = cast_or_null<DeclContext>(
2965 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2966 DeclContext *LexicalDC =
2967 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2969
2970 // If this typedef is not in block scope, determine whether we've
2971 // seen a typedef with the same name (that we can merge with) or any
2972 // other entity by that name (which name lookup could conflict with).
2973 // Note: Repeated typedefs are not valid in C99:
2974 // 'typedef int T; typedef int T;' is invalid
2975 // We do not care about this now.
2976 if (DC && !DC->isFunctionOrMethod()) {
2977 SmallVector<NamedDecl *, 4> ConflictingDecls;
2978 unsigned IDNS = Decl::IDNS_Ordinary;
2979 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2980 for (auto *FoundDecl : FoundDecls) {
2981 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2982 continue;
2983 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2984 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2985 continue;
2986
2987 QualType FromUT = D->getUnderlyingType();
2988 QualType FoundUT = FoundTypedef->getUnderlyingType();
2989 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2990 // If the underlying declarations are unnamed records these can be
2991 // imported as different types. We should create a distinct typedef
2992 // node in this case.
2993 // If we found an existing underlying type with a record in a
2994 // different context (than the imported), this is already reason for
2995 // having distinct typedef nodes for these.
2996 // Again this can create situation like
2997 // 'typedef int T; typedef int T;' but this is hard to avoid without
2998 // a rename strategy at import.
2999 if (!FromUT.isNull() && !FoundUT.isNull()) {
3000 RecordDecl *FromR = FromUT->getAsRecordDecl();
3001 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3002 if (FromR && FoundR &&
3003 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3004 continue;
3005 }
3006 // If the "From" context has a complete underlying type but we
3007 // already have a complete underlying type then return with that.
3008 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3009 return Importer.MapImported(D, FoundTypedef);
3010 // FIXME Handle redecl chain. When you do that make consistent changes
3011 // in ASTImporterLookupTable too.
3012 } else {
3013 ConflictingDecls.push_back(FoundDecl);
3014 }
3015 }
3016 }
3017
3018 if (!ConflictingDecls.empty()) {
3019 ExpectedName NameOrErr = Importer.HandleNameConflict(
3020 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3021 if (NameOrErr)
3022 Name = NameOrErr.get();
3023 else
3024 return NameOrErr.takeError();
3025 }
3026 }
3027
3028 Error Err = Error::success();
3030 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3031 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3032 if (Err)
3033 return std::move(Err);
3034
3035 // Create the new typedef node.
3036 // FIXME: ToUnderlyingType is not used.
3037 (void)ToUnderlyingType;
3038 TypedefNameDecl *ToTypedef;
3039 if (IsAlias) {
3040 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3041 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3042 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3043 return ToTypedef;
3044 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3045 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3046 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3047 return ToTypedef;
3048
3049 // Import the DeclContext and set it to the Typedef.
3050 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3051 return std::move(Err);
3052 ToTypedef->setDeclContext(DC);
3053 ToTypedef->setLexicalDeclContext(LexicalDC);
3054 // Add to the lookupTable because we could not do that in MapImported.
3055 Importer.AddToLookupTable(ToTypedef);
3056
3057 ToTypedef->setAccess(D->getAccess());
3058
3059 // Templated declarations should not appear in DeclContext.
3060 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3061 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3062 LexicalDC->addDeclInternal(ToTypedef);
3063
3064 return ToTypedef;
3065}
3066
3070
3074
3077 // Import the major distinguishing characteristics of this typedef.
3078 DeclContext *DC, *LexicalDC;
3079 DeclarationName Name;
3080 SourceLocation Loc;
3081 NamedDecl *FoundD;
3082 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3083 return std::move(Err);
3084 if (FoundD)
3085 return FoundD;
3086
3087 // If this typedef is not in block scope, determine whether we've
3088 // seen a typedef with the same name (that we can merge with) or any
3089 // other entity by that name (which name lookup could conflict with).
3090 if (!DC->isFunctionOrMethod()) {
3091 SmallVector<NamedDecl *, 4> ConflictingDecls;
3092 unsigned IDNS = Decl::IDNS_Ordinary;
3093 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3094 for (auto *FoundDecl : FoundDecls) {
3095 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3096 continue;
3097 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3098 if (IsStructuralMatch(D, FoundAlias))
3099 return Importer.MapImported(D, FoundAlias);
3100 ConflictingDecls.push_back(FoundDecl);
3101 }
3102 }
3103
3104 if (!ConflictingDecls.empty()) {
3105 ExpectedName NameOrErr = Importer.HandleNameConflict(
3106 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3107 if (NameOrErr)
3108 Name = NameOrErr.get();
3109 else
3110 return NameOrErr.takeError();
3111 }
3112 }
3113
3114 Error Err = Error::success();
3115 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3116 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3117 if (Err)
3118 return std::move(Err);
3119
3120 TypeAliasTemplateDecl *ToAlias;
3121 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3122 Name, ToTemplateParameters, ToTemplatedDecl))
3123 return ToAlias;
3124
3125 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3126
3127 ToAlias->setAccess(D->getAccess());
3128 ToAlias->setLexicalDeclContext(LexicalDC);
3129 LexicalDC->addDeclInternal(ToAlias);
3130 if (DC != Importer.getToContext().getTranslationUnitDecl())
3131 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3132 return ToAlias;
3133}
3134
3136 // Import the major distinguishing characteristics of this label.
3137 DeclContext *DC, *LexicalDC;
3138 DeclarationName Name;
3139 SourceLocation Loc;
3140 NamedDecl *ToD;
3141 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3142 return std::move(Err);
3143 if (ToD)
3144 return ToD;
3145
3146 assert(LexicalDC->isFunctionOrMethod());
3147
3148 LabelDecl *ToLabel;
3149 if (D->isGnuLocal()) {
3150 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3151 if (!BeginLocOrErr)
3152 return BeginLocOrErr.takeError();
3153 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3154 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3155 return ToLabel;
3156
3157 } else {
3158 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3159 Name.getAsIdentifierInfo()))
3160 return ToLabel;
3161
3162 }
3163
3164 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3165 if (!ToStmtOrErr)
3166 return ToStmtOrErr.takeError();
3167
3168 ToLabel->setStmt(*ToStmtOrErr);
3169 ToLabel->setLexicalDeclContext(LexicalDC);
3170 LexicalDC->addDeclInternal(ToLabel);
3171 return ToLabel;
3172}
3173
3175 // Import the major distinguishing characteristics of this enum.
3176 DeclContext *DC, *LexicalDC;
3177 DeclarationName Name;
3178 SourceLocation Loc;
3179 NamedDecl *ToD;
3180 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3181 return std::move(Err);
3182 if (ToD)
3183 return ToD;
3184
3185 // Figure out what enum name we're looking for.
3186 unsigned IDNS = Decl::IDNS_Tag;
3187 DeclarationName SearchName = Name;
3188 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3189 if (Error Err = importInto(
3190 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3191 return std::move(Err);
3192 IDNS = Decl::IDNS_Ordinary;
3193 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3194 IDNS |= Decl::IDNS_Ordinary;
3195
3196 // We may already have an enum of the same name; try to find and match it.
3197 EnumDecl *PrevDecl = nullptr;
3198 if (!DC->isFunctionOrMethod()) {
3199 SmallVector<NamedDecl *, 4> ConflictingDecls;
3200 auto FoundDecls =
3201 Importer.findDeclsInToCtx(DC, SearchName);
3202 for (auto *FoundDecl : FoundDecls) {
3203 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3204 continue;
3205
3206 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3207 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3208 FoundDecl = Tag->getDecl();
3209 }
3210
3211 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3212 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3213 continue;
3214 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3215 EnumDecl *FoundDef = FoundEnum->getDefinition();
3216 if (D->isThisDeclarationADefinition() && FoundDef)
3217 return Importer.MapImported(D, FoundDef);
3218 PrevDecl = FoundEnum->getMostRecentDecl();
3219 break;
3220 }
3221 ConflictingDecls.push_back(FoundDecl);
3222 }
3223 }
3224
3225 // In case of unnamed enums, we try to find an existing similar one, if none
3226 // was found, perform the import always.
3227 // Structural in-equivalence is not detected in this way here, but it may
3228 // be found when the parent decl is imported (if the enum is part of a
3229 // class). To make this totally exact a more difficult solution is needed.
3230 if (SearchName && !ConflictingDecls.empty()) {
3231 ExpectedName NameOrErr = Importer.HandleNameConflict(
3232 SearchName, DC, IDNS, ConflictingDecls.data(),
3233 ConflictingDecls.size());
3234 if (NameOrErr)
3235 Name = NameOrErr.get();
3236 else
3237 return NameOrErr.takeError();
3238 }
3239 }
3240
3241 Error Err = Error::success();
3242 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3243 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3244 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3245 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3246 if (Err)
3247 return std::move(Err);
3248
3249 // Create the enum declaration.
3250 EnumDecl *D2;
3251 if (GetImportedOrCreateDecl(
3252 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3253 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3254 D->isScopedUsingClassTag(), D->isFixed()))
3255 return D2;
3256
3257 D2->setQualifierInfo(ToQualifierLoc);
3258 D2->setIntegerType(ToIntegerType);
3259 D2->setBraceRange(ToBraceRange);
3260 D2->setAccess(D->getAccess());
3261 D2->setLexicalDeclContext(LexicalDC);
3262 addDeclToContexts(D, D2);
3263
3265 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3266 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3267 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3268 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3269 else
3270 return ToInstOrErr.takeError();
3271 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3273 else
3274 return POIOrErr.takeError();
3275 }
3276
3277 // Import the definition
3278 if (D->isCompleteDefinition())
3279 if (Error Err = ImportDefinition(D, D2))
3280 return std::move(Err);
3281
3282 return D2;
3283}
3284
3286 bool IsFriendTemplate = false;
3287 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3288 IsFriendTemplate =
3289 DCXX->getDescribedClassTemplate() &&
3290 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3292 }
3293
3294 // Import the major distinguishing characteristics of this record.
3295 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3296 DeclarationName Name;
3297 SourceLocation Loc;
3298 NamedDecl *ToD = nullptr;
3299 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3300 return std::move(Err);
3301 if (ToD)
3302 return ToD;
3303
3304 // Figure out what structure name we're looking for.
3305 unsigned IDNS = Decl::IDNS_Tag;
3306 DeclarationName SearchName = Name;
3307 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3308 if (Error Err = importInto(
3309 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3310 return std::move(Err);
3311 IDNS = Decl::IDNS_Ordinary;
3312 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3314
3315 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3316 : DC->isDependentContext();
3317 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3318
3319 // We may already have a record of the same name; try to find and match it.
3320 RecordDecl *PrevDecl = nullptr;
3321 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3322 SmallVector<NamedDecl *, 4> ConflictingDecls;
3323 auto FoundDecls =
3324 Importer.findDeclsInToCtx(DC, SearchName);
3325 if (!FoundDecls.empty()) {
3326 // We're going to have to compare D against potentially conflicting Decls,
3327 // so complete it.
3330 }
3331
3332 for (auto *FoundDecl : FoundDecls) {
3333 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3334 continue;
3335
3336 Decl *Found = FoundDecl;
3337 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3338 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3339 Found = Tag->getDecl();
3340 }
3341
3342 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3343 // Do not emit false positive diagnostic in case of unnamed
3344 // struct/union and in case of anonymous structs. Would be false
3345 // because there may be several anonymous/unnamed structs in a class.
3346 // E.g. these are both valid:
3347 // struct A { // unnamed structs
3348 // struct { struct A *next; } entry0;
3349 // struct { struct A *next; } entry1;
3350 // };
3351 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3352 if (!SearchName)
3353 if (!IsStructuralMatch(D, FoundRecord, false))
3354 continue;
3355
3356 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3357 continue;
3358
3359 if (IsStructuralMatch(D, FoundRecord)) {
3360 RecordDecl *FoundDef = FoundRecord->getDefinition();
3361 if (D->isThisDeclarationADefinition() && FoundDef) {
3362 // FIXME: Structural equivalence check should check for same
3363 // user-defined methods.
3364 Importer.MapImported(D, FoundDef);
3365 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3366 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3367 assert(FoundCXX && "Record type mismatch");
3368
3369 if (!Importer.isMinimalImport())
3370 // FoundDef may not have every implicit method that D has
3371 // because implicit methods are created only if they are used.
3372 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3373 return std::move(Err);
3374 }
3375 // FIXME: We can return FoundDef here.
3376 }
3377 PrevDecl = FoundRecord->getMostRecentDecl();
3378 break;
3379 }
3380 ConflictingDecls.push_back(FoundDecl);
3381 } // kind is RecordDecl
3382 } // for
3383
3384 if (!ConflictingDecls.empty() && SearchName) {
3385 ExpectedName NameOrErr = Importer.HandleNameConflict(
3386 SearchName, DC, IDNS, ConflictingDecls.data(),
3387 ConflictingDecls.size());
3388 if (NameOrErr)
3389 Name = NameOrErr.get();
3390 else
3391 return NameOrErr.takeError();
3392 }
3393 }
3394
3395 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3396 if (!BeginLocOrErr)
3397 return BeginLocOrErr.takeError();
3398
3399 // Create the record declaration.
3400 RecordDecl *D2 = nullptr;
3401 CXXRecordDecl *D2CXX = nullptr;
3402 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3403 if (DCXX->isLambda()) {
3404 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3405 if (!TInfoOrErr)
3406 return TInfoOrErr.takeError();
3407 if (GetImportedOrCreateSpecialDecl(
3408 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3409 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3410 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3411 return D2CXX;
3412 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3413 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3414 if (!CDeclOrErr)
3415 return CDeclOrErr.takeError();
3416 Numbering.ContextDecl = *CDeclOrErr;
3417 D2CXX->setLambdaNumbering(Numbering);
3418 } else {
3419 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3420 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3421 Name.getAsIdentifierInfo(),
3422 cast_or_null<CXXRecordDecl>(PrevDecl)))
3423 return D2CXX;
3424 }
3425
3426 D2 = D2CXX;
3427 D2->setAccess(D->getAccess());
3428 D2->setLexicalDeclContext(LexicalDC);
3429 addDeclToContexts(D, D2);
3430
3431 if (ClassTemplateDecl *FromDescribed =
3432 DCXX->getDescribedClassTemplate()) {
3433 ClassTemplateDecl *ToDescribed;
3434 if (Error Err = importInto(ToDescribed, FromDescribed))
3435 return std::move(Err);
3436 D2CXX->setDescribedClassTemplate(ToDescribed);
3437 } else if (MemberSpecializationInfo *MemberInfo =
3438 DCXX->getMemberSpecializationInfo()) {
3440 MemberInfo->getTemplateSpecializationKind();
3442
3443 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3444 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3445 else
3446 return ToInstOrErr.takeError();
3447
3448 if (ExpectedSLoc POIOrErr =
3449 import(MemberInfo->getPointOfInstantiation()))
3451 *POIOrErr);
3452 else
3453 return POIOrErr.takeError();
3454 }
3455
3456 } else {
3457 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3458 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3459 Name.getAsIdentifierInfo(), PrevDecl))
3460 return D2;
3461 D2->setLexicalDeclContext(LexicalDC);
3462 addDeclToContexts(D, D2);
3463 }
3464
3465 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3466 D2->setBraceRange(*BraceRangeOrErr);
3467 else
3468 return BraceRangeOrErr.takeError();
3469 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3470 D2->setQualifierInfo(*QualifierLocOrErr);
3471 else
3472 return QualifierLocOrErr.takeError();
3473
3474 if (D->isAnonymousStructOrUnion())
3475 D2->setAnonymousStructOrUnion(true);
3476
3477 if (D->isCompleteDefinition())
3478 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3479 return std::move(Err);
3480
3481 return D2;
3482}
3483
3485 // Import the major distinguishing characteristics of this enumerator.
3486 DeclContext *DC, *LexicalDC;
3487 DeclarationName Name;
3488 SourceLocation Loc;
3489 NamedDecl *ToD;
3490 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3491 return std::move(Err);
3492 if (ToD)
3493 return ToD;
3494
3495 // Determine whether there are any other declarations with the same name and
3496 // in the same context.
3497 if (!LexicalDC->isFunctionOrMethod()) {
3498 SmallVector<NamedDecl *, 4> ConflictingDecls;
3499 unsigned IDNS = Decl::IDNS_Ordinary;
3500 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3501 for (auto *FoundDecl : FoundDecls) {
3502 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3503 continue;
3504
3505 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3506 if (IsStructuralMatch(D, FoundEnumConstant))
3507 return Importer.MapImported(D, FoundEnumConstant);
3508 ConflictingDecls.push_back(FoundDecl);
3509 }
3510 }
3511
3512 if (!ConflictingDecls.empty()) {
3513 ExpectedName NameOrErr = Importer.HandleNameConflict(
3514 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3515 if (NameOrErr)
3516 Name = NameOrErr.get();
3517 else
3518 return NameOrErr.takeError();
3519 }
3520 }
3521
3522 ExpectedType TypeOrErr = import(D->getType());
3523 if (!TypeOrErr)
3524 return TypeOrErr.takeError();
3525
3526 ExpectedExpr InitOrErr = import(D->getInitExpr());
3527 if (!InitOrErr)
3528 return InitOrErr.takeError();
3529
3530 EnumConstantDecl *ToEnumerator;
3531 if (GetImportedOrCreateDecl(
3532 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3533 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3534 return ToEnumerator;
3535
3536 ToEnumerator->setAccess(D->getAccess());
3537 ToEnumerator->setLexicalDeclContext(LexicalDC);
3538 LexicalDC->addDeclInternal(ToEnumerator);
3539 return ToEnumerator;
3540}
3541
3542template <typename DeclTy>
3544 DeclTy *ToD) {
3545 unsigned int Num = FromD->getNumTemplateParameterLists();
3546 if (Num == 0)
3547 return Error::success();
3549 for (unsigned int I = 0; I < Num; ++I)
3550 if (Expected<TemplateParameterList *> ToTPListOrErr =
3551 import(FromD->getTemplateParameterList(I)))
3552 ToTPLists[I] = *ToTPListOrErr;
3553 else
3554 return ToTPListOrErr.takeError();
3555 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3556 return Error::success();
3557}
3558
3560 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3561 switch (FromFD->getTemplatedKind()) {
3564 return Error::success();
3565
3567 if (Expected<FunctionDecl *> InstFDOrErr =
3568 import(FromFD->getInstantiatedFromDecl()))
3569 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3570 return Error::success();
3573
3574 if (Expected<FunctionDecl *> InstFDOrErr =
3575 import(FromFD->getInstantiatedFromMemberFunction()))
3576 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3577 else
3578 return InstFDOrErr.takeError();
3579
3580 if (ExpectedSLoc POIOrErr = import(
3583 else
3584 return POIOrErr.takeError();
3585
3586 return Error::success();
3587 }
3588
3590 auto FunctionAndArgsOrErr =
3592 if (!FunctionAndArgsOrErr)
3593 return FunctionAndArgsOrErr.takeError();
3594
3596 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3597
3598 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3599 TemplateArgumentListInfo ToTAInfo;
3600 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3601 if (FromTAArgsAsWritten)
3603 *FromTAArgsAsWritten, ToTAInfo))
3604 return Err;
3605
3606 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3607 if (!POIOrErr)
3608 return POIOrErr.takeError();
3609
3610 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3611 return Err;
3612
3613 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3614 ToFD->setFunctionTemplateSpecialization(
3615 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3616 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3617 return Error::success();
3618 }
3619
3621 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3622 UnresolvedSet<8> Candidates;
3623 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3624 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3625 Candidates.addDecl(*ToFTDOrErr);
3626 else
3627 return ToFTDOrErr.takeError();
3628 }
3629
3630 // Import TemplateArgumentListInfo.
3631 TemplateArgumentListInfo ToTAInfo;
3632 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3633 if (FromTAArgsAsWritten)
3634 if (Error Err =
3635 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3636 return Err;
3637
3639 Importer.getToContext(), Candidates,
3640 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3641 return Error::success();
3642 }
3643 }
3644 llvm_unreachable("All cases should be covered!");
3645}
3646
3649 auto FunctionAndArgsOrErr =
3651 if (!FunctionAndArgsOrErr)
3652 return FunctionAndArgsOrErr.takeError();
3653
3655 TemplateArgsTy ToTemplArgs;
3656 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3657 void *InsertPos = nullptr;
3658 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3659 return FoundSpec;
3660}
3661
3663 FunctionDecl *ToFD) {
3664 if (Stmt *FromBody = FromFD->getBody()) {
3665 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3666 ToFD->setBody(*ToBodyOrErr);
3667 else
3668 return ToBodyOrErr.takeError();
3669 }
3670 return Error::success();
3671}
3672
3673// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3674// which is equal to the given DC, or D is equal to DC.
3675static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3676 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3677 if (!DCi)
3678 DCi = D->getDeclContext();
3679 assert(DCi && "Declaration should have a context");
3680 while (DCi != D->getTranslationUnitDecl()) {
3681 if (DCi == DC)
3682 return true;
3683 DCi = DCi->getParent();
3684 }
3685 return false;
3686}
3687
3688// Check if there is a declaration that has 'DC' as parent context and is
3689// referenced from statement 'S' or one of its children. The search is done in
3690// BFS order through children of 'S'.
3691static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3692 SmallVector<const Stmt *> ToProcess;
3693 ToProcess.push_back(S);
3694 while (!ToProcess.empty()) {
3695 const Stmt *CurrentS = ToProcess.pop_back_val();
3696 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3697 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3698 if (const Decl *D = DeclRef->getDecl())
3699 if (isAncestorDeclContextOf(DC, D))
3700 return true;
3701 } else if (const auto *E =
3702 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3703 if (const Decl *D = E->getAssociatedDecl())
3704 if (isAncestorDeclContextOf(DC, D))
3705 return true;
3706 }
3707 }
3708 return false;
3709}
3710
3711namespace {
3712/// Check if a type has any reference to a declaration that is inside the body
3713/// of a function.
3714/// The \c CheckType(QualType) function should be used to determine
3715/// this property.
3716///
3717/// The type visitor visits one type object only (not recursive).
3718/// To find all referenced declarations we must discover all type objects until
3719/// the canonical type is reached (walk over typedef and similar objects). This
3720/// is done by loop over all "sugar" type objects. For every such type we must
3721/// check all declarations that are referenced from it. For this check the
3722/// visitor is used. In the visit functions all referenced declarations except
3723/// the one that follows in the sugar chain (if any) must be checked. For this
3724/// check the same visitor is re-used (it has no state-dependent data).
3725///
3726/// The visit functions have 3 possible return values:
3727/// - True, found a declaration inside \c ParentDC.
3728/// - False, found declarations only outside \c ParentDC and it is not possible
3729/// to find more declarations (the "sugar" chain does not continue).
3730/// - Empty optional value, found no declarations or only outside \c ParentDC,
3731/// but it is possible to find more declarations in the type "sugar" chain.
3732/// The loop over the "sugar" types can be implemented by using type visit
3733/// functions only (call \c CheckType with the desugared type). With the current
3734/// solution no visit function is needed if the type has only a desugared type
3735/// as data.
3736class IsTypeDeclaredInsideVisitor
3737 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3738public:
3739 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3740 : ParentDC(ParentDC) {}
3741
3742 bool CheckType(QualType T) {
3743 // Check the chain of "sugar" types.
3744 // The "sugar" types are typedef or similar types that have the same
3745 // canonical type.
3746 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3747 return *Res;
3748 QualType DsT =
3749 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3750 while (DsT != T) {
3751 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3752 return *Res;
3753 T = DsT;
3754 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3755 }
3756 return false;
3757 }
3758
3759 std::optional<bool> VisitTagType(const TagType *T) {
3760 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3761 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3762 if (checkTemplateArgument(Arg))
3763 return true;
3764 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3765 }
3766
3767 std::optional<bool> VisitPointerType(const PointerType *T) {
3768 return CheckType(T->getPointeeType());
3769 }
3770
3771 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3772 return CheckType(T->getPointeeTypeAsWritten());
3773 }
3774
3775 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3776 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3777 }
3778
3779 std::optional<bool> VisitUsingType(const UsingType *T) {
3780 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3781 }
3782
3783 std::optional<bool>
3784 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3785 for (const auto &Arg : T->template_arguments())
3786 if (checkTemplateArgument(Arg))
3787 return true;
3788 // This type is a "sugar" to a record type, it can have a desugared type.
3789 return {};
3790 }
3791
3792 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3793 return CheckType(T->getBaseType());
3794 }
3795
3796 std::optional<bool>
3797 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3798 // The "associated declaration" can be the same as ParentDC.
3799 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3800 return true;
3801 return {};
3802 }
3803
3804 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3805 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3806 return true;
3807
3808 return CheckType(T->getElementType());
3809 }
3810
3811 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3812 llvm_unreachable(
3813 "Variable array should not occur in deduced return type of a function");
3814 }
3815
3816 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3817 llvm_unreachable("Incomplete array should not occur in deduced return type "
3818 "of a function");
3819 }
3820
3821 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3822 llvm_unreachable("Dependent array should not occur in deduced return type "
3823 "of a function");
3824 }
3825
3826private:
3827 const DeclContext *const ParentDC;
3828
3829 bool checkTemplateArgument(const TemplateArgument &Arg) {
3830 switch (Arg.getKind()) {
3832 return false;
3834 return CheckType(Arg.getIntegralType());
3836 return CheckType(Arg.getAsType());
3838 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3840 // FIXME: The declaration in this case is not allowed to be in a function?
3841 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3843 // FIXME: The type is not allowed to be in the function?
3844 return CheckType(Arg.getNullPtrType());
3846 return CheckType(Arg.getStructuralValueType());
3848 for (const auto &PackArg : Arg.getPackAsArray())
3849 if (checkTemplateArgument(PackArg))
3850 return true;
3851 return false;
3853 // Templates can not be defined locally in functions.
3854 // A template passed as argument can be not in ParentDC.
3855 return false;
3857 // Templates can not be defined locally in functions.
3858 // A template passed as argument can be not in ParentDC.
3859 return false;
3860 }
3861 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3862 };
3863};
3864} // namespace
3865
3866/// This function checks if the given function has a return type that contains
3867/// a reference (in any way) to a declaration inside the same function.
3869 QualType FromTy = D->getType();
3870 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3871 assert(FromFPT && "Must be called on FunctionProtoType");
3872
3873 auto IsCXX11Lambda = [&]() {
3874 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3875 return false;
3876
3877 return isLambdaMethod(D);
3878 };
3879
3880 QualType RetT = FromFPT->getReturnType();
3881 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3882 FunctionDecl *Def = D->getDefinition();
3883 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3884 return Visitor.CheckType(RetT);
3885 }
3886
3887 return false;
3888}
3889
3891ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3892 Expr *ExplicitExpr = ESpec.getExpr();
3893 if (ExplicitExpr)
3894 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3895 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3896}
3897
3899
3901 auto RedeclIt = Redecls.begin();
3902 // Import the first part of the decl chain. I.e. import all previous
3903 // declarations starting from the canonical decl.
3904 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3905 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3906 if (!ToRedeclOrErr)
3907 return ToRedeclOrErr.takeError();
3908 }
3909 assert(*RedeclIt == D);
3910
3911 // Import the major distinguishing characteristics of this function.
3912 DeclContext *DC, *LexicalDC;
3913 DeclarationName Name;
3914 SourceLocation Loc;
3915 NamedDecl *ToD;
3916 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3917 return std::move(Err);
3918 if (ToD)
3919 return ToD;
3920
3921 FunctionDecl *FoundByLookup = nullptr;
3923
3924 // If this is a function template specialization, then try to find the same
3925 // existing specialization in the "to" context. The lookup below will not
3926 // find any specialization, but would find the primary template; thus, we
3927 // have to skip normal lookup in case of specializations.
3928 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3929 if (D->getTemplatedKind() ==
3931 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3932 if (!FoundFunctionOrErr)
3933 return FoundFunctionOrErr.takeError();
3934 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3935 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3936 return Def;
3937 FoundByLookup = FoundFunction;
3938 }
3939 }
3940 // Try to find a function in our own ("to") context with the same name, same
3941 // type, and in the same context as the function we're importing.
3942 else if (!LexicalDC->isFunctionOrMethod()) {
3943 SmallVector<NamedDecl *, 4> ConflictingDecls;
3945 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3946 for (auto *FoundDecl : FoundDecls) {
3947 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3948 continue;
3949
3950 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3951 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3952 continue;
3953
3954 if (IsStructuralMatch(D, FoundFunction)) {
3955 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3956 return Def;
3957 FoundByLookup = FoundFunction;
3958 break;
3959 }
3960 // FIXME: Check for overloading more carefully, e.g., by boosting
3961 // Sema::IsOverload out to the AST library.
3962
3963 // Function overloading is okay in C++.
3964 if (Importer.getToContext().getLangOpts().CPlusPlus)
3965 continue;
3966
3967 // Complain about inconsistent function types.
3968 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3969 << Name << D->getType() << FoundFunction->getType();
3970 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3971 << FoundFunction->getType();
3972 ConflictingDecls.push_back(FoundDecl);
3973 }
3974 }
3975
3976 if (!ConflictingDecls.empty()) {
3977 ExpectedName NameOrErr = Importer.HandleNameConflict(
3978 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3979 if (NameOrErr)
3980 Name = NameOrErr.get();
3981 else
3982 return NameOrErr.takeError();
3983 }
3984 }
3985
3986 // We do not allow more than one in-class declaration of a function. This is
3987 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3988 // assumes there is only one in-class declaration. Building a redecl
3989 // chain would result in more than one in-class declaration for
3990 // overrides (even if they are part of the same redecl chain inside the
3991 // derived class.)
3992 if (FoundByLookup) {
3993 if (isa<CXXMethodDecl>(FoundByLookup)) {
3994 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3995 if (!D->doesThisDeclarationHaveABody()) {
3996 if (FunctionTemplateDecl *DescribedD =
3998 // Handle a "templated" function together with its described
3999 // template. This avoids need for a similar check at import of the
4000 // described template.
4001 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4002 "Templated function mapped to non-templated?");
4003 Importer.MapImported(DescribedD,
4004 FoundByLookup->getDescribedFunctionTemplate());
4005 }
4006 return Importer.MapImported(D, FoundByLookup);
4007 } else {
4008 // Let's continue and build up the redecl chain in this case.
4009 // FIXME Merge the functions into one decl.
4010 }
4011 }
4012 }
4013 }
4014
4015 DeclarationNameInfo NameInfo(Name, Loc);
4016 // Import additional name location/type info.
4017 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4018 return std::move(Err);
4019
4020 QualType FromTy = D->getType();
4021 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4022 // Set to true if we do not import the type of the function as is. There are
4023 // cases when the original type would result in an infinite recursion during
4024 // the import. To avoid an infinite recursion when importing, we create the
4025 // FunctionDecl with a simplified function type and update it only after the
4026 // relevant AST nodes are already imported.
4027 // The type is related to TypeSourceInfo (it references the type), so we must
4028 // do the same with TypeSourceInfo.
4029 bool UsedDifferentProtoType = false;
4030 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4031 QualType FromReturnTy = FromFPT->getReturnType();
4032 // Functions with auto return type may define a struct inside their body
4033 // and the return type could refer to that struct.
4034 // E.g.: auto foo() { struct X{}; return X(); }
4035 // To avoid an infinite recursion when importing, create the FunctionDecl
4036 // with a simplified return type.
4038 FromReturnTy = Importer.getFromContext().VoidTy;
4039 UsedDifferentProtoType = true;
4040 }
4041 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4042 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4043 // FunctionDecl that we are importing the FunctionProtoType for.
4044 // To avoid an infinite recursion when importing, create the FunctionDecl
4045 // with a simplified function type.
4046 if (FromEPI.ExceptionSpec.SourceDecl ||
4047 FromEPI.ExceptionSpec.SourceTemplate ||
4048 FromEPI.ExceptionSpec.NoexceptExpr) {
4050 FromEPI = DefaultEPI;
4051 UsedDifferentProtoType = true;
4052 }
4053 FromTy = Importer.getFromContext().getFunctionType(
4054 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4055 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4056 FromTy, D->getBeginLoc());
4057 }
4058
4059 Error Err = Error::success();
4060 auto T = importChecked(Err, FromTy);
4061 auto TInfo = importChecked(Err, FromTSI);
4062 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4063 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4064 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4065 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4066 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4067 TrailingRequiresClause.ConstraintExpr =
4068 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4069 if (Err)
4070 return std::move(Err);
4071
4072 // Import the function parameters.
4074 for (auto *P : D->parameters()) {
4075 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4076 Parameters.push_back(*ToPOrErr);
4077 else
4078 return ToPOrErr.takeError();
4079 }
4080
4081 // Create the imported function.
4082 FunctionDecl *ToFunction = nullptr;
4083 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4084 ExplicitSpecifier ESpec =
4085 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4086 if (Err)
4087 return std::move(Err);
4088 auto ToInheritedConstructor = InheritedConstructor();
4089 if (FromConstructor->isInheritingConstructor()) {
4090 Expected<InheritedConstructor> ImportedInheritedCtor =
4091 import(FromConstructor->getInheritedConstructor());
4092 if (!ImportedInheritedCtor)
4093 return ImportedInheritedCtor.takeError();
4094 ToInheritedConstructor = *ImportedInheritedCtor;
4095 }
4096 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4097 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4098 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4100 ToInheritedConstructor, TrailingRequiresClause))
4101 return ToFunction;
4102 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4103
4104 Error Err = Error::success();
4105 auto ToOperatorDelete = importChecked(
4106 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4107 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4108 if (Err)
4109 return std::move(Err);
4110
4111 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4112 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4113 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4115 TrailingRequiresClause))
4116 return ToFunction;
4117
4118 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4119
4120 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4121 } else if (CXXConversionDecl *FromConversion =
4122 dyn_cast<CXXConversionDecl>(D)) {
4123 ExplicitSpecifier ESpec =
4124 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4125 if (Err)
4126 return std::move(Err);
4127 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4128 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4129 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4130 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4131 SourceLocation(), TrailingRequiresClause))
4132 return ToFunction;
4133 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4134 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4135 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4136 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4137 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4138 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4139 return ToFunction;
4140 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4141 ExplicitSpecifier ESpec =
4142 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4143 CXXConstructorDecl *Ctor =
4144 importChecked(Err, Guide->getCorrespondingConstructor());
4145 const CXXDeductionGuideDecl *SourceDG =
4146 importChecked(Err, Guide->getSourceDeductionGuide());
4147 if (Err)
4148 return std::move(Err);
4149 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4150 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4151 NameInfo, T, TInfo, ToEndLoc, Ctor,
4152 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4153 SourceDG, Guide->getSourceDeductionGuideKind()))
4154 return ToFunction;
4155 } else {
4156 if (GetImportedOrCreateDecl(
4157 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4158 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4160 D->getConstexprKind(), TrailingRequiresClause))
4161 return ToFunction;
4162 }
4163
4164 // Connect the redecl chain.
4165 if (FoundByLookup) {
4166 auto *Recent = const_cast<FunctionDecl *>(
4167 FoundByLookup->getMostRecentDecl());
4168 ToFunction->setPreviousDecl(Recent);
4169 // FIXME Probably we should merge exception specifications. E.g. In the
4170 // "To" context the existing function may have exception specification with
4171 // noexcept-unevaluated, while the newly imported function may have an
4172 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4173 // decl and its redeclarations may be required.
4174 }
4175
4176 StringLiteral *Msg = D->getDeletedMessage();
4177 if (Msg) {
4178 auto Imported = import(Msg);
4179 if (!Imported)
4180 return Imported.takeError();
4181 Msg = *Imported;
4182 }
4183
4184 ToFunction->setQualifierInfo(ToQualifierLoc);
4185 ToFunction->setAccess(D->getAccess());
4186 ToFunction->setLexicalDeclContext(LexicalDC);
4187 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4188 ToFunction->setTrivial(D->isTrivial());
4189 ToFunction->setIsPureVirtual(D->isPureVirtual());
4190 ToFunction->setDefaulted(D->isDefaulted());
4192 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4198 ToFunction->setRangeEnd(ToEndLoc);
4199 ToFunction->setDefaultLoc(ToDefaultLoc);
4200
4201 if (Msg)
4202 ToFunction->setDefaultedOrDeletedInfo(
4204 Importer.getToContext(), {}, Msg));
4205
4206 // Set the parameters.
4207 for (auto *Param : Parameters) {
4208 Param->setOwningFunction(ToFunction);
4209 ToFunction->addDeclInternal(Param);
4210 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4211 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4212 }
4213 ToFunction->setParams(Parameters);
4214
4215 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4216 // params it refers to.
4217 if (TInfo) {
4218 if (auto ProtoLoc =
4219 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4220 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4221 ProtoLoc.setParam(I, Parameters[I]);
4222 }
4223 }
4224
4225 // Import the describing template function, if any.
4226 if (FromFT) {
4227 auto ToFTOrErr = import(FromFT);
4228 if (!ToFTOrErr)
4229 return ToFTOrErr.takeError();
4230 }
4231
4232 // Import Ctor initializers.
4233 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4234 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4235 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4236 // Import first, then allocate memory and copy if there was no error.
4237 if (Error Err = ImportContainerChecked(
4238 FromConstructor->inits(), CtorInitializers))
4239 return std::move(Err);
4240 auto **Memory =
4241 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4242 llvm::copy(CtorInitializers, Memory);
4243 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4244 ToCtor->setCtorInitializers(Memory);
4245 ToCtor->setNumCtorInitializers(NumInitializers);
4246 }
4247 }
4248
4249 // If it is a template, import all related things.
4250 if (Error Err = ImportTemplateInformation(D, ToFunction))
4251 return std::move(Err);
4252
4253 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4255 FromCXXMethod))
4256 return std::move(Err);
4257
4259 Error Err = ImportFunctionDeclBody(D, ToFunction);
4260
4261 if (Err)
4262 return std::move(Err);
4263 }
4264
4265 // Import and set the original type in case we used another type.
4266 if (UsedDifferentProtoType) {
4267 if (ExpectedType TyOrErr = import(D->getType()))
4268 ToFunction->setType(*TyOrErr);
4269 else
4270 return TyOrErr.takeError();
4271 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4272 ToFunction->setTypeSourceInfo(*TSIOrErr);
4273 else
4274 return TSIOrErr.takeError();
4275 }
4276
4277 // FIXME: Other bits to merge?
4278
4279 addDeclToContexts(D, ToFunction);
4280
4281 // Import the rest of the chain. I.e. import all subsequent declarations.
4282 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4283 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4284 if (!ToRedeclOrErr)
4285 return ToRedeclOrErr.takeError();
4286 }
4287
4288 return ToFunction;
4289}
4290
4294
4298
4302
4306
4311
4313 // Import the major distinguishing characteristics of a variable.
4314 DeclContext *DC, *LexicalDC;
4315 DeclarationName Name;
4316 SourceLocation Loc;
4317 NamedDecl *ToD;
4318 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4319 return std::move(Err);
4320 if (ToD)
4321 return ToD;
4322
4323 // Determine whether we've already imported this field.
4324 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4325 for (auto *FoundDecl : FoundDecls) {
4326 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4327 // For anonymous fields, match up by index.
4328 if (!Name &&
4330 ASTImporter::getFieldIndex(FoundField))
4331 continue;
4332
4333 if (Importer.IsStructurallyEquivalent(D->getType(),
4334 FoundField->getType())) {
4335 Importer.MapImported(D, FoundField);
4336 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4337 // initializer of a FieldDecl might not had been instantiated in the
4338 // "To" context. However, the "From" context might instantiated that,
4339 // thus we have to merge that.
4340 // Note: `hasInClassInitializer()` is not the same as non-null
4341 // `getInClassInitializer()` value.
4342 if (Expr *FromInitializer = D->getInClassInitializer()) {
4343 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4344 // Import of the FromInitializer may result in the setting of
4345 // InClassInitializer. If not, set it here.
4346 assert(FoundField->hasInClassInitializer() &&
4347 "Field should have an in-class initializer if it has an "
4348 "expression for it.");
4349 if (!FoundField->getInClassInitializer())
4350 FoundField->setInClassInitializer(*ToInitializerOrErr);
4351 } else {
4352 return ToInitializerOrErr.takeError();
4353 }
4354 }
4355 return FoundField;
4356 }
4357
4358 // FIXME: Why is this case not handled with calling HandleNameConflict?
4359 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4360 << Name << D->getType() << FoundField->getType();
4361 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4362 << FoundField->getType();
4363
4364 return make_error<ASTImportError>(ASTImportError::NameConflict);
4365 }
4366 }
4367
4368 Error Err = Error::success();
4369 auto ToType = importChecked(Err, D->getType());
4370 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4371 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4372 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4373 if (Err)
4374 return std::move(Err);
4375 const Type *ToCapturedVLAType = nullptr;
4376 if (Error Err = Importer.importInto(
4377 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4378 return std::move(Err);
4379
4380 FieldDecl *ToField;
4381 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4382 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4383 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4384 D->getInClassInitStyle()))
4385 return ToField;
4386
4387 ToField->setAccess(D->getAccess());
4388 ToField->setLexicalDeclContext(LexicalDC);
4389 ToField->setImplicit(D->isImplicit());
4390 if (ToCapturedVLAType)
4391 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4392 LexicalDC->addDeclInternal(ToField);
4393 // Import initializer only after the field was created, it may have recursive
4394 // reference to the field.
4395 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4396 if (Err)
4397 return std::move(Err);
4398 if (ToInitializer) {
4399 auto *AlreadyImported = ToField->getInClassInitializer();
4400 if (AlreadyImported)
4401 assert(ToInitializer == AlreadyImported &&
4402 "Duplicate import of in-class initializer.");
4403 else
4404 ToField->setInClassInitializer(ToInitializer);
4405 }
4406
4407 return ToField;
4408}
4409
4411 // Import the major distinguishing characteristics of a variable.
4412 DeclContext *DC, *LexicalDC;
4413 DeclarationName Name;
4414 SourceLocation Loc;
4415 NamedDecl *ToD;
4416 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4417 return std::move(Err);
4418 if (ToD)
4419 return ToD;
4420
4421 // Determine whether we've already imported this field.
4422 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4423 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4424 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4425 // For anonymous indirect fields, match up by index.
4426 if (!Name &&
4428 ASTImporter::getFieldIndex(FoundField))
4429 continue;
4430
4431 if (Importer.IsStructurallyEquivalent(D->getType(),
4432 FoundField->getType(),
4433 !Name.isEmpty())) {
4434 Importer.MapImported(D, FoundField);
4435 return FoundField;
4436 }
4437
4438 // If there are more anonymous fields to check, continue.
4439 if (!Name && I < N-1)
4440 continue;
4441
4442 // FIXME: Why is this case not handled with calling HandleNameConflict?
4443 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4444 << Name << D->getType() << FoundField->getType();
4445 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4446 << FoundField->getType();
4447
4448 return make_error<ASTImportError>(ASTImportError::NameConflict);
4449 }
4450 }
4451
4452 // Import the type.
4453 auto TypeOrErr = import(D->getType());
4454 if (!TypeOrErr)
4455 return TypeOrErr.takeError();
4456
4457 auto **NamedChain =
4458 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4459
4460 unsigned i = 0;
4461 for (auto *PI : D->chain())
4462 if (Expected<NamedDecl *> ToD = import(PI))
4463 NamedChain[i++] = *ToD;
4464 else
4465 return ToD.takeError();
4466
4467 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4468 IndirectFieldDecl *ToIndirectField;
4469 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4470 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4471 // FIXME here we leak `NamedChain` which is allocated before
4472 return ToIndirectField;
4473
4474 ToIndirectField->setAccess(D->getAccess());
4475 ToIndirectField->setLexicalDeclContext(LexicalDC);
4476 LexicalDC->addDeclInternal(ToIndirectField);
4477 return ToIndirectField;
4478}
4479
4480/// Used as return type of getFriendCountAndPosition.
4482 /// Number of similar looking friends.
4483 unsigned int TotalCount;
4484 /// Index of the specific FriendDecl.
4485 unsigned int IndexOfDecl;
4486};
4487
4488static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4489 FriendDecl *FD2) {
4490 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4491 return false;
4492
4493 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4494 return Importer.IsStructurallyEquivalent(
4495 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4496
4497 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4499 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4500 FD2->getASTContext(), NonEquivalentDecls,
4502 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4503 return Ctx.IsEquivalent(FD1, FD2);
4504}
4505
4507 FriendDecl *FD) {
4508 unsigned int FriendCount = 0;
4509 UnsignedOrNone FriendPosition = std::nullopt;
4510 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4511
4512 for (FriendDecl *FoundFriend : RD->friends()) {
4513 if (FoundFriend == FD) {
4514 FriendPosition = FriendCount;
4515 ++FriendCount;
4516 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4517 ++FriendCount;
4518 }
4519 }
4520
4521 assert(FriendPosition && "Friend decl not found in own parent.");
4522
4523 return {FriendCount, *FriendPosition};
4524}
4525
4527 // Import the major distinguishing characteristics of a declaration.
4528 DeclContext *DC, *LexicalDC;
4529 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4530 return std::move(Err);
4531
4532 // Determine whether we've already imported this decl.
4533 // FriendDecl is not a NamedDecl so we cannot use lookup.
4534 // We try to maintain order and count of redundant friend declarations.
4535 const auto *RD = cast<CXXRecordDecl>(DC);
4536 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4537 for (FriendDecl *ImportedFriend : RD->friends())
4538 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4539 ImportedEquivalentFriends.push_back(ImportedFriend);
4540
4541 FriendCountAndPosition CountAndPosition =
4542 getFriendCountAndPosition(Importer, D);
4543
4544 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4545 "Class with non-matching friends is imported, ODR check wrong?");
4546 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4547 return Importer.MapImported(
4548 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4549
4550 // Not found. Create it.
4551 // The declarations will be put into order later by ImportDeclContext.
4553 if (NamedDecl *FriendD = D->getFriendDecl()) {
4554 NamedDecl *ToFriendD;
4555 if (Error Err = importInto(ToFriendD, FriendD))
4556 return std::move(Err);
4557
4558 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4559 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4560 ToFriendD->setObjectOfFriendDecl(false);
4561
4562 ToFU = ToFriendD;
4563 } else { // The friend is a type, not a decl.
4564 if (auto TSIOrErr = import(D->getFriendType()))
4565 ToFU = *TSIOrErr;
4566 else
4567 return TSIOrErr.takeError();
4568 }
4569
4570 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4571 auto **FromTPLists = D->getTrailingObjects();
4572 for (unsigned I = 0; I < D->NumTPLists; I++) {
4573 if (auto ListOrErr = import(FromTPLists[I]))
4574 ToTPLists[I] = *ListOrErr;
4575 else
4576 return ListOrErr.takeError();
4577 }
4578
4579 auto LocationOrErr = import(D->getLocation());
4580 if (!LocationOrErr)
4581 return LocationOrErr.takeError();
4582 auto FriendLocOrErr = import(D->getFriendLoc());
4583 if (!FriendLocOrErr)
4584 return FriendLocOrErr.takeError();
4585 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4586 if (!EllipsisLocOrErr)
4587 return EllipsisLocOrErr.takeError();
4588
4589 FriendDecl *FrD;
4590 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4591 *LocationOrErr, ToFU, *FriendLocOrErr,
4592 *EllipsisLocOrErr, ToTPLists))
4593 return FrD;
4594
4595 FrD->setAccess(D->getAccess());
4596 FrD->setLexicalDeclContext(LexicalDC);
4597 LexicalDC->addDeclInternal(FrD);
4598 return FrD;
4599}
4600
4602 // Import the major distinguishing characteristics of an ivar.
4603 DeclContext *DC, *LexicalDC;
4604 DeclarationName Name;
4605 SourceLocation Loc;
4606 NamedDecl *ToD;
4607 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4608 return std::move(Err);
4609 if (ToD)
4610 return ToD;
4611
4612 // Determine whether we've already imported this ivar
4613 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4614 for (auto *FoundDecl : FoundDecls) {
4615 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4616 if (Importer.IsStructurallyEquivalent(D->getType(),
4617 FoundIvar->getType())) {
4618 Importer.MapImported(D, FoundIvar);
4619 return FoundIvar;
4620 }
4621
4622 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4623 << Name << D->getType() << FoundIvar->getType();
4624 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4625 << FoundIvar->getType();
4626
4627 return make_error<ASTImportError>(ASTImportError::NameConflict);
4628 }
4629 }
4630
4631 Error Err = Error::success();
4632 auto ToType = importChecked(Err, D->getType());
4633 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4634 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4635 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4636 if (Err)
4637 return std::move(Err);
4638
4639 ObjCIvarDecl *ToIvar;
4640 if (GetImportedOrCreateDecl(
4641 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4642 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4643 ToType, ToTypeSourceInfo,
4644 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4645 return ToIvar;
4646
4647 ToIvar->setLexicalDeclContext(LexicalDC);
4648 LexicalDC->addDeclInternal(ToIvar);
4649 return ToIvar;
4650}
4651
4653
4655 auto RedeclIt = Redecls.begin();
4656 // Import the first part of the decl chain. I.e. import all previous
4657 // declarations starting from the canonical decl.
4658 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4659 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4660 if (!RedeclOrErr)
4661 return RedeclOrErr.takeError();
4662 }
4663 assert(*RedeclIt == D);
4664
4665 // Import the major distinguishing characteristics of a variable.
4666 DeclContext *DC, *LexicalDC;
4667 DeclarationName Name;
4668 SourceLocation Loc;
4669 NamedDecl *ToD;
4670 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4671 return std::move(Err);
4672 if (ToD)
4673 return ToD;
4674
4675 // Try to find a variable in our own ("to") context with the same name and
4676 // in the same context as the variable we're importing.
4677 VarDecl *FoundByLookup = nullptr;
4678 if (D->isFileVarDecl()) {
4679 SmallVector<NamedDecl *, 4> ConflictingDecls;
4680 unsigned IDNS = Decl::IDNS_Ordinary;
4681 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4682 for (auto *FoundDecl : FoundDecls) {
4683 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4684 continue;
4685
4686 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4687 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4688 continue;
4689 if (Importer.IsStructurallyEquivalent(D->getType(),
4690 FoundVar->getType())) {
4691
4692 // The VarDecl in the "From" context has a definition, but in the
4693 // "To" context we already have a definition.
4694 VarDecl *FoundDef = FoundVar->getDefinition();
4695 if (D->isThisDeclarationADefinition() && FoundDef)
4696 // FIXME Check for ODR error if the two definitions have
4697 // different initializers?
4698 return Importer.MapImported(D, FoundDef);
4699
4700 // The VarDecl in the "From" context has an initializer, but in the
4701 // "To" context we already have an initializer.
4702 const VarDecl *FoundDInit = nullptr;
4703 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4704 // FIXME Diagnose ODR error if the two initializers are different?
4705 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4706
4707 FoundByLookup = FoundVar;
4708 break;
4709 }
4710
4711 const ArrayType *FoundArray
4712 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4713 const ArrayType *TArray
4714 = Importer.getToContext().getAsArrayType(D->getType());
4715 if (FoundArray && TArray) {
4716 if (isa<IncompleteArrayType>(FoundArray) &&
4717 isa<ConstantArrayType>(TArray)) {
4718 // Import the type.
4719 if (auto TyOrErr = import(D->getType()))
4720 FoundVar->setType(*TyOrErr);
4721 else
4722 return TyOrErr.takeError();
4723
4724 FoundByLookup = FoundVar;
4725 break;
4726 } else if (isa<IncompleteArrayType>(TArray) &&
4727 isa<ConstantArrayType>(FoundArray)) {
4728 FoundByLookup = FoundVar;
4729 break;
4730 }
4731 }
4732
4733 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4734 << Name << D->getType() << FoundVar->getType();
4735 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4736 << FoundVar->getType();
4737 ConflictingDecls.push_back(FoundDecl);
4738 }
4739 }
4740
4741 if (!ConflictingDecls.empty()) {
4742 ExpectedName NameOrErr = Importer.HandleNameConflict(
4743 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4744 if (NameOrErr)
4745 Name = NameOrErr.get();
4746 else
4747 return NameOrErr.takeError();
4748 }
4749 }
4750
4751 Error Err = Error::success();
4752 auto ToType = importChecked(Err, D->getType());
4753 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4754 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4755 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4756 if (Err)
4757 return std::move(Err);
4758
4759 VarDecl *ToVar;
4760 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4761 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4762 if (Error Err =
4763 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4764 return std::move(Err);
4765 DecompositionDecl *ToDecomp;
4766 if (GetImportedOrCreateDecl(
4767 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4768 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4769 return ToDecomp;
4770 ToVar = ToDecomp;
4771 } else {
4772 // Create the imported variable.
4773 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4774 ToInnerLocStart, Loc,
4775 Name.getAsIdentifierInfo(), ToType,
4776 ToTypeSourceInfo, D->getStorageClass()))
4777 return ToVar;
4778 }
4779
4780 ToVar->setTSCSpec(D->getTSCSpec());
4781 ToVar->setQualifierInfo(ToQualifierLoc);
4782 ToVar->setAccess(D->getAccess());
4783 ToVar->setLexicalDeclContext(LexicalDC);
4784 if (D->isInlineSpecified())
4785 ToVar->setInlineSpecified();
4786 if (D->isInline())
4787 ToVar->setImplicitlyInline();
4788
4789 if (FoundByLookup) {
4790 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4791 ToVar->setPreviousDecl(Recent);
4792 }
4793
4794 // Import the described template, if any.
4795 if (D->getDescribedVarTemplate()) {
4796 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4797 if (!ToVTOrErr)
4798 return ToVTOrErr.takeError();
4800 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4802 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4803 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4804 else
4805 return ToInstOrErr.takeError();
4806 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4808 else
4809 return POIOrErr.takeError();
4810 }
4811
4812 if (Error Err = ImportInitializer(D, ToVar))
4813 return std::move(Err);
4814
4815 if (D->isConstexpr())
4816 ToVar->setConstexpr(true);
4817
4818 addDeclToContexts(D, ToVar);
4819
4820 // Import the rest of the chain. I.e. import all subsequent declarations.
4821 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4822 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4823 if (!RedeclOrErr)
4824 return RedeclOrErr.takeError();
4825 }
4826
4827 return ToVar;
4828}
4829
4831 // Parameters are created in the translation unit's context, then moved
4832 // into the function declaration's context afterward.
4833 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4834
4835 Error Err = Error::success();
4836 auto ToDeclName = importChecked(Err, D->getDeclName());
4837 auto ToLocation = importChecked(Err, D->getLocation());
4838 auto ToType = importChecked(Err, D->getType());
4839 if (Err)
4840 return std::move(Err);
4841
4842 // Create the imported parameter.
4843 ImplicitParamDecl *ToParm = nullptr;
4844 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4845 ToLocation, ToDeclName.getAsIdentifierInfo(),
4846 ToType, D->getParameterKind()))
4847 return ToParm;
4848 return ToParm;
4849}
4850
4852 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4853
4854 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4855 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4856 else
4857 return LocOrErr.takeError();
4858
4860 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4861
4862 if (FromParam->hasUninstantiatedDefaultArg()) {
4863 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4864 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4865 else
4866 return ToDefArgOrErr.takeError();
4867 } else if (FromParam->hasUnparsedDefaultArg()) {
4868 ToParam->setUnparsedDefaultArg();
4869 } else if (FromParam->hasDefaultArg()) {
4870 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4871 ToParam->setDefaultArg(*ToDefArgOrErr);
4872 else
4873 return ToDefArgOrErr.takeError();
4874 }
4875
4876 return Error::success();
4877}
4878
4881 Error Err = Error::success();
4882 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4883 ConstructorUsingShadowDecl *ToShadow =
4884 importChecked(Err, From.getShadowDecl());
4885 if (Err)
4886 return std::move(Err);
4887 return InheritedConstructor(ToShadow, ToBaseCtor);
4888}
4889
4891 // Parameters are created in the translation unit's context, then moved
4892 // into the function declaration's context afterward.
4893 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4894
4895 Error Err = Error::success();
4896 auto ToDeclName = importChecked(Err, D->getDeclName());
4897 auto ToLocation = importChecked(Err, D->getLocation());
4898 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4899 auto ToType = importChecked(Err, D->getType());
4900 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4901 if (Err)
4902 return std::move(Err);
4903
4904 ParmVarDecl *ToParm;
4905 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4906 ToInnerLocStart, ToLocation,
4907 ToDeclName.getAsIdentifierInfo(), ToType,
4908 ToTypeSourceInfo, D->getStorageClass(),
4909 /*DefaultArg*/ nullptr))
4910 return ToParm;
4911
4912 // Set the default argument. It should be no problem if it was already done.
4913 // Do not import the default expression before GetImportedOrCreateDecl call
4914 // to avoid possible infinite import loop because circular dependency.
4915 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4916 return std::move(Err);
4917
4918 if (D->isObjCMethodParameter()) {
4921 } else {
4924 }
4925
4926 return ToParm;
4927}
4928
4930 // Import the major distinguishing characteristics of a method.
4931 DeclContext *DC, *LexicalDC;
4932 DeclarationName Name;
4933 SourceLocation Loc;
4934 NamedDecl *ToD;
4935 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4936 return std::move(Err);
4937 if (ToD)
4938 return ToD;
4939
4940 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4941 for (auto *FoundDecl : FoundDecls) {
4942 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4943 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4944 continue;
4945
4946 // Check return types.
4947 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4948 FoundMethod->getReturnType())) {
4949 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4950 << D->isInstanceMethod() << Name << D->getReturnType()
4951 << FoundMethod->getReturnType();
4952 Importer.ToDiag(FoundMethod->getLocation(),
4953 diag::note_odr_objc_method_here)
4954 << D->isInstanceMethod() << Name;
4955
4956 return make_error<ASTImportError>(ASTImportError::NameConflict);
4957 }
4958
4959 // Check the number of parameters.
4960 if (D->param_size() != FoundMethod->param_size()) {
4961 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4962 << D->isInstanceMethod() << Name
4963 << D->param_size() << FoundMethod->param_size();
4964 Importer.ToDiag(FoundMethod->getLocation(),
4965 diag::note_odr_objc_method_here)
4966 << D->isInstanceMethod() << Name;
4967
4968 return make_error<ASTImportError>(ASTImportError::NameConflict);
4969 }
4970
4971 // Check parameter types.
4973 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4974 P != PEnd; ++P, ++FoundP) {
4975 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4976 (*FoundP)->getType())) {
4977 Importer.FromDiag((*P)->getLocation(),
4978 diag::warn_odr_objc_method_param_type_inconsistent)
4979 << D->isInstanceMethod() << Name
4980 << (*P)->getType() << (*FoundP)->getType();
4981 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4982 << (*FoundP)->getType();
4983
4984 return make_error<ASTImportError>(ASTImportError::NameConflict);
4985 }
4986 }
4987
4988 // Check variadic/non-variadic.
4989 // Check the number of parameters.
4990 if (D->isVariadic() != FoundMethod->isVariadic()) {
4991 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4992 << D->isInstanceMethod() << Name;
4993 Importer.ToDiag(FoundMethod->getLocation(),
4994 diag::note_odr_objc_method_here)
4995 << D->isInstanceMethod() << Name;
4996
4997 return make_error<ASTImportError>(ASTImportError::NameConflict);
4998 }
4999
5000 // FIXME: Any other bits we need to merge?
5001 return Importer.MapImported(D, FoundMethod);
5002 }
5003 }
5004
5005 Error Err = Error::success();
5006 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5007 auto ToReturnType = importChecked(Err, D->getReturnType());
5008 auto ToReturnTypeSourceInfo =
5010 if (Err)
5011 return std::move(Err);
5012
5013 ObjCMethodDecl *ToMethod;
5014 if (GetImportedOrCreateDecl(
5015 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5016 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5020 return ToMethod;
5021
5022 // FIXME: When we decide to merge method definitions, we'll need to
5023 // deal with implicit parameters.
5024
5025 // Import the parameters
5027 for (auto *FromP : D->parameters()) {
5028 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5029 ToParams.push_back(*ToPOrErr);
5030 else
5031 return ToPOrErr.takeError();
5032 }
5033
5034 // Set the parameters.
5035 for (auto *ToParam : ToParams) {
5036 ToParam->setOwningFunction(ToMethod);
5037 ToMethod->addDeclInternal(ToParam);
5038 }
5039
5041 D->getSelectorLocs(FromSelLocs);
5042 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5043 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5044 return std::move(Err);
5045
5046 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5047
5048 ToMethod->setLexicalDeclContext(LexicalDC);
5049 LexicalDC->addDeclInternal(ToMethod);
5050
5051 // Implicit params are declared when Sema encounters the definition but this
5052 // never happens when the method is imported. Manually declare the implicit
5053 // params now that the MethodDecl knows its class interface.
5054 if (D->getSelfDecl())
5055 ToMethod->createImplicitParams(Importer.getToContext(),
5056 ToMethod->getClassInterface());
5057
5058 return ToMethod;
5059}
5060
5062 // Import the major distinguishing characteristics of a category.
5063 DeclContext *DC, *LexicalDC;
5064 DeclarationName Name;
5065 SourceLocation Loc;
5066 NamedDecl *ToD;
5067 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5068 return std::move(Err);
5069 if (ToD)
5070 return ToD;
5071
5072 Error Err = Error::success();
5073 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5074 auto ToLocation = importChecked(Err, D->getLocation());
5075 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5076 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5077 if (Err)
5078 return std::move(Err);
5079
5081 if (GetImportedOrCreateDecl(
5082 Result, D, Importer.getToContext(), DC, D->getVariance(),
5083 ToVarianceLoc, D->getIndex(),
5084 ToLocation, Name.getAsIdentifierInfo(),
5085 ToColonLoc, ToTypeSourceInfo))
5086 return Result;
5087
5088 // Only import 'ObjCTypeParamType' after the decl is created.
5089 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5090 if (Err)
5091 return std::move(Err);
5092 Result->setTypeForDecl(ToTypeForDecl);
5093 Result->setLexicalDeclContext(LexicalDC);
5094 return Result;
5095}
5096
5098 // Import the major distinguishing characteristics of a category.
5099 DeclContext *DC, *LexicalDC;
5100 DeclarationName Name;
5101 SourceLocation Loc;
5102 NamedDecl *ToD;
5103 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5104 return std::move(Err);
5105 if (ToD)
5106 return ToD;
5107
5108 ObjCInterfaceDecl *ToInterface;
5109 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5110 return std::move(Err);
5111
5112 // Determine if we've already encountered this category.
5113 ObjCCategoryDecl *MergeWithCategory
5114 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5115 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5116 if (!ToCategory) {
5117
5118 Error Err = Error::success();
5119 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5120 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5121 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5122 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5123 if (Err)
5124 return std::move(Err);
5125
5126 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5127 ToAtStartLoc, Loc,
5128 ToCategoryNameLoc,
5129 Name.getAsIdentifierInfo(), ToInterface,
5130 /*TypeParamList=*/nullptr,
5131 ToIvarLBraceLoc,
5132 ToIvarRBraceLoc))
5133 return ToCategory;
5134
5135 ToCategory->setLexicalDeclContext(LexicalDC);
5136 LexicalDC->addDeclInternal(ToCategory);
5137 // Import the type parameter list after MapImported, to avoid
5138 // loops when bringing in their DeclContext.
5139 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5140 ToCategory->setTypeParamList(*PListOrErr);
5141 else
5142 return PListOrErr.takeError();
5143
5144 // Import protocols
5146 SmallVector<SourceLocation, 4> ProtocolLocs;
5148 = D->protocol_loc_begin();
5150 FromProtoEnd = D->protocol_end();
5151 FromProto != FromProtoEnd;
5152 ++FromProto, ++FromProtoLoc) {
5153 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5154 Protocols.push_back(*ToProtoOrErr);
5155 else
5156 return ToProtoOrErr.takeError();
5157
5158 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5159 ProtocolLocs.push_back(*ToProtoLocOrErr);
5160 else
5161 return ToProtoLocOrErr.takeError();
5162 }
5163
5164 // FIXME: If we're merging, make sure that the protocol list is the same.
5165 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5166 ProtocolLocs.data(), Importer.getToContext());
5167
5168 } else {
5169 Importer.MapImported(D, ToCategory);
5170 }
5171
5172 // Import all of the members of this category.
5173 if (Error Err = ImportDeclContext(D))
5174 return std::move(Err);
5175
5176 // If we have an implementation, import it as well.
5177 if (D->getImplementation()) {
5178 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5179 import(D->getImplementation()))
5180 ToCategory->setImplementation(*ToImplOrErr);
5181 else
5182 return ToImplOrErr.takeError();
5183 }
5184
5185 return ToCategory;
5186}
5187
5190 if (To->getDefinition()) {
5192 if (Error Err = ImportDeclContext(From))
5193 return Err;
5194 return Error::success();
5195 }
5196
5197 // Start the protocol definition
5198 To->startDefinition();
5199
5200 // Import protocols
5202 SmallVector<SourceLocation, 4> ProtocolLocs;
5204 From->protocol_loc_begin();
5205 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5206 FromProtoEnd = From->protocol_end();
5207 FromProto != FromProtoEnd;
5208 ++FromProto, ++FromProtoLoc) {
5209 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5210 Protocols.push_back(*ToProtoOrErr);
5211 else
5212 return ToProtoOrErr.takeError();
5213
5214 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5215 ProtocolLocs.push_back(*ToProtoLocOrErr);
5216 else
5217 return ToProtoLocOrErr.takeError();
5218
5219 }
5220
5221 // FIXME: If we're merging, make sure that the protocol list is the same.
5222 To->setProtocolList(Protocols.data(), Protocols.size(),
5223 ProtocolLocs.data(), Importer.getToContext());
5224
5225 if (shouldForceImportDeclContext(Kind)) {
5226 // Import all of the members of this protocol.
5227 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5228 return Err;
5229 }
5230 return Error::success();
5231}
5232
5234 // If this protocol has a definition in the translation unit we're coming
5235 // from, but this particular declaration is not that definition, import the
5236 // definition and map to that.
5238 if (Definition && Definition != D) {
5239 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5240 return Importer.MapImported(D, *ImportedDefOrErr);
5241 else
5242 return ImportedDefOrErr.takeError();
5243 }
5244
5245 // Import the major distinguishing characteristics of a protocol.
5246 DeclContext *DC, *LexicalDC;
5247 DeclarationName Name;
5248 SourceLocation Loc;
5249 NamedDecl *ToD;
5250 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5251 return std::move(Err);
5252 if (ToD)
5253 return ToD;
5254
5255 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5256 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5257 for (auto *FoundDecl : FoundDecls) {
5258 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5259 continue;
5260
5261 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5262 break;
5263 }
5264
5265 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5266 if (!ToProto) {
5267 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5268 if (!ToAtBeginLocOrErr)
5269 return ToAtBeginLocOrErr.takeError();
5270
5271 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5272 Name.getAsIdentifierInfo(), Loc,
5273 *ToAtBeginLocOrErr,
5274 /*PrevDecl=*/nullptr))
5275 return ToProto;
5276 ToProto->setLexicalDeclContext(LexicalDC);
5277 LexicalDC->addDeclInternal(ToProto);
5278 }
5279
5280 Importer.MapImported(D, ToProto);
5281
5283 if (Error Err = ImportDefinition(D, ToProto))
5284 return std::move(Err);
5285
5286 return ToProto;
5287}
5288
5290 DeclContext *DC, *LexicalDC;
5291 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5292 return std::move(Err);
5293
5294 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5295 if (!ExternLocOrErr)
5296 return ExternLocOrErr.takeError();
5297
5298 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5299 if (!LangLocOrErr)
5300 return LangLocOrErr.takeError();
5301
5302 bool HasBraces = D->hasBraces();
5303
5304 LinkageSpecDecl *ToLinkageSpec;
5305 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5306 *ExternLocOrErr, *LangLocOrErr,
5307 D->getLanguage(), HasBraces))
5308 return ToLinkageSpec;
5309
5310 if (HasBraces) {
5311 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5312 if (!RBraceLocOrErr)
5313 return RBraceLocOrErr.takeError();
5314 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5315 }
5316
5317 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5318 LexicalDC->addDeclInternal(ToLinkageSpec);
5319
5320 return ToLinkageSpec;
5321}
5322
5324 BaseUsingDecl *ToSI) {
5325 for (UsingShadowDecl *FromShadow : D->shadows()) {
5326 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5327 ToSI->addShadowDecl(*ToShadowOrErr);
5328 else
5329 // FIXME: We return error here but the definition is already created
5330 // and available with lookups. How to fix this?..
5331 return ToShadowOrErr.takeError();
5332 }
5333 return ToSI;
5334}
5335
5337 DeclContext *DC, *LexicalDC;
5338 DeclarationName Name;
5339 SourceLocation Loc;
5340 NamedDecl *ToD = nullptr;
5341 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5342 return std::move(Err);
5343 if (ToD)
5344 return ToD;
5345
5346 Error Err = Error::success();
5347 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5348 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5349 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5350 if (Err)
5351 return std::move(Err);
5352
5353 DeclarationNameInfo NameInfo(Name, ToLoc);
5354 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5355 return std::move(Err);
5356
5357 UsingDecl *ToUsing;
5358 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5359 ToUsingLoc, ToQualifierLoc, NameInfo,
5360 D->hasTypename()))
5361 return ToUsing;
5362
5363 ToUsing->setLexicalDeclContext(LexicalDC);
5364 LexicalDC->addDeclInternal(ToUsing);
5365
5366 if (NamedDecl *FromPattern =
5367 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5368 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5369 Importer.getToContext().setInstantiatedFromUsingDecl(
5370 ToUsing, *ToPatternOrErr);
5371 else
5372 return ToPatternOrErr.takeError();
5373 }
5374
5375 return ImportUsingShadowDecls(D, ToUsing);
5376}
5377
5379 DeclContext *DC, *LexicalDC;
5380 DeclarationName Name;
5381 SourceLocation Loc;
5382 NamedDecl *ToD = nullptr;
5383 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5384 return std::move(Err);
5385 if (ToD)
5386 return ToD;
5387
5388 Error Err = Error::success();
5389 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5390 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5391 auto ToNameLoc = importChecked(Err, D->getLocation());
5392 auto *ToEnumType = importChecked(Err, D->getEnumType());
5393 if (Err)
5394 return std::move(Err);
5395
5396 UsingEnumDecl *ToUsingEnum;
5397 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5398 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5399 return ToUsingEnum;
5400
5401 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5402 LexicalDC->addDeclInternal(ToUsingEnum);
5403
5404 if (UsingEnumDecl *FromPattern =
5405 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5406 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5407 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5408 *ToPatternOrErr);
5409 else
5410 return ToPatternOrErr.takeError();
5411 }
5412
5413 return ImportUsingShadowDecls(D, ToUsingEnum);
5414}
5415
5417 DeclContext *DC, *LexicalDC;
5418 DeclarationName Name;
5419 SourceLocation Loc;
5420 NamedDecl *ToD = nullptr;
5421 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5422 return std::move(Err);
5423 if (ToD)
5424 return ToD;
5425
5426 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5427 if (!ToIntroducerOrErr)
5428 return ToIntroducerOrErr.takeError();
5429
5430 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5431 if (!ToTargetOrErr)
5432 return ToTargetOrErr.takeError();
5433
5434 UsingShadowDecl *ToShadow;
5435 if (auto *FromConstructorUsingShadow =
5436 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5437 Error Err = Error::success();
5439 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5440 if (Err)
5441 return std::move(Err);
5442 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5443 // is really the "NominatedBaseClassShadowDecl" value if it exists
5444 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5445 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5446 // get the correct values.
5447 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5448 ToShadow, D, Importer.getToContext(), DC, Loc,
5449 cast<UsingDecl>(*ToIntroducerOrErr),
5450 Nominated ? Nominated : *ToTargetOrErr,
5451 FromConstructorUsingShadow->constructsVirtualBase()))
5452 return ToShadow;
5453 } else {
5454 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5455 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5456 return ToShadow;
5457 }
5458
5459 ToShadow->setLexicalDeclContext(LexicalDC);
5460 ToShadow->setAccess(D->getAccess());
5461
5462 if (UsingShadowDecl *FromPattern =
5463 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5464 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5465 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5466 ToShadow, *ToPatternOrErr);
5467 else
5468 // FIXME: We return error here but the definition is already created
5469 // and available with lookups. How to fix this?..
5470 return ToPatternOrErr.takeError();
5471 }
5472
5473 LexicalDC->addDeclInternal(ToShadow);
5474
5475 return ToShadow;
5476}
5477
5479 DeclContext *DC, *LexicalDC;
5480 DeclarationName Name;
5481 SourceLocation Loc;
5482 NamedDecl *ToD = nullptr;
5483 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5484 return std::move(Err);
5485 if (ToD)
5486 return ToD;
5487
5488 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5489 if (!ToComAncestorOrErr)
5490 return ToComAncestorOrErr.takeError();
5491
5492 Error Err = Error::success();
5493 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5494 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5495 auto ToNamespaceKeyLocation =
5497 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5498 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5499 if (Err)
5500 return std::move(Err);
5501
5502 UsingDirectiveDecl *ToUsingDir;
5503 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5504 ToUsingLoc,
5505 ToNamespaceKeyLocation,
5506 ToQualifierLoc,
5507 ToIdentLocation,
5508 ToNominatedNamespace, *ToComAncestorOrErr))
5509 return ToUsingDir;
5510
5511 ToUsingDir->setLexicalDeclContext(LexicalDC);
5512 LexicalDC->addDeclInternal(ToUsingDir);
5513
5514 return ToUsingDir;
5515}
5516
5518 DeclContext *DC, *LexicalDC;
5519 DeclarationName Name;
5520 SourceLocation Loc;
5521 NamedDecl *ToD = nullptr;
5522 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5523 return std::move(Err);
5524 if (ToD)
5525 return ToD;
5526
5527 auto ToInstantiatedFromUsingOrErr =
5528 Importer.Import(D->getInstantiatedFromUsingDecl());
5529 if (!ToInstantiatedFromUsingOrErr)
5530 return ToInstantiatedFromUsingOrErr.takeError();
5531 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5532 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5533 return std::move(Err);
5534
5535 UsingPackDecl *ToUsingPack;
5536 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5537 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5538 Expansions))
5539 return ToUsingPack;
5540
5541 addDeclToContexts(D, ToUsingPack);
5542
5543 return ToUsingPack;
5544}
5545
5548 DeclContext *DC, *LexicalDC;
5549 DeclarationName Name;
5550 SourceLocation Loc;
5551 NamedDecl *ToD = nullptr;
5552 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5553 return std::move(Err);
5554 if (ToD)
5555 return ToD;
5556
5557 Error Err = Error::success();
5558 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5559 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5560 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5561 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5562 if (Err)
5563 return std::move(Err);
5564
5565 DeclarationNameInfo NameInfo(Name, ToLoc);
5566 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5567 return std::move(Err);
5568
5569 UnresolvedUsingValueDecl *ToUsingValue;
5570 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5571 ToUsingLoc, ToQualifierLoc, NameInfo,
5572 ToEllipsisLoc))
5573 return ToUsingValue;
5574
5575 ToUsingValue->setAccess(D->getAccess());
5576 ToUsingValue->setLexicalDeclContext(LexicalDC);
5577 LexicalDC->addDeclInternal(ToUsingValue);
5578
5579 return ToUsingValue;
5580}
5581
5584 DeclContext *DC, *LexicalDC;
5585 DeclarationName Name;
5586 SourceLocation Loc;
5587 NamedDecl *ToD = nullptr;
5588 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5589 return std::move(Err);
5590 if (ToD)
5591 return ToD;
5592
5593 Error Err = Error::success();
5594 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5595 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5596 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5597 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5598 if (Err)
5599 return std::move(Err);
5600
5602 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5603 ToUsingLoc, ToTypenameLoc,
5604 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5605 return ToUsing;
5606
5607 ToUsing->setAccess(D->getAccess());
5608 ToUsing->setLexicalDeclContext(LexicalDC);
5609 LexicalDC->addDeclInternal(ToUsing);
5610
5611 return ToUsing;
5612}
5613
5615 Decl* ToD = nullptr;
5616 switch (D->getBuiltinTemplateKind()) {
5617#define BuiltinTemplate(BTName) \
5618 case BuiltinTemplateKind::BTK##BTName: \
5619 ToD = Importer.getToContext().get##BTName##Decl(); \
5620 break;
5621#include "clang/Basic/BuiltinTemplates.inc"
5622 }
5623 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5624 Importer.MapImported(D, ToD);
5625 return ToD;
5626}
5627
5630 if (To->getDefinition()) {
5631 // Check consistency of superclass.
5632 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5633 if (FromSuper) {
5634 if (auto FromSuperOrErr = import(FromSuper))
5635 FromSuper = *FromSuperOrErr;
5636 else
5637 return FromSuperOrErr.takeError();
5638 }
5639
5640 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5641 if ((bool)FromSuper != (bool)ToSuper ||
5642 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5643 Importer.ToDiag(To->getLocation(),
5644 diag::warn_odr_objc_superclass_inconsistent)
5645 << To->getDeclName();
5646 if (ToSuper)
5647 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5648 << To->getSuperClass()->getDeclName();
5649 else
5650 Importer.ToDiag(To->getLocation(),
5651 diag::note_odr_objc_missing_superclass);
5652 if (From->getSuperClass())
5653 Importer.FromDiag(From->getSuperClassLoc(),
5654 diag::note_odr_objc_superclass)
5655 << From->getSuperClass()->getDeclName();
5656 else
5657 Importer.FromDiag(From->getLocation(),
5658 diag::note_odr_objc_missing_superclass);
5659 }
5660
5662 if (Error Err = ImportDeclContext(From))
5663 return Err;
5664 return Error::success();
5665 }
5666
5667 // Start the definition.
5668 To->startDefinition();
5669
5670 // If this class has a superclass, import it.
5671 if (From->getSuperClass()) {
5672 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5673 To->setSuperClass(*SuperTInfoOrErr);
5674 else
5675 return SuperTInfoOrErr.takeError();
5676 }
5677
5678 // Import protocols
5680 SmallVector<SourceLocation, 4> ProtocolLocs;
5682 From->protocol_loc_begin();
5683
5685 FromProtoEnd = From->protocol_end();
5686 FromProto != FromProtoEnd;
5687 ++FromProto, ++FromProtoLoc) {
5688 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5689 Protocols.push_back(*ToProtoOrErr);
5690 else
5691 return ToProtoOrErr.takeError();
5692
5693 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5694 ProtocolLocs.push_back(*ToProtoLocOrErr);
5695 else
5696 return ToProtoLocOrErr.takeError();
5697
5698 }
5699
5700 // FIXME: If we're merging, make sure that the protocol list is the same.
5701 To->setProtocolList(Protocols.data(), Protocols.size(),
5702 ProtocolLocs.data(), Importer.getToContext());
5703
5704 // Import categories. When the categories themselves are imported, they'll
5705 // hook themselves into this interface.
5706 for (auto *Cat : From->known_categories()) {
5707 auto ToCatOrErr = import(Cat);
5708 if (!ToCatOrErr)
5709 return ToCatOrErr.takeError();
5710 }
5711
5712 // If we have an @implementation, import it as well.
5713 if (From->getImplementation()) {
5714 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5715 import(From->getImplementation()))
5716 To->setImplementation(*ToImplOrErr);
5717 else
5718 return ToImplOrErr.takeError();
5719 }
5720
5721 // Import all of the members of this class.
5722 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5723 return Err;
5724
5725 return Error::success();
5726}
5727
5730 if (!list)
5731 return nullptr;
5732
5734 for (auto *fromTypeParam : *list) {
5735 if (auto toTypeParamOrErr = import(fromTypeParam))
5736 toTypeParams.push_back(*toTypeParamOrErr);
5737 else
5738 return toTypeParamOrErr.takeError();
5739 }
5740
5741 auto LAngleLocOrErr = import(list->getLAngleLoc());
5742 if (!LAngleLocOrErr)
5743 return LAngleLocOrErr.takeError();
5744
5745 auto RAngleLocOrErr = import(list->getRAngleLoc());
5746 if (!RAngleLocOrErr)
5747 return RAngleLocOrErr.takeError();
5748
5749 return ObjCTypeParamList::create(Importer.getToContext(),
5750 *LAngleLocOrErr,
5751 toTypeParams,
5752 *RAngleLocOrErr);
5753}
5754
5756 // If this class has a definition in the translation unit we're coming from,
5757 // but this particular declaration is not that definition, import the
5758 // definition and map to that.
5760 if (Definition && Definition != D) {
5761 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5762 return Importer.MapImported(D, *ImportedDefOrErr);
5763 else
5764 return ImportedDefOrErr.takeError();
5765 }
5766
5767 // Import the major distinguishing characteristics of an @interface.
5768 DeclContext *DC, *LexicalDC;
5769 DeclarationName Name;
5770 SourceLocation Loc;
5771 NamedDecl *ToD;
5772 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5773 return std::move(Err);
5774 if (ToD)
5775 return ToD;
5776
5777 // Look for an existing interface with the same name.
5778 ObjCInterfaceDecl *MergeWithIface = nullptr;
5779 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5780 for (auto *FoundDecl : FoundDecls) {
5781 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5782 continue;
5783
5784 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5785 break;
5786 }
5787
5788 // Create an interface declaration, if one does not already exist.
5789 ObjCInterfaceDecl *ToIface = MergeWithIface;
5790 if (!ToIface) {
5791 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5792 if (!AtBeginLocOrErr)
5793 return AtBeginLocOrErr.takeError();
5794
5795 if (GetImportedOrCreateDecl(
5796 ToIface, D, Importer.getToContext(), DC,
5797 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5798 /*TypeParamList=*/nullptr,
5799 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5800 return ToIface;
5801 ToIface->setLexicalDeclContext(LexicalDC);
5802 LexicalDC->addDeclInternal(ToIface);
5803 }
5804 Importer.MapImported(D, ToIface);
5805 // Import the type parameter list after MapImported, to avoid
5806 // loops when bringing in their DeclContext.
5807 if (auto ToPListOrErr =
5809 ToIface->setTypeParamList(*ToPListOrErr);
5810 else
5811 return ToPListOrErr.takeError();
5812
5814 if (Error Err = ImportDefinition(D, ToIface))
5815 return std::move(Err);
5816
5817 return ToIface;
5818}
5819
5822 ObjCCategoryDecl *Category;
5823 if (Error Err = importInto(Category, D->getCategoryDecl()))
5824 return std::move(Err);
5825
5826 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5827 if (!ToImpl) {
5828 DeclContext *DC, *LexicalDC;
5829 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5830 return std::move(Err);
5831
5832 Error Err = Error::success();
5833 auto ToLocation = importChecked(Err, D->getLocation());
5834 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5835 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5836 if (Err)
5837 return std::move(Err);
5838
5839 if (GetImportedOrCreateDecl(
5840 ToImpl, D, Importer.getToContext(), DC,
5841 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5842 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5843 return ToImpl;
5844
5845 ToImpl->setLexicalDeclContext(LexicalDC);
5846 LexicalDC->addDeclInternal(ToImpl);
5847 Category->setImplementation(ToImpl);
5848 }
5849
5850 Importer.MapImported(D, ToImpl);
5851 if (Error Err = ImportDeclContext(D))
5852 return std::move(Err);
5853
5854 return ToImpl;
5855}
5856
5859 // Find the corresponding interface.
5860 ObjCInterfaceDecl *Iface;
5861 if (Error Err = importInto(Iface, D->getClassInterface()))
5862 return std::move(Err);
5863
5864 // Import the superclass, if any.
5865 ObjCInterfaceDecl *Super;
5866 if (Error Err = importInto(Super, D->getSuperClass()))
5867 return std::move(Err);
5868
5870 if (!Impl) {
5871 // We haven't imported an implementation yet. Create a new @implementation
5872 // now.
5873 DeclContext *DC, *LexicalDC;
5874 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5875 return std::move(Err);
5876
5877 Error Err = Error::success();
5878 auto ToLocation = importChecked(Err, D->getLocation());
5879 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5880 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5881 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5882 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5883 if (Err)
5884 return std::move(Err);
5885
5886 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5887 DC, Iface, Super,
5888 ToLocation,
5889 ToAtStartLoc,
5890 ToSuperClassLoc,
5891 ToIvarLBraceLoc,
5892 ToIvarRBraceLoc))
5893 return Impl;
5894
5895 Impl->setLexicalDeclContext(LexicalDC);
5896
5897 // Associate the implementation with the class it implements.
5898 Iface->setImplementation(Impl);
5899 Importer.MapImported(D, Iface->getImplementation());
5900 } else {
5901 Importer.MapImported(D, Iface->getImplementation());
5902
5903 // Verify that the existing @implementation has the same superclass.
5904 if ((Super && !Impl->getSuperClass()) ||
5905 (!Super && Impl->getSuperClass()) ||
5906 (Super && Impl->getSuperClass() &&
5908 Impl->getSuperClass()))) {
5909 Importer.ToDiag(Impl->getLocation(),
5910 diag::warn_odr_objc_superclass_inconsistent)
5911 << Iface->getDeclName();
5912 // FIXME: It would be nice to have the location of the superclass
5913 // below.
5914 if (Impl->getSuperClass())
5915 Importer.ToDiag(Impl->getLocation(),
5916 diag::note_odr_objc_superclass)
5917 << Impl->getSuperClass()->getDeclName();
5918 else
5919 Importer.ToDiag(Impl->getLocation(),
5920 diag::note_odr_objc_missing_superclass);
5921 if (D->getSuperClass())
5922 Importer.FromDiag(D->getLocation(),
5923 diag::note_odr_objc_superclass)
5924 << D->getSuperClass()->getDeclName();
5925 else
5926 Importer.FromDiag(D->getLocation(),
5927 diag::note_odr_objc_missing_superclass);
5928
5929 return make_error<ASTImportError>(ASTImportError::NameConflict);
5930 }
5931 }
5932
5933 // Import all of the members of this @implementation.
5934 if (Error Err = ImportDeclContext(D))
5935 return std::move(Err);
5936
5937 return Impl;
5938}
5939
5941 // Import the major distinguishing characteristics of an @property.
5942 DeclContext *DC, *LexicalDC;
5943 DeclarationName Name;
5944 SourceLocation Loc;
5945 NamedDecl *ToD;
5946 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5947 return std::move(Err);
5948 if (ToD)
5949 return ToD;
5950
5951 // Check whether we have already imported this property.
5952 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5953 for (auto *FoundDecl : FoundDecls) {
5954 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5955 // Instance and class properties can share the same name but are different
5956 // declarations.
5957 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5958 continue;
5959
5960 // Check property types.
5961 if (!Importer.IsStructurallyEquivalent(D->getType(),
5962 FoundProp->getType())) {
5963 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5964 << Name << D->getType() << FoundProp->getType();
5965 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5966 << FoundProp->getType();
5967
5968 return make_error<ASTImportError>(ASTImportError::NameConflict);
5969 }
5970
5971 // FIXME: Check property attributes, getters, setters, etc.?
5972
5973 // Consider these properties to be equivalent.
5974 Importer.MapImported(D, FoundProp);
5975 return FoundProp;
5976 }
5977 }
5978
5979 Error Err = Error::success();
5980 auto ToType = importChecked(Err, D->getType());
5981 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5982 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5983 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5984 if (Err)
5985 return std::move(Err);
5986
5987 // Create the new property.
5988 ObjCPropertyDecl *ToProperty;
5989 if (GetImportedOrCreateDecl(
5990 ToProperty, D, Importer.getToContext(), DC, Loc,
5991 Name.getAsIdentifierInfo(), ToAtLoc,
5992 ToLParenLoc, ToType,
5993 ToTypeSourceInfo, D->getPropertyImplementation()))
5994 return ToProperty;
5995
5996 auto ToGetterName = importChecked(Err, D->getGetterName());
5997 auto ToSetterName = importChecked(Err, D->getSetterName());
5998 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5999 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6000 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6001 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6002 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6003 if (Err)
6004 return std::move(Err);
6005
6006 ToProperty->setLexicalDeclContext(LexicalDC);
6007 LexicalDC->addDeclInternal(ToProperty);
6008
6012 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6013 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6014 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6015 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6016 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6017 return ToProperty;
6018}
6019
6023 if (Error Err = importInto(Property, D->getPropertyDecl()))
6024 return std::move(Err);
6025
6026 DeclContext *DC, *LexicalDC;
6027 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6028 return std::move(Err);
6029
6030 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6031
6032 // Import the ivar (for an @synthesize).
6033 ObjCIvarDecl *Ivar = nullptr;
6034 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6035 return std::move(Err);
6036
6037 ObjCPropertyImplDecl *ToImpl
6038 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6039 Property->getQueryKind());
6040 if (!ToImpl) {
6041
6042 Error Err = Error::success();
6043 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6044 auto ToLocation = importChecked(Err, D->getLocation());
6045 auto ToPropertyIvarDeclLoc =
6047 if (Err)
6048 return std::move(Err);
6049
6050 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6051 ToBeginLoc,
6052 ToLocation, Property,
6053 D->getPropertyImplementation(), Ivar,
6054 ToPropertyIvarDeclLoc))
6055 return ToImpl;
6056
6057 ToImpl->setLexicalDeclContext(LexicalDC);
6058 LexicalDC->addDeclInternal(ToImpl);
6059 } else {
6060 // Check that we have the same kind of property implementation (@synthesize
6061 // vs. @dynamic).
6063 Importer.ToDiag(ToImpl->getLocation(),
6064 diag::warn_odr_objc_property_impl_kind_inconsistent)
6065 << Property->getDeclName()
6066 << (ToImpl->getPropertyImplementation()
6068 Importer.FromDiag(D->getLocation(),
6069 diag::note_odr_objc_property_impl_kind)
6070 << D->getPropertyDecl()->getDeclName()
6072
6073 return make_error<ASTImportError>(ASTImportError::NameConflict);
6074 }
6075
6076 // For @synthesize, check that we have the same
6078 Ivar != ToImpl->getPropertyIvarDecl()) {
6079 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6080 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6081 << Property->getDeclName()
6082 << ToImpl->getPropertyIvarDecl()->getDeclName()
6083 << Ivar->getDeclName();
6084 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6085 diag::note_odr_objc_synthesize_ivar_here)
6087
6088 return make_error<ASTImportError>(ASTImportError::NameConflict);
6089 }
6090
6091 // Merge the existing implementation with the new implementation.
6092 Importer.MapImported(D, ToImpl);
6093 }
6094
6095 return ToImpl;
6096}
6097
6100 // For template arguments, we adopt the translation unit as our declaration
6101 // context. This context will be fixed when (during) the actual template
6102 // declaration is created.
6103
6104 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6105 if (!BeginLocOrErr)
6106 return BeginLocOrErr.takeError();
6107
6108 ExpectedSLoc LocationOrErr = import(D->getLocation());
6109 if (!LocationOrErr)
6110 return LocationOrErr.takeError();
6111
6112 TemplateTypeParmDecl *ToD = nullptr;
6113 if (GetImportedOrCreateDecl(
6114 ToD, D, Importer.getToContext(),
6115 Importer.getToContext().getTranslationUnitDecl(),
6116 *BeginLocOrErr, *LocationOrErr,
6117 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6119 D->hasTypeConstraint()))
6120 return ToD;
6121
6122 // Import the type-constraint
6123 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6124
6125 Error Err = Error::success();
6126 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6127 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6128 if (Err)
6129 return std::move(Err);
6130
6131 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6132 }
6133
6134 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6135 return Err;
6136
6137 return ToD;
6138}
6139
6142
6143 Error Err = Error::success();
6144 auto ToDeclName = importChecked(Err, D->getDeclName());
6145 auto ToLocation = importChecked(Err, D->getLocation());
6146 auto ToType = importChecked(Err, D->getType());
6147 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6148 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6149 if (Err)
6150 return std::move(Err);
6151
6152 NonTypeTemplateParmDecl *ToD = nullptr;
6153 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6154 Importer.getToContext().getTranslationUnitDecl(),
6155 ToInnerLocStart, ToLocation, D->getDepth(),
6156 D->getPosition(),
6157 ToDeclName.getAsIdentifierInfo(), ToType,
6158 D->isParameterPack(), ToTypeSourceInfo))
6159 return ToD;
6160
6161 Err = importTemplateParameterDefaultArgument(D, ToD);
6162 if (Err)
6163 return Err;
6164
6165 return ToD;
6166}
6167
6170 bool IsCanonical = false;
6171 if (auto *CanonD = Importer.getFromContext()
6172 .findCanonicalTemplateTemplateParmDeclInternal(D);
6173 CanonD == D)
6174 IsCanonical = true;
6175
6176 // Import the name of this declaration.
6177 auto NameOrErr = import(D->getDeclName());
6178 if (!NameOrErr)
6179 return NameOrErr.takeError();
6180
6181 // Import the location of this declaration.
6182 ExpectedSLoc LocationOrErr = import(D->getLocation());
6183 if (!LocationOrErr)
6184 return LocationOrErr.takeError();
6185
6186 // Import template parameters.
6187 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6188 if (!TemplateParamsOrErr)
6189 return TemplateParamsOrErr.takeError();
6190
6191 TemplateTemplateParmDecl *ToD = nullptr;
6192 if (GetImportedOrCreateDecl(
6193 ToD, D, Importer.getToContext(),
6194 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6195 D->getDepth(), D->getPosition(), D->isParameterPack(),
6196 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6197 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6198 return ToD;
6199
6200 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6201 return Err;
6202
6203 if (IsCanonical)
6204 return Importer.getToContext()
6205 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6206
6207 return ToD;
6208}
6209
6210// Returns the definition for a (forward) declaration of a TemplateDecl, if
6211// it has any definition in the redecl chain.
6212template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6213 assert(D->getTemplatedDecl() && "Should be called on templates only");
6214 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6215 if (!ToTemplatedDef)
6216 return nullptr;
6217 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6218 return cast_or_null<T>(TemplateWithDef);
6219}
6220
6222
6223 // Import the major distinguishing characteristics of this class template.
6224 DeclContext *DC, *LexicalDC;
6225 DeclarationName Name;
6226 SourceLocation Loc;
6227 NamedDecl *ToD;
6228 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6229 return std::move(Err);
6230 if (ToD)
6231 return ToD;
6232
6233 // Should check if a declaration is friend in a dependent context.
6234 // Such templates are not linked together in a declaration chain.
6235 // The ASTImporter strategy is to map existing forward declarations to
6236 // imported ones only if strictly necessary, otherwise import these as new
6237 // forward declarations. In case of the "dependent friend" declarations, new
6238 // declarations are created, but not linked in a declaration chain.
6239 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6240 return TD->getFriendObjectKind() != Decl::FOK_None &&
6241 TD->getLexicalDeclContext()->isDependentContext();
6242 };
6243 bool DependentFriend = IsDependentFriend(D);
6244
6245 ClassTemplateDecl *FoundByLookup = nullptr;
6246
6247 // We may already have a template of the same name; try to find and match it.
6248 if (!DC->isFunctionOrMethod()) {
6249 SmallVector<NamedDecl *, 4> ConflictingDecls;
6250 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6251 for (auto *FoundDecl : FoundDecls) {
6252 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6254 continue;
6255
6256 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6257 if (FoundTemplate) {
6258 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6259 continue;
6260
6261 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6262 bool IgnoreTemplateParmDepth =
6263 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6265 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6266 IgnoreTemplateParmDepth)) {
6267 if (DependentFriend || IsDependentFriend(FoundTemplate))
6268 continue;
6269
6270 ClassTemplateDecl *TemplateWithDef =
6271 getTemplateDefinition(FoundTemplate);
6272 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6273 return Importer.MapImported(D, TemplateWithDef);
6274 if (!FoundByLookup)
6275 FoundByLookup = FoundTemplate;
6276 // Search in all matches because there may be multiple decl chains,
6277 // see ASTTests test ImportExistingFriendClassTemplateDef.
6278 continue;
6279 }
6280 // When importing a friend, it is possible that multiple declarations
6281 // with same name can co-exist in specific cases (if a template contains
6282 // a friend template and has a specialization). For this case the
6283 // declarations should match, except that the "template depth" is
6284 // different. No linking of previous declaration is needed in this case.
6285 // FIXME: This condition may need refinement.
6286 if (D->getFriendObjectKind() != Decl::FOK_None &&
6287 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6288 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6289 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6290 /*IgnoreTemplateParmDepth=*/true))
6291 continue;
6292
6293 ConflictingDecls.push_back(FoundDecl);
6294 }
6295 }
6296
6297 if (!ConflictingDecls.empty()) {
6298 ExpectedName NameOrErr = Importer.HandleNameConflict(
6299 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6300 ConflictingDecls.size());
6301 if (NameOrErr)
6302 Name = NameOrErr.get();
6303 else
6304 return NameOrErr.takeError();
6305 }
6306 }
6307
6308 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6309
6310 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6311 if (!TemplateParamsOrErr)
6312 return TemplateParamsOrErr.takeError();
6313
6314 // Create the declaration that is being templated.
6315 CXXRecordDecl *ToTemplated;
6316 if (Error Err = importInto(ToTemplated, FromTemplated))
6317 return std::move(Err);
6318
6319 // Create the class template declaration itself.
6321 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6322 *TemplateParamsOrErr, ToTemplated))
6323 return D2;
6324
6325 ToTemplated->setDescribedClassTemplate(D2);
6326
6327 D2->setAccess(D->getAccess());
6328 D2->setLexicalDeclContext(LexicalDC);
6329
6330 addDeclToContexts(D, D2);
6331 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6332
6333 if (FoundByLookup) {
6334 auto *Recent =
6335 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6336
6337 // It is possible that during the import of the class template definition
6338 // we start the import of a fwd friend decl of the very same class template
6339 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6340 // had been created earlier and by that time the lookup could not find
6341 // anything existing, so it has no previous decl. Later, (still during the
6342 // import of the fwd friend decl) we start to import the definition again
6343 // and this time the lookup finds the previous fwd friend class template.
6344 // In this case we must set up the previous decl for the templated decl.
6345 if (!ToTemplated->getPreviousDecl()) {
6346 assert(FoundByLookup->getTemplatedDecl() &&
6347 "Found decl must have its templated decl set");
6348 CXXRecordDecl *PrevTemplated =
6349 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6350 if (ToTemplated != PrevTemplated)
6351 ToTemplated->setPreviousDecl(PrevTemplated);
6352 }
6353
6354 D2->setPreviousDecl(Recent);
6355 }
6356
6357 return D2;
6358}
6359
6362 ClassTemplateDecl *ClassTemplate;
6363 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6364 return std::move(Err);
6365
6366 // Import the context of this declaration.
6367 DeclContext *DC, *LexicalDC;
6368 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6369 return std::move(Err);
6370
6371 // Import template arguments.
6373 if (Error Err =
6374 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6375 return std::move(Err);
6376 // Try to find an existing specialization with these template arguments and
6377 // template parameter list.
6378 void *InsertPos = nullptr;
6379 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6381 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6382
6383 // Import template parameters.
6384 TemplateParameterList *ToTPList = nullptr;
6385
6386 if (PartialSpec) {
6387 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6388 if (!ToTPListOrErr)
6389 return ToTPListOrErr.takeError();
6390 ToTPList = *ToTPListOrErr;
6391 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6392 *ToTPListOrErr,
6393 InsertPos);
6394 } else
6395 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6396
6397 if (PrevDecl) {
6398 if (IsStructuralMatch(D, PrevDecl)) {
6399 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6400 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6401 Importer.MapImported(D, PrevDefinition);
6402 // Import those default field initializers which have been
6403 // instantiated in the "From" context, but not in the "To" context.
6404 for (auto *FromField : D->fields()) {
6405 auto ToOrErr = import(FromField);
6406 if (!ToOrErr)
6407 return ToOrErr.takeError();
6408 }
6409
6410 // Import those methods which have been instantiated in the
6411 // "From" context, but not in the "To" context.
6412 for (CXXMethodDecl *FromM : D->methods()) {
6413 auto ToOrErr = import(FromM);
6414 if (!ToOrErr)
6415 return ToOrErr.takeError();
6416 }
6417
6418 // TODO Import instantiated default arguments.
6419 // TODO Import instantiated exception specifications.
6420 //
6421 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6422 // what else could be fused during an AST merge.
6423 return PrevDefinition;
6424 }
6425 } else { // ODR violation.
6426 // FIXME HandleNameConflict
6427 return make_error<ASTImportError>(ASTImportError::NameConflict);
6428 }
6429 }
6430
6431 // Import the location of this declaration.
6432 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6433 if (!BeginLocOrErr)
6434 return BeginLocOrErr.takeError();
6435 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6436 if (!IdLocOrErr)
6437 return IdLocOrErr.takeError();
6438
6439 // Import TemplateArgumentListInfo.
6440 TemplateArgumentListInfo ToTAInfo;
6441 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6442 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6443 return std::move(Err);
6444 }
6445
6446 // Create the specialization.
6447 ClassTemplateSpecializationDecl *D2 = nullptr;
6448 if (PartialSpec) {
6449 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6450 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6451 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6452 /*CanonInjectedTST=*/CanQualType(),
6453 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6454 return D2;
6455
6456 // Update InsertPos, because preceding import calls may have invalidated
6457 // it by adding new specializations.
6459 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6460 InsertPos))
6461 // Add this partial specialization to the class template.
6462 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6464 import(PartialSpec->getInstantiatedFromMember()))
6465 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6466 else
6467 return ToInstOrErr.takeError();
6468
6469 updateLookupTableForTemplateParameters(*ToTPList);
6470 } else { // Not a partial specialization.
6471 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6472 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6473 TemplateArgs, D->hasStrictPackMatch(),
6474 PrevDecl))
6475 return D2;
6476
6477 // Update InsertPos, because preceding import calls may have invalidated
6478 // it by adding new specializations.
6479 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6480 // Add this specialization to the class template.
6481 ClassTemplate->AddSpecialization(D2, InsertPos);
6482 }
6483
6485
6486 // Set the context of this specialization/instantiation.
6487 D2->setLexicalDeclContext(LexicalDC);
6488
6489 // Add to the DC only if it was an explicit specialization/instantiation.
6491 LexicalDC->addDeclInternal(D2);
6492 }
6493
6494 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6495 D2->setBraceRange(*BraceRangeOrErr);
6496 else
6497 return BraceRangeOrErr.takeError();
6498
6499 if (Error Err = ImportTemplateParameterLists(D, D2))
6500 return std::move(Err);
6501
6502 // Import the qualifier, if any.
6503 if (auto LocOrErr = import(D->getQualifierLoc()))
6504 D2->setQualifierInfo(*LocOrErr);
6505 else
6506 return LocOrErr.takeError();
6507
6508 if (D->getTemplateArgsAsWritten())
6509 D2->setTemplateArgsAsWritten(ToTAInfo);
6510
6511 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6512 D2->setTemplateKeywordLoc(*LocOrErr);
6513 else
6514 return LocOrErr.takeError();
6515
6516 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6517 D2->setExternKeywordLoc(*LocOrErr);
6518 else
6519 return LocOrErr.takeError();
6520
6521 if (D->getPointOfInstantiation().isValid()) {
6522 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6523 D2->setPointOfInstantiation(*POIOrErr);
6524 else
6525 return POIOrErr.takeError();
6526 }
6527
6529
6530 if (auto P = D->getInstantiatedFrom()) {
6531 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6532 if (auto CTDorErr = import(CTD))
6533 D2->setInstantiationOf(*CTDorErr);
6534 } else {
6536 auto CTPSDOrErr = import(CTPSD);
6537 if (!CTPSDOrErr)
6538 return CTPSDOrErr.takeError();
6540 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6541 for (unsigned I = 0; I < DArgs.size(); ++I) {
6542 const TemplateArgument &DArg = DArgs[I];
6543 if (auto ArgOrErr = import(DArg))
6544 D2ArgsVec[I] = *ArgOrErr;
6545 else
6546 return ArgOrErr.takeError();
6547 }
6549 *CTPSDOrErr,
6550 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6551 }
6552 }
6553
6554 if (D->isCompleteDefinition())
6555 if (Error Err = ImportDefinition(D, D2))
6556 return std::move(Err);
6557
6558 return D2;
6559}
6560
6562 // Import the major distinguishing characteristics of this variable template.
6563 DeclContext *DC, *LexicalDC;
6564 DeclarationName Name;
6565 SourceLocation Loc;
6566 NamedDecl *ToD;
6567 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6568 return std::move(Err);
6569 if (ToD)
6570 return ToD;
6571
6572 // We may already have a template of the same name; try to find and match it.
6573 assert(!DC->isFunctionOrMethod() &&
6574 "Variable templates cannot be declared at function scope");
6575
6576 SmallVector<NamedDecl *, 4> ConflictingDecls;
6577 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6578 VarTemplateDecl *FoundByLookup = nullptr;
6579 for (auto *FoundDecl : FoundDecls) {
6580 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6581 continue;
6582
6583 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6584 // Use the templated decl, some linkage flags are set only there.
6585 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6586 D->getTemplatedDecl()))
6587 continue;
6588 if (IsStructuralMatch(D, FoundTemplate)) {
6589 // FIXME Check for ODR error if the two definitions have
6590 // different initializers?
6591 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6592 if (D->getDeclContext()->isRecord()) {
6593 assert(FoundTemplate->getDeclContext()->isRecord() &&
6594 "Member variable template imported as non-member, "
6595 "inconsistent imported AST?");
6596 if (FoundDef)
6597 return Importer.MapImported(D, FoundDef);
6599 return Importer.MapImported(D, FoundTemplate);
6600 } else {
6601 if (FoundDef && D->isThisDeclarationADefinition())
6602 return Importer.MapImported(D, FoundDef);
6603 }
6604 FoundByLookup = FoundTemplate;
6605 break;
6606 }
6607 ConflictingDecls.push_back(FoundDecl);
6608 }
6609 }
6610
6611 if (!ConflictingDecls.empty()) {
6612 ExpectedName NameOrErr = Importer.HandleNameConflict(
6613 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6614 ConflictingDecls.size());
6615 if (NameOrErr)
6616 Name = NameOrErr.get();
6617 else
6618 return NameOrErr.takeError();
6619 }
6620
6621 VarDecl *DTemplated = D->getTemplatedDecl();
6622
6623 // Import the type.
6624 // FIXME: Value not used?
6625 ExpectedType TypeOrErr = import(DTemplated->getType());
6626 if (!TypeOrErr)
6627 return TypeOrErr.takeError();
6628
6629 // Create the declaration that is being templated.
6630 VarDecl *ToTemplated;
6631 if (Error Err = importInto(ToTemplated, DTemplated))
6632 return std::move(Err);
6633
6634 // Create the variable template declaration itself.
6635 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6636 if (!TemplateParamsOrErr)
6637 return TemplateParamsOrErr.takeError();
6638
6639 VarTemplateDecl *ToVarTD;
6640 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6641 Name, *TemplateParamsOrErr, ToTemplated))
6642 return ToVarTD;
6643
6644 ToTemplated->setDescribedVarTemplate(ToVarTD);
6645
6646 ToVarTD->setAccess(D->getAccess());
6647 ToVarTD->setLexicalDeclContext(LexicalDC);
6648 LexicalDC->addDeclInternal(ToVarTD);
6649 if (DC != Importer.getToContext().getTranslationUnitDecl())
6650 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6651
6652 if (FoundByLookup) {
6653 auto *Recent =
6654 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6655 if (!ToTemplated->getPreviousDecl()) {
6656 auto *PrevTemplated =
6657 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6658 if (ToTemplated != PrevTemplated)
6659 ToTemplated->setPreviousDecl(PrevTemplated);
6660 }
6661 ToVarTD->setPreviousDecl(Recent);
6662 }
6663
6664 return ToVarTD;
6665}
6666
6669 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6670 // in an analog way (but specialized for this case).
6671
6673 auto RedeclIt = Redecls.begin();
6674 // Import the first part of the decl chain. I.e. import all previous
6675 // declarations starting from the canonical decl.
6676 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6677 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6678 if (!RedeclOrErr)
6679 return RedeclOrErr.takeError();
6680 }
6681 assert(*RedeclIt == D);
6682
6683 VarTemplateDecl *VarTemplate = nullptr;
6684 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6685 return std::move(Err);
6686
6687 // Import the context of this declaration.
6688 DeclContext *DC, *LexicalDC;
6689 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6690 return std::move(Err);
6691
6692 // Import the location of this declaration.
6693 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6694 if (!BeginLocOrErr)
6695 return BeginLocOrErr.takeError();
6696
6697 auto IdLocOrErr = import(D->getLocation());
6698 if (!IdLocOrErr)
6699 return IdLocOrErr.takeError();
6700
6701 // Import template arguments.
6703 if (Error Err =
6704 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6705 return std::move(Err);
6706
6707 // Try to find an existing specialization with these template arguments.
6708 void *InsertPos = nullptr;
6709 VarTemplateSpecializationDecl *FoundSpecialization =
6710 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6711 if (FoundSpecialization) {
6712 if (IsStructuralMatch(D, FoundSpecialization)) {
6713 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6714 if (D->getDeclContext()->isRecord()) {
6715 // In a record, it is allowed only to have one optional declaration and
6716 // one definition of the (static or constexpr) variable template.
6717 assert(
6718 FoundSpecialization->getDeclContext()->isRecord() &&
6719 "Member variable template specialization imported as non-member, "
6720 "inconsistent imported AST?");
6721 if (FoundDef)
6722 return Importer.MapImported(D, FoundDef);
6724 return Importer.MapImported(D, FoundSpecialization);
6725 } else {
6726 // If definition is imported and there is already one, map to it.
6727 // Otherwise create a new variable and link it to the existing.
6728 if (FoundDef && D->isThisDeclarationADefinition())
6729 return Importer.MapImported(D, FoundDef);
6730 }
6731 } else {
6732 return make_error<ASTImportError>(ASTImportError::NameConflict);
6733 }
6734 }
6735
6736 VarTemplateSpecializationDecl *D2 = nullptr;
6737
6738 TemplateArgumentListInfo ToTAInfo;
6739 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6740 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6741 return std::move(Err);
6742 }
6743
6744 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6745 // Create a new specialization.
6746 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6747 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6748 if (!ToTPListOrErr)
6749 return ToTPListOrErr.takeError();
6750
6751 PartVarSpecDecl *ToPartial;
6752 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6753 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6754 VarTemplate, QualType(), nullptr,
6755 D->getStorageClass(), TemplateArgs))
6756 return ToPartial;
6757
6758 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6759 import(FromPartial->getInstantiatedFromMember()))
6760 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6761 else
6762 return ToInstOrErr.takeError();
6763
6764 if (FromPartial->isMemberSpecialization())
6765 ToPartial->setMemberSpecialization();
6766
6767 D2 = ToPartial;
6768
6769 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6770 // to adopt template parameters.
6771 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6772 } else { // Full specialization
6773 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6774 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6775 QualType(), nullptr, D->getStorageClass(),
6776 TemplateArgs))
6777 return D2;
6778 }
6779
6780 // Update InsertPos, because preceding import calls may have invalidated
6781 // it by adding new specializations.
6782 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6783 VarTemplate->AddSpecialization(D2, InsertPos);
6784
6785 QualType T;
6786 if (Error Err = importInto(T, D->getType()))
6787 return std::move(Err);
6788 D2->setType(T);
6789
6790 auto TInfoOrErr = import(D->getTypeSourceInfo());
6791 if (!TInfoOrErr)
6792 return TInfoOrErr.takeError();
6793 D2->setTypeSourceInfo(*TInfoOrErr);
6794
6795 if (D->getPointOfInstantiation().isValid()) {
6796 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6797 D2->setPointOfInstantiation(*POIOrErr);
6798 else
6799 return POIOrErr.takeError();
6800 }
6801
6803
6804 if (D->getTemplateArgsAsWritten())
6805 D2->setTemplateArgsAsWritten(ToTAInfo);
6806
6807 if (auto LocOrErr = import(D->getQualifierLoc()))
6808 D2->setQualifierInfo(*LocOrErr);
6809 else
6810 return LocOrErr.takeError();
6811
6812 if (D->isConstexpr())
6813 D2->setConstexpr(true);
6814
6815 D2->setAccess(D->getAccess());
6816
6817 if (Error Err = ImportInitializer(D, D2))
6818 return std::move(Err);
6819
6820 if (FoundSpecialization)
6821 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6822
6823 addDeclToContexts(D, D2);
6824
6825 // Import the rest of the chain. I.e. import all subsequent declarations.
6826 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6827 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6828 if (!RedeclOrErr)
6829 return RedeclOrErr.takeError();
6830 }
6831
6832 return D2;
6833}
6834
6837 DeclContext *DC, *LexicalDC;
6838 DeclarationName Name;
6839 SourceLocation Loc;
6840 NamedDecl *ToD;
6841
6842 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6843 return std::move(Err);
6844
6845 if (ToD)
6846 return ToD;
6847
6848 const FunctionTemplateDecl *FoundByLookup = nullptr;
6849
6850 // Try to find a function in our own ("to") context with the same name, same
6851 // type, and in the same context as the function we're importing.
6852 // FIXME Split this into a separate function.
6853 if (!LexicalDC->isFunctionOrMethod()) {
6855 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6856 for (auto *FoundDecl : FoundDecls) {
6857 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6858 continue;
6859
6860 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6861 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6862 continue;
6863 if (IsStructuralMatch(D, FoundTemplate)) {
6864 FunctionTemplateDecl *TemplateWithDef =
6865 getTemplateDefinition(FoundTemplate);
6866 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6867 return Importer.MapImported(D, TemplateWithDef);
6868
6869 FoundByLookup = FoundTemplate;
6870 break;
6871 // TODO: handle conflicting names
6872 }
6873 }
6874 }
6875 }
6876
6877 auto ParamsOrErr = import(D->getTemplateParameters());
6878 if (!ParamsOrErr)
6879 return ParamsOrErr.takeError();
6880 TemplateParameterList *Params = *ParamsOrErr;
6881
6882 FunctionDecl *TemplatedFD;
6883 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6884 return std::move(Err);
6885
6886 // At creation of the template the template parameters are "adopted"
6887 // (DeclContext is changed). After this possible change the lookup table
6888 // must be updated.
6889 // At deduction guides the DeclContext of the template parameters may be
6890 // different from what we would expect, it may be the class template, or a
6891 // probably different CXXDeductionGuideDecl. This may come from the fact that
6892 // the template parameter objects may be shared between deduction guides or
6893 // the class template, and at creation of multiple FunctionTemplateDecl
6894 // objects (for deduction guides) the same parameters are re-used. The
6895 // "adoption" happens multiple times with different parent, even recursively
6896 // for TemplateTemplateParmDecl. The same happens at import when the
6897 // FunctionTemplateDecl objects are created, but in different order.
6898 // In this way the DeclContext of these template parameters is not necessarily
6899 // the same as in the "from" context.
6901 OldParamDC.reserve(Params->size());
6902 llvm::transform(*Params, std::back_inserter(OldParamDC),
6903 [](NamedDecl *ND) { return ND->getDeclContext(); });
6904
6905 FunctionTemplateDecl *ToFunc;
6906 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6907 Params, TemplatedFD))
6908 return ToFunc;
6909
6910 // Fail if TemplatedFD is already part of a template.
6911 // The template should have been found by structural equivalence check before,
6912 // or ToFunc should be already imported.
6913 // If not, there is AST incompatibility that can be caused by previous import
6914 // errors. (NameConflict is not exact here.)
6915 if (TemplatedFD->getDescribedTemplate())
6916 return make_error<ASTImportError>(ASTImportError::NameConflict);
6917
6918 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6919
6920 ToFunc->setAccess(D->getAccess());
6921 ToFunc->setLexicalDeclContext(LexicalDC);
6922 addDeclToContexts(D, ToFunc);
6923
6924 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6925 if (LT && !OldParamDC.empty()) {
6926 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6927 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6928 }
6929
6930 if (FoundByLookup) {
6931 auto *Recent =
6932 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6933 if (!TemplatedFD->getPreviousDecl()) {
6934 assert(FoundByLookup->getTemplatedDecl() &&
6935 "Found decl must have its templated decl set");
6936 auto *PrevTemplated =
6937 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6938 if (TemplatedFD != PrevTemplated)
6939 TemplatedFD->setPreviousDecl(PrevTemplated);
6940 }
6941 ToFunc->setPreviousDecl(Recent);
6942 }
6943
6944 return ToFunc;
6945}
6946
6948 DeclContext *DC, *LexicalDC;
6949 Error Err = ImportDeclContext(D, DC, LexicalDC);
6950 auto LocationOrErr = importChecked(Err, D->getLocation());
6951 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6952 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6953 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6954 if (Err)
6955 return std::move(Err);
6956
6957 ConceptDecl *To;
6958 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6959 NameDeclOrErr, ToTemplateParameters,
6960 ConstraintExpr))
6961 return To;
6962 To->setLexicalDeclContext(LexicalDC);
6963 LexicalDC->addDeclInternal(To);
6964 return To;
6965}
6966
6969 DeclContext *DC, *LexicalDC;
6970 Error Err = ImportDeclContext(D, DC, LexicalDC);
6971 auto RequiresLoc = importChecked(Err, D->getLocation());
6972 if (Err)
6973 return std::move(Err);
6974
6976 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
6977 return To;
6978 To->setLexicalDeclContext(LexicalDC);
6979 LexicalDC->addDeclInternal(To);
6980 return To;
6981}
6982
6985 DeclContext *DC, *LexicalDC;
6986 Error Err = ImportDeclContext(D, DC, LexicalDC);
6987 auto ToSL = importChecked(Err, D->getLocation());
6988 if (Err)
6989 return std::move(Err);
6990
6992 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
6993 return std::move(Err);
6994
6996 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
6997 return To;
6998 To->setLexicalDeclContext(LexicalDC);
6999 LexicalDC->addDeclInternal(To);
7000 return To;
7001}
7002
7003//----------------------------------------------------------------------------
7004// Import Statements
7005//----------------------------------------------------------------------------
7006
7008 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7009 << S->getStmtClassName();
7010 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7011}
7012
7013
7015 if (Importer.returnWithErrorInTest())
7016 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7018 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7019 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7020 // ToII is nullptr when no symbolic name is given for output operand
7021 // see ParseStmtAsm::ParseAsmOperandsOpt
7022 Names.push_back(ToII);
7023 }
7024
7025 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7026 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7027 // ToII is nullptr when no symbolic name is given for input operand
7028 // see ParseStmtAsm::ParseAsmOperandsOpt
7029 Names.push_back(ToII);
7030 }
7031
7032 SmallVector<Expr *, 4> Clobbers;
7033 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7034 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7035 Clobbers.push_back(*ClobberOrErr);
7036 else
7037 return ClobberOrErr.takeError();
7038
7039 }
7040
7041 SmallVector<Expr *, 4> Constraints;
7042 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7043 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7044 Constraints.push_back(*OutputOrErr);
7045 else
7046 return OutputOrErr.takeError();
7047 }
7048
7049 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7050 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7051 Constraints.push_back(*InputOrErr);
7052 else
7053 return InputOrErr.takeError();
7054 }
7055
7057 S->getNumLabels());
7058 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7059 return std::move(Err);
7060
7061 if (Error Err =
7062 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7063 return std::move(Err);
7064
7065 if (Error Err = ImportArrayChecked(
7066 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7067 return std::move(Err);
7068
7069 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7070 if (!AsmLocOrErr)
7071 return AsmLocOrErr.takeError();
7072 auto AsmStrOrErr = import(S->getAsmStringExpr());
7073 if (!AsmStrOrErr)
7074 return AsmStrOrErr.takeError();
7075 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7076 if (!RParenLocOrErr)
7077 return RParenLocOrErr.takeError();
7078
7079 return new (Importer.getToContext()) GCCAsmStmt(
7080 Importer.getToContext(),
7081 *AsmLocOrErr,
7082 S->isSimple(),
7083 S->isVolatile(),
7084 S->getNumOutputs(),
7085 S->getNumInputs(),
7086 Names.data(),
7087 Constraints.data(),
7088 Exprs.data(),
7089 *AsmStrOrErr,
7090 S->getNumClobbers(),
7091 Clobbers.data(),
7092 S->getNumLabels(),
7093 *RParenLocOrErr);
7094}
7095
7097
7098 Error Err = Error::success();
7099 auto ToDG = importChecked(Err, S->getDeclGroup());
7100 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7101 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7102 if (Err)
7103 return std::move(Err);
7104 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7105}
7106
7108 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7109 if (!ToSemiLocOrErr)
7110 return ToSemiLocOrErr.takeError();
7111 return new (Importer.getToContext()) NullStmt(
7112 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7113}
7114
7116 SmallVector<Stmt *, 8> ToStmts(S->size());
7117
7118 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7119 return std::move(Err);
7120
7121 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7122 if (!ToLBracLocOrErr)
7123 return ToLBracLocOrErr.takeError();
7124
7125 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7126 if (!ToRBracLocOrErr)
7127 return ToRBracLocOrErr.takeError();
7128
7129 FPOptionsOverride FPO =
7131 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7132 *ToLBracLocOrErr, *ToRBracLocOrErr);
7133}
7134
7136
7137 Error Err = Error::success();
7138 auto ToLHS = importChecked(Err, S->getLHS());
7139 auto ToRHS = importChecked(Err, S->getRHS());
7140 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7141 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7142 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7143 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7144 if (Err)
7145 return std::move(Err);
7146
7147 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7148 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7149 ToStmt->setSubStmt(ToSubStmt);
7150
7151 return ToStmt;
7152}
7153
7155
7156 Error Err = Error::success();
7157 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7158 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7159 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7160 if (Err)
7161 return std::move(Err);
7162
7163 return new (Importer.getToContext()) DefaultStmt(
7164 ToDefaultLoc, ToColonLoc, ToSubStmt);
7165}
7166
7168
7169 Error Err = Error::success();
7170 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7171 auto ToLabelDecl = importChecked(Err, S->getDecl());
7172 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7173 if (Err)
7174 return std::move(Err);
7175
7176 return new (Importer.getToContext()) LabelStmt(
7177 ToIdentLoc, ToLabelDecl, ToSubStmt);
7178}
7179
7181 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7182 if (!ToAttrLocOrErr)
7183 return ToAttrLocOrErr.takeError();
7184 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7185 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7186 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7187 return std::move(Err);
7188 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7189 if (!ToSubStmtOrErr)
7190 return ToSubStmtOrErr.takeError();
7191
7193 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7194}
7195
7197
7198 Error Err = Error::success();
7199 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7200 auto ToInit = importChecked(Err, S->getInit());
7201 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7202 auto ToCond = importChecked(Err, S->getCond());
7203 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7204 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7205 auto ToThen = importChecked(Err, S->getThen());
7206 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7207 auto ToElse = importChecked(Err, S->getElse());
7208 if (Err)
7209 return std::move(Err);
7210
7211 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7212 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7213 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7214}
7215
7217
7218 Error Err = Error::success();
7219 auto ToInit = importChecked(Err, S->getInit());
7220 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7221 auto ToCond = importChecked(Err, S->getCond());
7222 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7223 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7224 auto ToBody = importChecked(Err, S->getBody());
7225 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7226 if (Err)
7227 return std::move(Err);
7228
7229 auto *ToStmt =
7230 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7231 ToCond, ToLParenLoc, ToRParenLoc);
7232 ToStmt->setBody(ToBody);
7233 ToStmt->setSwitchLoc(ToSwitchLoc);
7234
7235 // Now we have to re-chain the cases.
7236 SwitchCase *LastChainedSwitchCase = nullptr;
7237 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7238 SC = SC->getNextSwitchCase()) {
7239 Expected<SwitchCase *> ToSCOrErr = import(SC);
7240 if (!ToSCOrErr)
7241 return ToSCOrErr.takeError();
7242 if (LastChainedSwitchCase)
7243 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7244 else
7245 ToStmt->setSwitchCaseList(*ToSCOrErr);
7246 LastChainedSwitchCase = *ToSCOrErr;
7247 }
7248
7249 return ToStmt;
7250}
7251
7253
7254 Error Err = Error::success();
7255 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7256 auto ToCond = importChecked(Err, S->getCond());
7257 auto ToBody = importChecked(Err, S->getBody());
7258 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7259 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7260 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7261 if (Err)
7262 return std::move(Err);
7263
7264 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7265 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7266}
7267
7269
7270 Error Err = Error::success();
7271 auto ToBody = importChecked(Err, S->getBody());
7272 auto ToCond = importChecked(Err, S->getCond());
7273 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7274 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7275 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7276 if (Err)
7277 return std::move(Err);
7278
7279 return new (Importer.getToContext()) DoStmt(
7280 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7281}
7282
7284
7285 Error Err = Error::success();
7286 auto ToInit = importChecked(Err, S->getInit());
7287 auto ToCond = importChecked(Err, S->getCond());
7288 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7289 auto ToInc = importChecked(Err, S->getInc());
7290 auto ToBody = importChecked(Err, S->getBody());
7291 auto ToForLoc = importChecked(Err, S->getForLoc());
7292 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7293 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7294 if (Err)
7295 return std::move(Err);
7296
7297 return new (Importer.getToContext()) ForStmt(
7298 Importer.getToContext(),
7299 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7300 ToRParenLoc);
7301}
7302
7304
7305 Error Err = Error::success();
7306 auto ToLabel = importChecked(Err, S->getLabel());
7307 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7308 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7309 if (Err)
7310 return std::move(Err);
7311
7312 return new (Importer.getToContext()) GotoStmt(
7313 ToLabel, ToGotoLoc, ToLabelLoc);
7314}
7315
7317
7318 Error Err = Error::success();
7319 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7320 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7321 auto ToTarget = importChecked(Err, S->getTarget());
7322 if (Err)
7323 return std::move(Err);
7324
7325 return new (Importer.getToContext()) IndirectGotoStmt(
7326 ToGotoLoc, ToStarLoc, ToTarget);
7327}
7328
7329template <typename StmtClass>
7331 ASTImporter &Importer, StmtClass *S) {
7332 Error Err = Error::success();
7333 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7334 auto ToLabelLoc = S->hasLabelTarget()
7335 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7336 : SourceLocation();
7337 auto ToDecl = S->hasLabelTarget()
7338 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7339 : nullptr;
7340 if (Err)
7341 return std::move(Err);
7342 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7343}
7344
7348
7352
7354
7355 Error Err = Error::success();
7356 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7357 auto ToRetValue = importChecked(Err, S->getRetValue());
7358 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7359 if (Err)
7360 return std::move(Err);
7361
7362 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7363 ToNRVOCandidate);
7364}
7365
7367
7368 Error Err = Error::success();
7369 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7370 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7371 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7372 if (Err)
7373 return std::move(Err);
7374
7375 return new (Importer.getToContext()) CXXCatchStmt (
7376 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7377}
7378
7380 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7381 if (!ToTryLocOrErr)
7382 return ToTryLocOrErr.takeError();
7383
7384 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7385 if (!ToTryBlockOrErr)
7386 return ToTryBlockOrErr.takeError();
7387
7388 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7389 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7390 CXXCatchStmt *FromHandler = S->getHandler(HI);
7391 if (auto ToHandlerOrErr = import(FromHandler))
7392 ToHandlers[HI] = *ToHandlerOrErr;
7393 else
7394 return ToHandlerOrErr.takeError();
7395 }
7396
7397 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7398 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7399}
7400
7402
7403 Error Err = Error::success();
7404 auto ToInit = importChecked(Err, S->getInit());
7405 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7406 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7407 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7408 auto ToCond = importChecked(Err, S->getCond());
7409 auto ToInc = importChecked(Err, S->getInc());
7410 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7411 auto ToBody = importChecked(Err, S->getBody());
7412 auto ToForLoc = importChecked(Err, S->getForLoc());
7413 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7414 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7415 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7416 if (Err)
7417 return std::move(Err);
7418
7419 return new (Importer.getToContext()) CXXForRangeStmt(
7420 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7421 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7422}
7423
7426 Error Err = Error::success();
7427 auto ToElement = importChecked(Err, S->getElement());
7428 auto ToCollection = importChecked(Err, S->getCollection());
7429 auto ToBody = importChecked(Err, S->getBody());
7430 auto ToForLoc = importChecked(Err, S->getForLoc());
7431 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7432 if (Err)
7433 return std::move(Err);
7434
7435 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7436 ToCollection,
7437 ToBody,
7438 ToForLoc,
7439 ToRParenLoc);
7440}
7441
7443
7444 Error Err = Error::success();
7445 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7446 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7447 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7448 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7449 if (Err)
7450 return std::move(Err);
7451
7452 return new (Importer.getToContext()) ObjCAtCatchStmt (
7453 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7454}
7455
7457 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7458 if (!ToAtFinallyLocOrErr)
7459 return ToAtFinallyLocOrErr.takeError();
7460 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7461 if (!ToAtFinallyStmtOrErr)
7462 return ToAtFinallyStmtOrErr.takeError();
7463 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7464 *ToAtFinallyStmtOrErr);
7465}
7466
7468
7469 Error Err = Error::success();
7470 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7471 auto ToTryBody = importChecked(Err, S->getTryBody());
7472 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7473 if (Err)
7474 return std::move(Err);
7475
7476 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7477 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7478 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7479 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7480 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7481 else
7482 return ToCatchStmtOrErr.takeError();
7483 }
7484
7485 return ObjCAtTryStmt::Create(Importer.getToContext(),
7486 ToAtTryLoc, ToTryBody,
7487 ToCatchStmts.begin(), ToCatchStmts.size(),
7488 ToFinallyStmt);
7489}
7490
7493
7494 Error Err = Error::success();
7495 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7496 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7497 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7498 if (Err)
7499 return std::move(Err);
7500
7501 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7502 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7503}
7504
7506 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7507 if (!ToThrowLocOrErr)
7508 return ToThrowLocOrErr.takeError();
7509 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7510 if (!ToThrowExprOrErr)
7511 return ToThrowExprOrErr.takeError();
7512 return new (Importer.getToContext()) ObjCAtThrowStmt(
7513 *ToThrowLocOrErr, *ToThrowExprOrErr);
7514}
7515
7518 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7519 if (!ToAtLocOrErr)
7520 return ToAtLocOrErr.takeError();
7521 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7522 if (!ToSubStmtOrErr)
7523 return ToSubStmtOrErr.takeError();
7524 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7525 *ToSubStmtOrErr);
7526}
7527
7528//----------------------------------------------------------------------------
7529// Import Expressions
7530//----------------------------------------------------------------------------
7532 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7533 << E->getStmtClassName();
7534 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7535}
7536
7538 Error Err = Error::success();
7539 auto ToType = importChecked(Err, E->getType());
7540 auto BLoc = importChecked(Err, E->getBeginLoc());
7541 auto RParenLoc = importChecked(Err, E->getEndLoc());
7542 if (Err)
7543 return std::move(Err);
7544 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7545 if (!ParentContextOrErr)
7546 return ParentContextOrErr.takeError();
7547
7548 return new (Importer.getToContext())
7549 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7550 RParenLoc, *ParentContextOrErr);
7551}
7552
7554
7555 Error Err = Error::success();
7556 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7557 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7558 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7559 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7560 auto ToType = importChecked(Err, E->getType());
7561 if (Err)
7562 return std::move(Err);
7563
7564 return new (Importer.getToContext()) VAArgExpr(
7565 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7566 E->isMicrosoftABI());
7567}
7568
7570
7571 Error Err = Error::success();
7572 auto ToCond = importChecked(Err, E->getCond());
7573 auto ToLHS = importChecked(Err, E->getLHS());
7574 auto ToRHS = importChecked(Err, E->getRHS());
7575 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7576 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7577 auto ToType = importChecked(Err, E->getType());
7578 if (Err)
7579 return std::move(Err);
7580
7582 ExprObjectKind OK = E->getObjectKind();
7583
7584 // The value of CondIsTrue only matters if the value is not
7585 // condition-dependent.
7586 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7587
7588 return new (Importer.getToContext())
7589 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7590 ToRParenLoc, CondIsTrue);
7591}
7592
7594 Error Err = Error::success();
7595 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7596 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7597 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7598 auto ToType = importChecked(Err, E->getType());
7599 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7600 if (Err)
7601 return std::move(Err);
7602
7604 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7605 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7607}
7608
7610 Error Err = Error::success();
7611 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7612 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7613 auto ToType = importChecked(Err, E->getType());
7614 const unsigned NumSubExprs = E->getNumSubExprs();
7615
7617 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7618 ToSubExprs.resize(NumSubExprs);
7619
7620 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7621 return std::move(Err);
7622
7623 return new (Importer.getToContext()) ShuffleVectorExpr(
7624 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7625}
7626
7628 ExpectedType TypeOrErr = import(E->getType());
7629 if (!TypeOrErr)
7630 return TypeOrErr.takeError();
7631
7632 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7633 if (!BeginLocOrErr)
7634 return BeginLocOrErr.takeError();
7635
7636 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7637}
7638
7641 Error Err = Error::success();
7642 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7643 Expr *ToControllingExpr = nullptr;
7644 TypeSourceInfo *ToControllingType = nullptr;
7645 if (E->isExprPredicate())
7646 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7647 else
7648 ToControllingType = importChecked(Err, E->getControllingType());
7649 assert((ToControllingExpr || ToControllingType) &&
7650 "Either the controlling expr or type must be nonnull");
7651 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7652 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7653 if (Err)
7654 return std::move(Err);
7655
7657 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7658 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7659 return std::move(Err);
7660
7661 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7662 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7663 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7664 return std::move(Err);
7665
7666 const ASTContext &ToCtx = Importer.getToContext();
7667 if (E->isResultDependent()) {
7668 if (ToControllingExpr) {
7670 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7671 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7673 }
7675 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7676 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7678 }
7679
7680 if (ToControllingExpr) {
7682 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7683 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7685 }
7687 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7688 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7690}
7691
7693
7694 Error Err = Error::success();
7695 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7696 auto ToType = importChecked(Err, E->getType());
7697 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7698 if (Err)
7699 return std::move(Err);
7700
7701 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7702 E->getIdentKind(), E->isTransparent(),
7703 ToFunctionName);
7704}
7705
7707
7708 Error Err = Error::success();
7709 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7710 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7711 auto ToDecl = importChecked(Err, E->getDecl());
7712 auto ToLocation = importChecked(Err, E->getLocation());
7713 auto ToType = importChecked(Err, E->getType());
7714 if (Err)
7715 return std::move(Err);
7716
7717 NamedDecl *ToFoundD = nullptr;
7718 if (E->getDecl() != E->getFoundDecl()) {
7719 auto FoundDOrErr = import(E->getFoundDecl());
7720 if (!FoundDOrErr)
7721 return FoundDOrErr.takeError();
7722 ToFoundD = *FoundDOrErr;
7723 }
7724
7725 TemplateArgumentListInfo ToTAInfo;
7726 TemplateArgumentListInfo *ToResInfo = nullptr;
7727 if (E->hasExplicitTemplateArgs()) {
7728 if (Error Err =
7730 E->template_arguments(), ToTAInfo))
7731 return std::move(Err);
7732 ToResInfo = &ToTAInfo;
7733 }
7734
7735 auto *ToE = DeclRefExpr::Create(
7736 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7737 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7738 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7739 if (E->hadMultipleCandidates())
7740 ToE->setHadMultipleCandidates(true);
7741 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7742 return ToE;
7743}
7744
7746 ExpectedType TypeOrErr = import(E->getType());
7747 if (!TypeOrErr)
7748 return TypeOrErr.takeError();
7749
7750 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7751}
7752
7754 ExpectedExpr ToInitOrErr = import(E->getInit());
7755 if (!ToInitOrErr)
7756 return ToInitOrErr.takeError();
7757
7758 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7759 if (!ToEqualOrColonLocOrErr)
7760 return ToEqualOrColonLocOrErr.takeError();
7761
7762 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7763 // List elements from the second, the first is Init itself
7764 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7765 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7766 ToIndexExprs[I - 1] = *ToArgOrErr;
7767 else
7768 return ToArgOrErr.takeError();
7769 }
7770
7771 SmallVector<Designator, 4> ToDesignators(E->size());
7772 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7773 return std::move(Err);
7774
7776 Importer.getToContext(), ToDesignators,
7777 ToIndexExprs, *ToEqualOrColonLocOrErr,
7778 E->usesGNUSyntax(), *ToInitOrErr);
7779}
7780
7783 ExpectedType ToTypeOrErr = import(E->getType());
7784 if (!ToTypeOrErr)
7785 return ToTypeOrErr.takeError();
7786
7787 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7788 if (!ToLocationOrErr)
7789 return ToLocationOrErr.takeError();
7790
7791 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7792 *ToTypeOrErr, *ToLocationOrErr);
7793}
7794
7796 ExpectedType ToTypeOrErr = import(E->getType());
7797 if (!ToTypeOrErr)
7798 return ToTypeOrErr.takeError();
7799
7800 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7801 if (!ToLocationOrErr)
7802 return ToLocationOrErr.takeError();
7803
7805 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7806}
7807
7808
7810 ExpectedType ToTypeOrErr = import(E->getType());
7811 if (!ToTypeOrErr)
7812 return ToTypeOrErr.takeError();
7813
7814 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7815 if (!ToLocationOrErr)
7816 return ToLocationOrErr.takeError();
7817
7819 Importer.getToContext(), E->getValue(), E->isExact(),
7820 *ToTypeOrErr, *ToLocationOrErr);
7821}
7822
7824 auto ToTypeOrErr = import(E->getType());
7825 if (!ToTypeOrErr)
7826 return ToTypeOrErr.takeError();
7827
7828 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7829 if (!ToSubExprOrErr)
7830 return ToSubExprOrErr.takeError();
7831
7832 return new (Importer.getToContext()) ImaginaryLiteral(
7833 *ToSubExprOrErr, *ToTypeOrErr);
7834}
7835
7837 auto ToTypeOrErr = import(E->getType());
7838 if (!ToTypeOrErr)
7839 return ToTypeOrErr.takeError();
7840
7841 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7842 if (!ToLocationOrErr)
7843 return ToLocationOrErr.takeError();
7844
7845 return new (Importer.getToContext()) FixedPointLiteral(
7846 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7847 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7848}
7849
7851 ExpectedType ToTypeOrErr = import(E->getType());
7852 if (!ToTypeOrErr)
7853 return ToTypeOrErr.takeError();
7854
7855 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7856 if (!ToLocationOrErr)
7857 return ToLocationOrErr.takeError();
7858
7859 return new (Importer.getToContext()) CharacterLiteral(
7860 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7861}
7862
7864 ExpectedType ToTypeOrErr = import(E->getType());
7865 if (!ToTypeOrErr)
7866 return ToTypeOrErr.takeError();
7867
7869 if (Error Err = ImportArrayChecked(
7870 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7871 return std::move(Err);
7872
7873 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7874 E->getKind(), E->isPascal(), *ToTypeOrErr,
7875 ToLocations);
7876}
7877
7879
7880 Error Err = Error::success();
7881 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7882 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7883 auto ToType = importChecked(Err, E->getType());
7884 auto ToInitializer = importChecked(Err, E->getInitializer());
7885 if (Err)
7886 return std::move(Err);
7887
7888 return new (Importer.getToContext()) CompoundLiteralExpr(
7889 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7890 ToInitializer, E->isFileScope());
7891}
7892
7894
7895 Error Err = Error::success();
7896 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7897 auto ToType = importChecked(Err, E->getType());
7898 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7899 if (Err)
7900 return std::move(Err);
7901
7903 if (Error Err = ImportArrayChecked(
7904 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7905 ToExprs.begin()))
7906 return std::move(Err);
7907
7908 return new (Importer.getToContext()) AtomicExpr(
7909
7910 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7911}
7912
7914 Error Err = Error::success();
7915 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7916 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7917 auto ToLabel = importChecked(Err, E->getLabel());
7918 auto ToType = importChecked(Err, E->getType());
7919 if (Err)
7920 return std::move(Err);
7921
7922 return new (Importer.getToContext()) AddrLabelExpr(
7923 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7924}
7926 Error Err = Error::success();
7927 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7928 auto ToResult = importChecked(Err, E->getAPValueResult());
7929 if (Err)
7930 return std::move(Err);
7931
7932 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7933}
7935 Error Err = Error::success();
7936 auto ToLParen = importChecked(Err, E->getLParen());
7937 auto ToRParen = importChecked(Err, E->getRParen());
7938 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7939 if (Err)
7940 return std::move(Err);
7941
7942 return new (Importer.getToContext())
7943 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7944}
7945
7947 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7948 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7949 return std::move(Err);
7950
7951 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7952 if (!ToLParenLocOrErr)
7953 return ToLParenLocOrErr.takeError();
7954
7955 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7956 if (!ToRParenLocOrErr)
7957 return ToRParenLocOrErr.takeError();
7958
7959 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7960 ToExprs, *ToRParenLocOrErr);
7961}
7962
7964 Error Err = Error::success();
7965 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7966 auto ToType = importChecked(Err, E->getType());
7967 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7968 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7969 if (Err)
7970 return std::move(Err);
7971
7972 return new (Importer.getToContext())
7973 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7974 E->getTemplateDepth());
7975}
7976
7978 Error Err = Error::success();
7979 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7980 auto ToType = importChecked(Err, E->getType());
7981 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7982 if (Err)
7983 return std::move(Err);
7984
7985 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7986 E->hasStoredFPFeatures());
7987 UO->setType(ToType);
7988 UO->setSubExpr(ToSubExpr);
7989 UO->setOpcode(E->getOpcode());
7990 UO->setOperatorLoc(ToOperatorLoc);
7991 UO->setCanOverflow(E->canOverflow());
7992 if (E->hasStoredFPFeatures())
7993 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7994
7995 return UO;
7996}
7997
7999
8001 Error Err = Error::success();
8002 auto ToType = importChecked(Err, E->getType());
8003 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8004 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8005 if (Err)
8006 return std::move(Err);
8007
8008 if (E->isArgumentType()) {
8009 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8010 import(E->getArgumentTypeInfo());
8011 if (!ToArgumentTypeInfoOrErr)
8012 return ToArgumentTypeInfoOrErr.takeError();
8013
8014 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8015 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8016 ToRParenLoc);
8017 }
8018
8019 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8020 if (!ToArgumentExprOrErr)
8021 return ToArgumentExprOrErr.takeError();
8022
8023 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8024 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8025}
8026
8028 Error Err = Error::success();
8029 auto ToLHS = importChecked(Err, E->getLHS());
8030 auto ToRHS = importChecked(Err, E->getRHS());
8031 auto ToType = importChecked(Err, E->getType());
8032 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8033 if (Err)
8034 return std::move(Err);
8035
8037 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8038 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8039 E->getFPFeatures());
8040}
8041
8043 Error Err = Error::success();
8044 auto ToCond = importChecked(Err, E->getCond());
8045 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8046 auto ToLHS = importChecked(Err, E->getLHS());
8047 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8048 auto ToRHS = importChecked(Err, E->getRHS());
8049 auto ToType = importChecked(Err, E->getType());
8050 if (Err)
8051 return std::move(Err);
8052
8053 return new (Importer.getToContext()) ConditionalOperator(
8054 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8055 E->getValueKind(), E->getObjectKind());
8056}
8057
8060 Error Err = Error::success();
8061 auto ToCommon = importChecked(Err, E->getCommon());
8062 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8063 auto ToCond = importChecked(Err, E->getCond());
8064 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8065 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8066 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8067 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8068 auto ToType = importChecked(Err, E->getType());
8069 if (Err)
8070 return std::move(Err);
8071
8072 return new (Importer.getToContext()) BinaryConditionalOperator(
8073 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8074 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8075 E->getObjectKind());
8076}
8077
8080 Error Err = Error::success();
8081 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8082 if (Err)
8083 return std::move(Err);
8084
8085 return new (Importer.getToContext())
8086 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8087}
8088
8090 Error Err = Error::success();
8091 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8092 auto ToQueriedTypeSourceInfo =
8094 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8095 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8096 auto ToType = importChecked(Err, E->getType());
8097 if (Err)
8098 return std::move(Err);
8099
8100 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8101 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8102 ToDimensionExpression, ToEndLoc, ToType);
8103}
8104
8106 Error Err = Error::success();
8107 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8108 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8109 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8110 auto ToType = importChecked(Err, E->getType());
8111 if (Err)
8112 return std::move(Err);
8113
8114 return new (Importer.getToContext()) ExpressionTraitExpr(
8115 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8116 ToEndLoc, ToType);
8117}
8118
8120 Error Err = Error::success();
8121 auto ToLocation = importChecked(Err, E->getLocation());
8122 auto ToType = importChecked(Err, E->getType());
8123 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8124 if (Err)
8125 return std::move(Err);
8126
8127 return new (Importer.getToContext()) OpaqueValueExpr(
8128 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8129}
8130
8132 Error Err = Error::success();
8133 auto ToLHS = importChecked(Err, E->getLHS());
8134 auto ToRHS = importChecked(Err, E->getRHS());
8135 auto ToType = importChecked(Err, E->getType());
8136 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8137 if (Err)
8138 return std::move(Err);
8139
8140 return new (Importer.getToContext()) ArraySubscriptExpr(
8141 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8142 ToRBracketLoc);
8143}
8144
8147 Error Err = Error::success();
8148 auto ToLHS = importChecked(Err, E->getLHS());
8149 auto ToRHS = importChecked(Err, E->getRHS());
8150 auto ToType = importChecked(Err, E->getType());
8151 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8152 auto ToComputationResultType =
8154 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8155 if (Err)
8156 return std::move(Err);
8157
8159 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8160 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8161 E->getFPFeatures(),
8162 ToComputationLHSType, ToComputationResultType);
8163}
8164
8167 CXXCastPath Path;
8168 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8169 if (auto SpecOrErr = import(*I))
8170 Path.push_back(*SpecOrErr);
8171 else
8172 return SpecOrErr.takeError();
8173 }
8174 return Path;
8175}
8176
8178 ExpectedType ToTypeOrErr = import(E->getType());
8179 if (!ToTypeOrErr)
8180 return ToTypeOrErr.takeError();
8181
8182 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8183 if (!ToSubExprOrErr)
8184 return ToSubExprOrErr.takeError();
8185
8186 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8187 if (!ToBasePathOrErr)
8188 return ToBasePathOrErr.takeError();
8189
8191 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8192 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8193}
8194
8196 Error Err = Error::success();
8197 auto ToType = importChecked(Err, E->getType());
8198 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8199 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8200 if (Err)
8201 return std::move(Err);
8202
8203 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8204 if (!ToBasePathOrErr)
8205 return ToBasePathOrErr.takeError();
8206 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8207
8208 switch (E->getStmtClass()) {
8209 case Stmt::CStyleCastExprClass: {
8210 auto *CCE = cast<CStyleCastExpr>(E);
8211 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8212 if (!ToLParenLocOrErr)
8213 return ToLParenLocOrErr.takeError();
8214 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8215 if (!ToRParenLocOrErr)
8216 return ToRParenLocOrErr.takeError();
8218 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8219 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8220 *ToLParenLocOrErr, *ToRParenLocOrErr);
8221 }
8222
8223 case Stmt::CXXFunctionalCastExprClass: {
8224 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8225 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8226 if (!ToLParenLocOrErr)
8227 return ToLParenLocOrErr.takeError();
8228 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8229 if (!ToRParenLocOrErr)
8230 return ToRParenLocOrErr.takeError();
8232 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8233 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8234 *ToLParenLocOrErr, *ToRParenLocOrErr);
8235 }
8236
8237 case Stmt::ObjCBridgedCastExprClass: {
8238 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8239 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8240 if (!ToLParenLocOrErr)
8241 return ToLParenLocOrErr.takeError();
8242 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8243 if (!ToBridgeKeywordLocOrErr)
8244 return ToBridgeKeywordLocOrErr.takeError();
8245 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8246 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8247 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8248 }
8249 case Stmt::BuiltinBitCastExprClass: {
8250 auto *BBC = cast<BuiltinBitCastExpr>(E);
8251 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8252 if (!ToKWLocOrErr)
8253 return ToKWLocOrErr.takeError();
8254 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8255 if (!ToRParenLocOrErr)
8256 return ToRParenLocOrErr.takeError();
8257 return new (Importer.getToContext()) BuiltinBitCastExpr(
8258 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8259 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8260 }
8261 default:
8262 llvm_unreachable("Cast expression of unsupported type!");
8263 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8264 }
8265}
8266
8269 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8270 const OffsetOfNode &FromNode = E->getComponent(I);
8271
8272 SourceLocation ToBeginLoc, ToEndLoc;
8273
8274 if (FromNode.getKind() != OffsetOfNode::Base) {
8275 Error Err = Error::success();
8276 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8277 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8278 if (Err)
8279 return std::move(Err);
8280 }
8281
8282 switch (FromNode.getKind()) {
8284 ToNodes.push_back(
8285 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8286 break;
8287 case OffsetOfNode::Base: {
8288 auto ToBSOrErr = import(FromNode.getBase());
8289 if (!ToBSOrErr)
8290 return ToBSOrErr.takeError();
8291 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8292 break;
8293 }
8294 case OffsetOfNode::Field: {
8295 auto ToFieldOrErr = import(FromNode.getField());
8296 if (!ToFieldOrErr)
8297 return ToFieldOrErr.takeError();
8298 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8299 break;
8300 }
8302 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8303 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8304 break;
8305 }
8306 }
8307 }
8308
8310 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8311 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8312 if (!ToIndexExprOrErr)
8313 return ToIndexExprOrErr.takeError();
8314 ToExprs[I] = *ToIndexExprOrErr;
8315 }
8316
8317 Error Err = Error::success();
8318 auto ToType = importChecked(Err, E->getType());
8319 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8320 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8321 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8322 if (Err)
8323 return std::move(Err);
8324
8325 return OffsetOfExpr::Create(
8326 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8327 ToExprs, ToRParenLoc);
8328}
8329
8331 Error Err = Error::success();
8332 auto ToType = importChecked(Err, E->getType());
8333 auto ToOperand = importChecked(Err, E->getOperand());
8334 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8335 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8336 if (Err)
8337 return std::move(Err);
8338
8339 CanThrowResult ToCanThrow;
8340 if (E->isValueDependent())
8341 ToCanThrow = CT_Dependent;
8342 else
8343 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8344
8345 return new (Importer.getToContext()) CXXNoexceptExpr(
8346 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8347}
8348
8350 Error Err = Error::success();
8351 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8352 auto ToType = importChecked(Err, E->getType());
8353 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8354 if (Err)
8355 return std::move(Err);
8356
8357 return new (Importer.getToContext()) CXXThrowExpr(
8358 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8359}
8360
8362 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8363 if (!ToUsedLocOrErr)
8364 return ToUsedLocOrErr.takeError();
8365
8366 auto ToParamOrErr = import(E->getParam());
8367 if (!ToParamOrErr)
8368 return ToParamOrErr.takeError();
8369
8370 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8371 if (!UsedContextOrErr)
8372 return UsedContextOrErr.takeError();
8373
8374 // Import the default arg if it was not imported yet.
8375 // This is needed because it can happen that during the import of the
8376 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8377 // encountered here. The default argument for a ParmVarDecl is set in the
8378 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8379 // see VisitParmVarDecl).
8380 ParmVarDecl *ToParam = *ToParamOrErr;
8381 if (!ToParam->getDefaultArg()) {
8382 std::optional<ParmVarDecl *> FromParam =
8383 Importer.getImportedFromDecl(ToParam);
8384 assert(FromParam && "ParmVarDecl was not imported?");
8385
8386 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8387 return std::move(Err);
8388 }
8389 Expr *RewrittenInit = nullptr;
8390 if (E->hasRewrittenInit()) {
8391 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8392 if (!ExprOrErr)
8393 return ExprOrErr.takeError();
8394 RewrittenInit = ExprOrErr.get();
8395 }
8396 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8397 *ToParamOrErr, RewrittenInit,
8398 *UsedContextOrErr);
8399}
8400
8403 Error Err = Error::success();
8404 auto ToType = importChecked(Err, E->getType());
8405 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8406 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8407 if (Err)
8408 return std::move(Err);
8409
8410 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8411 ToType, ToTypeSourceInfo, ToRParenLoc);
8412}
8413
8416 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8417 if (!ToSubExprOrErr)
8418 return ToSubExprOrErr.takeError();
8419
8420 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8421 if (!ToDtorOrErr)
8422 return ToDtorOrErr.takeError();
8423
8424 ASTContext &ToCtx = Importer.getToContext();
8425 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8426 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8427}
8428
8430
8432 Error Err = Error::success();
8433 auto ToConstructor = importChecked(Err, E->getConstructor());
8434 auto ToType = importChecked(Err, E->getType());
8435 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8436 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8437 if (Err)
8438 return std::move(Err);
8439
8441 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8442 return std::move(Err);
8443
8445 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8446 ToParenOrBraceRange, E->hadMultipleCandidates(),
8449}
8450
8453 DeclContext *DC, *LexicalDC;
8454 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8455 return std::move(Err);
8456
8457 Error Err = Error::success();
8458 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8459 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8460 if (Err)
8461 return std::move(Err);
8462 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8463
8465 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8466 D->getManglingNumber()))
8467 return To;
8468
8469 To->setLexicalDeclContext(LexicalDC);
8470 LexicalDC->addDeclInternal(To);
8471 return To;
8472}
8473
8476 Error Err = Error::success();
8477 auto ToType = importChecked(Err, E->getType());
8478 Expr *ToTemporaryExpr = importChecked(
8479 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8480 auto ToMaterializedDecl =
8482 if (Err)
8483 return std::move(Err);
8484
8485 if (!ToTemporaryExpr)
8486 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8487
8488 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8489 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8490 ToMaterializedDecl);
8491
8492 return ToMTE;
8493}
8494
8496 Error Err = Error::success();
8497 auto *ToPattern = importChecked(Err, E->getPattern());
8498 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8499 if (Err)
8500 return std::move(Err);
8501
8502 return new (Importer.getToContext())
8503 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8504}
8505
8507 Error Err = Error::success();
8508 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8509 auto ToPack = importChecked(Err, E->getPack());
8510 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8511 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8512 if (Err)
8513 return std::move(Err);
8514
8515 UnsignedOrNone Length = std::nullopt;
8516 if (!E->isValueDependent())
8517 Length = E->getPackLength();
8518
8519 SmallVector<TemplateArgument, 8> ToPartialArguments;
8520 if (E->isPartiallySubstituted()) {
8522 ToPartialArguments))
8523 return std::move(Err);
8524 }
8525
8527 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8528 Length, ToPartialArguments);
8529}
8530
8531
8533 Error Err = Error::success();
8534 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8535 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8536 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8537 auto ToArraySize = importChecked(Err, E->getArraySize());
8538 auto ToInitializer = importChecked(Err, E->getInitializer());
8539 auto ToType = importChecked(Err, E->getType());
8540 auto ToAllocatedTypeSourceInfo =
8542 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8543 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8544 if (Err)
8545 return std::move(Err);
8546
8547 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8548 if (Error Err =
8549 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8550 return std::move(Err);
8551
8552 return CXXNewExpr::Create(
8553 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8554 ToOperatorDelete, E->implicitAllocationParameters(),
8555 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8556 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8557 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8558}
8559
8561 Error Err = Error::success();
8562 auto ToType = importChecked(Err, E->getType());
8563 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8564 auto ToArgument = importChecked(Err, E->getArgument());
8565 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8566 if (Err)
8567 return std::move(Err);
8568
8569 return new (Importer.getToContext()) CXXDeleteExpr(
8570 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8571 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8572 ToBeginLoc);
8573}
8574
8576 Error Err = Error::success();
8577 auto ToType = importChecked(Err, E->getType());
8578 auto ToLocation = importChecked(Err, E->getLocation());
8579 auto ToConstructor = importChecked(Err, E->getConstructor());
8580 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8581 if (Err)
8582 return std::move(Err);
8583
8585 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8586 return std::move(Err);
8587
8589 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8590 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8593 ToParenOrBraceRange);
8595 return ToE;
8596}
8597
8599 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8600 if (!ToSubExprOrErr)
8601 return ToSubExprOrErr.takeError();
8602
8604 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8605 return std::move(Err);
8606
8608 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8609 ToObjects);
8610}
8611
8613 Error Err = Error::success();
8614 auto ToCallee = importChecked(Err, E->getCallee());
8615 auto ToType = importChecked(Err, E->getType());
8616 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8617 if (Err)
8618 return std::move(Err);
8619
8621 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8622 return std::move(Err);
8623
8624 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8625 ToType, E->getValueKind(), ToRParenLoc,
8626 E->getFPFeatures());
8627}
8628
8630 ExpectedType ToTypeOrErr = import(E->getType());
8631 if (!ToTypeOrErr)
8632 return ToTypeOrErr.takeError();
8633
8634 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8635 if (!ToLocationOrErr)
8636 return ToLocationOrErr.takeError();
8637
8638 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8639 *ToTypeOrErr, E->isImplicit());
8640}
8641
8643 ExpectedType ToTypeOrErr = import(E->getType());
8644 if (!ToTypeOrErr)
8645 return ToTypeOrErr.takeError();
8646
8647 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8648 if (!ToLocationOrErr)
8649 return ToLocationOrErr.takeError();
8650
8651 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8652 *ToTypeOrErr, *ToLocationOrErr);
8653}
8654
8656 Error Err = Error::success();
8657 auto ToBase = importChecked(Err, E->getBase());
8658 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8659 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8660 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8661 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8662 auto ToType = importChecked(Err, E->getType());
8663 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8664 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8665 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8666 if (Err)
8667 return std::move(Err);
8668
8669 DeclAccessPair ToFoundDecl =
8671
8672 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8673
8674 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8675 if (E->hasExplicitTemplateArgs()) {
8676 if (Error Err =
8678 E->template_arguments(), ToTAInfo))
8679 return std::move(Err);
8680 ResInfo = &ToTAInfo;
8681 }
8682
8683 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8684 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8685 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8686 ResInfo, ToType, E->getValueKind(),
8687 E->getObjectKind(), E->isNonOdrUse());
8688}
8689
8692 Error Err = Error::success();
8693 auto ToBase = importChecked(Err, E->getBase());
8694 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8695 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8696 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8697 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8698 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8699 if (Err)
8700 return std::move(Err);
8701
8703 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8704 const IdentifierInfo *ToII = Importer.Import(FromII);
8705 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8706 if (!ToDestroyedTypeLocOrErr)
8707 return ToDestroyedTypeLocOrErr.takeError();
8708 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8709 } else {
8710 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8711 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8712 else
8713 return ToTIOrErr.takeError();
8714 }
8715
8716 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8717 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8718 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8719}
8720
8723 Error Err = Error::success();
8724 auto ToType = importChecked(Err, E->getType());
8725 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8726 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8727 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8728 auto ToFirstQualifierFoundInScope =
8730 if (Err)
8731 return std::move(Err);
8732
8733 Expr *ToBase = nullptr;
8734 if (!E->isImplicitAccess()) {
8735 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8736 ToBase = *ToBaseOrErr;
8737 else
8738 return ToBaseOrErr.takeError();
8739 }
8740
8741 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8742
8743 if (E->hasExplicitTemplateArgs()) {
8744 if (Error Err =
8746 E->template_arguments(), ToTAInfo))
8747 return std::move(Err);
8748 ResInfo = &ToTAInfo;
8749 }
8750 auto ToMember = importChecked(Err, E->getMember());
8751 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8752 if (Err)
8753 return std::move(Err);
8754 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8755
8756 // Import additional name location/type info.
8757 if (Error Err =
8758 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8759 return std::move(Err);
8760
8762 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8763 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8764 ToMemberNameInfo, ResInfo);
8765}
8766
8769 Error Err = Error::success();
8770 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8771 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8772 auto ToDeclName = importChecked(Err, E->getDeclName());
8773 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8774 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8775 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8776 if (Err)
8777 return std::move(Err);
8778
8779 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8780 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8781 return std::move(Err);
8782
8783 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8784 TemplateArgumentListInfo *ResInfo = nullptr;
8785 if (E->hasExplicitTemplateArgs()) {
8786 if (Error Err =
8788 return std::move(Err);
8789 ResInfo = &ToTAInfo;
8790 }
8791
8793 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8794 ToNameInfo, ResInfo);
8795}
8796
8799 Error Err = Error::success();
8800 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8801 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8802 auto ToType = importChecked(Err, E->getType());
8803 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8804 if (Err)
8805 return std::move(Err);
8806
8808 if (Error Err =
8809 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8810 return std::move(Err);
8811
8813 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8814 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8815}
8816
8819 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8820 if (!ToNamingClassOrErr)
8821 return ToNamingClassOrErr.takeError();
8822
8823 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8824 if (!ToQualifierLocOrErr)
8825 return ToQualifierLocOrErr.takeError();
8826
8827 Error Err = Error::success();
8828 auto ToName = importChecked(Err, E->getName());
8829 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8830 if (Err)
8831 return std::move(Err);
8832 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8833
8834 // Import additional name location/type info.
8835 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8836 return std::move(Err);
8837
8838 UnresolvedSet<8> ToDecls;
8839 for (auto *D : E->decls())
8840 if (auto ToDOrErr = import(D))
8841 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8842 else
8843 return ToDOrErr.takeError();
8844
8845 if (E->hasExplicitTemplateArgs()) {
8846 TemplateArgumentListInfo ToTAInfo;
8849 ToTAInfo))
8850 return std::move(Err);
8851
8852 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8853 if (!ToTemplateKeywordLocOrErr)
8854 return ToTemplateKeywordLocOrErr.takeError();
8855
8856 const bool KnownDependent =
8857 (E->getDependence() & ExprDependence::TypeValue) ==
8858 ExprDependence::TypeValue;
8860 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8861 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8862 ToDecls.begin(), ToDecls.end(), KnownDependent,
8863 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8864 }
8865
8867 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8868 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8869 /*KnownDependent=*/E->isTypeDependent(),
8870 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8871}
8872
8875 Error Err = Error::success();
8876 auto ToType = importChecked(Err, E->getType());
8877 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8878 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8879 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8880 auto ToName = importChecked(Err, E->getName());
8881 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8882 if (Err)
8883 return std::move(Err);
8884
8885 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8886 // Import additional name location/type info.
8887 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8888 return std::move(Err);
8889
8890 UnresolvedSet<8> ToDecls;
8891 for (Decl *D : E->decls())
8892 if (auto ToDOrErr = import(D))
8893 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8894 else
8895 return ToDOrErr.takeError();
8896
8897 TemplateArgumentListInfo ToTAInfo;
8898 TemplateArgumentListInfo *ResInfo = nullptr;
8899 if (E->hasExplicitTemplateArgs()) {
8900 TemplateArgumentListInfo FromTAInfo;
8901 E->copyTemplateArgumentsInto(FromTAInfo);
8902 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8903 return std::move(Err);
8904 ResInfo = &ToTAInfo;
8905 }
8906
8907 Expr *ToBase = nullptr;
8908 if (!E->isImplicitAccess()) {
8909 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8910 ToBase = *ToBaseOrErr;
8911 else
8912 return ToBaseOrErr.takeError();
8913 }
8914
8916 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8917 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8918 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8919}
8920
8922 Error Err = Error::success();
8923 auto ToCallee = importChecked(Err, E->getCallee());
8924 auto ToType = importChecked(Err, E->getType());
8925 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8926 if (Err)
8927 return std::move(Err);
8928
8929 unsigned NumArgs = E->getNumArgs();
8930 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8931 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8932 return std::move(Err);
8933
8934 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8936 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8937 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8938 OCE->getADLCallKind());
8939 }
8940
8941 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8942 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8943 /*MinNumArgs=*/0, E->getADLCallKind());
8944}
8945
8947 CXXRecordDecl *FromClass = E->getLambdaClass();
8948 auto ToClassOrErr = import(FromClass);
8949 if (!ToClassOrErr)
8950 return ToClassOrErr.takeError();
8951 CXXRecordDecl *ToClass = *ToClassOrErr;
8952
8953 auto ToCallOpOrErr = import(E->getCallOperator());
8954 if (!ToCallOpOrErr)
8955 return ToCallOpOrErr.takeError();
8956
8957 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8958 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8959 return std::move(Err);
8960
8961 Error Err = Error::success();
8962 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8963 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8964 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8965 if (Err)
8966 return std::move(Err);
8967
8968 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8969 E->getCaptureDefault(), ToCaptureDefaultLoc,
8971 E->hasExplicitResultType(), ToCaptureInits,
8972 ToEndLoc, E->containsUnexpandedParameterPack());
8973}
8974
8975
8977 Error Err = Error::success();
8978 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8979 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8980 auto ToType = importChecked(Err, E->getType());
8981 if (Err)
8982 return std::move(Err);
8983
8984 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8985 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8986 return std::move(Err);
8987
8988 ASTContext &ToCtx = Importer.getToContext();
8989 InitListExpr *To = new (ToCtx) InitListExpr(
8990 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8991 To->setType(ToType);
8992
8993 if (E->hasArrayFiller()) {
8994 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8995 To->setArrayFiller(*ToFillerOrErr);
8996 else
8997 return ToFillerOrErr.takeError();
8998 }
8999
9000 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9001 if (auto ToFDOrErr = import(FromFD))
9002 To->setInitializedFieldInUnion(*ToFDOrErr);
9003 else
9004 return ToFDOrErr.takeError();
9005 }
9006
9007 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9008 if (auto ToSyntFormOrErr = import(SyntForm))
9009 To->setSyntacticForm(*ToSyntFormOrErr);
9010 else
9011 return ToSyntFormOrErr.takeError();
9012 }
9013
9014 // Copy InitListExprBitfields, which are not handled in the ctor of
9015 // InitListExpr.
9017
9018 return To;
9019}
9020
9023 ExpectedType ToTypeOrErr = import(E->getType());
9024 if (!ToTypeOrErr)
9025 return ToTypeOrErr.takeError();
9026
9027 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9028 if (!ToSubExprOrErr)
9029 return ToSubExprOrErr.takeError();
9030
9031 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9032 *ToTypeOrErr, *ToSubExprOrErr);
9033}
9034
9037 Error Err = Error::success();
9038 auto ToLocation = importChecked(Err, E->getLocation());
9039 auto ToType = importChecked(Err, E->getType());
9040 auto ToConstructor = importChecked(Err, E->getConstructor());
9041 if (Err)
9042 return std::move(Err);
9043
9044 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9045 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9046 E->inheritedFromVBase());
9047}
9048
9050 Error Err = Error::success();
9051 auto ToType = importChecked(Err, E->getType());
9052 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9053 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9054 if (Err)
9055 return std::move(Err);
9056
9057 return new (Importer.getToContext()) ArrayInitLoopExpr(
9058 ToType, ToCommonExpr, ToSubExpr);
9059}
9060
9062 ExpectedType ToTypeOrErr = import(E->getType());
9063 if (!ToTypeOrErr)
9064 return ToTypeOrErr.takeError();
9065 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9066}
9067
9069 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9070 if (!ToBeginLocOrErr)
9071 return ToBeginLocOrErr.takeError();
9072
9073 auto ToFieldOrErr = import(E->getField());
9074 if (!ToFieldOrErr)
9075 return ToFieldOrErr.takeError();
9076
9077 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9078 if (!UsedContextOrErr)
9079 return UsedContextOrErr.takeError();
9080
9081 FieldDecl *ToField = *ToFieldOrErr;
9082 assert(ToField->hasInClassInitializer() &&
9083 "Field should have in-class initializer if there is a default init "
9084 "expression that uses it.");
9085 if (!ToField->getInClassInitializer()) {
9086 // The in-class initializer may be not yet set in "To" AST even if the
9087 // field is already there. This must be set here to make construction of
9088 // CXXDefaultInitExpr work.
9089 auto ToInClassInitializerOrErr =
9090 import(E->getField()->getInClassInitializer());
9091 if (!ToInClassInitializerOrErr)
9092 return ToInClassInitializerOrErr.takeError();
9093 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9094 }
9095
9096 Expr *RewrittenInit = nullptr;
9097 if (E->hasRewrittenInit()) {
9098 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9099 if (!ExprOrErr)
9100 return ExprOrErr.takeError();
9101 RewrittenInit = ExprOrErr.get();
9102 }
9103
9104 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9105 ToField, *UsedContextOrErr, RewrittenInit);
9106}
9107
9109 Error Err = Error::success();
9110 auto ToType = importChecked(Err, E->getType());
9111 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9112 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9113 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9114 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9115 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9116 if (Err)
9117 return std::move(Err);
9118
9120 CastKind CK = E->getCastKind();
9121 auto ToBasePathOrErr = ImportCastPath(E);
9122 if (!ToBasePathOrErr)
9123 return ToBasePathOrErr.takeError();
9124
9125 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9127 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9128 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9129 ToAngleBrackets);
9130 } else if (isa<CXXDynamicCastExpr>(E)) {
9132 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9133 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9134 } else if (isa<CXXReinterpretCastExpr>(E)) {
9136 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9137 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9138 } else if (isa<CXXConstCastExpr>(E)) {
9140 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9141 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9142 } else {
9143 llvm_unreachable("Unknown cast type");
9144 return make_error<ASTImportError>();
9145 }
9146}
9147
9150 Error Err = Error::success();
9151 auto ToType = importChecked(Err, E->getType());
9152 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9153 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9154 auto ToReplacement = importChecked(Err, E->getReplacement());
9155 if (Err)
9156 return std::move(Err);
9157
9158 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9159 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9161 E->getFinal());
9162}
9163
9165 Error Err = Error::success();
9166 auto ToType = importChecked(Err, E->getType());
9167 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9168 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9169 if (Err)
9170 return std::move(Err);
9171
9173 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9174 return std::move(Err);
9175
9176 if (E->isStoredAsBoolean()) {
9177 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9178 // Value is always false.
9179 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9180 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9181 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9182 }
9183 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9184 E->getTrait(), ToArgs, ToEndLoc,
9185 E->getAPValue());
9186}
9187
9189 ExpectedType ToTypeOrErr = import(E->getType());
9190 if (!ToTypeOrErr)
9191 return ToTypeOrErr.takeError();
9192
9193 auto ToSourceRangeOrErr = import(E->getSourceRange());
9194 if (!ToSourceRangeOrErr)
9195 return ToSourceRangeOrErr.takeError();
9196
9197 if (E->isTypeOperand()) {
9198 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9199 return new (Importer.getToContext()) CXXTypeidExpr(
9200 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9201 else
9202 return ToTSIOrErr.takeError();
9203 }
9204
9205 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9206 if (!ToExprOperandOrErr)
9207 return ToExprOperandOrErr.takeError();
9208
9209 return new (Importer.getToContext()) CXXTypeidExpr(
9210 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9211}
9212
9214 Error Err = Error::success();
9215
9216 QualType ToType = importChecked(Err, E->getType());
9217 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9218 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9219 Expr *ToLHS = importChecked(Err, E->getLHS());
9220 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9221 Expr *ToRHS = importChecked(Err, E->getRHS());
9222 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9223
9224 if (Err)
9225 return std::move(Err);
9226
9227 return new (Importer.getToContext())
9228 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9229 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9230}
9231
9233 Error Err = Error::success();
9234 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9235 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9236 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9237
9238 auto Body = importChecked(Err, E->getBody());
9239 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9240 if (Err)
9241 return std::move(Err);
9242 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9243 if (Error Err =
9244 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9245 return std::move(Err);
9247 E->getRequirements().size());
9248 if (Error Err =
9249 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9250 return std::move(Err);
9251 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9252 LParenLoc, LocalParameters, RParenLoc,
9253 Requirements, RBraceLoc);
9254}
9255
9258 Error Err = Error::success();
9259 auto CL = importChecked(Err, E->getConceptReference());
9260 auto CSD = importChecked(Err, E->getSpecializationDecl());
9261 if (Err)
9262 return std::move(Err);
9263 if (E->isValueDependent())
9265 Importer.getToContext(), CL,
9266 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9267 ConstraintSatisfaction Satisfaction;
9268 if (Error Err =
9270 return std::move(Err);
9272 Importer.getToContext(), CL,
9273 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9274}
9275
9277 CXXMethodDecl *FromMethod) {
9278 Error ImportErrors = Error::success();
9279 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9280 if (auto ImportedOrErr = import(FromOverriddenMethod))
9282 (*ImportedOrErr)->getCanonicalDecl()));
9283 else
9284 ImportErrors =
9285 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9286 }
9287 return ImportErrors;
9288}
9289
9291 ASTContext &FromContext, FileManager &FromFileManager,
9292 bool MinimalImport,
9293 std::shared_ptr<ASTImporterSharedState> SharedState)
9294 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9295 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9296 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9297
9298 // Create a default state without the lookup table: LLDB case.
9299 if (!SharedState) {
9300 this->SharedState = std::make_shared<ASTImporterSharedState>();
9301 }
9302
9303 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9304 ToContext.getTranslationUnitDecl();
9305}
9306
9307ASTImporter::~ASTImporter() = default;
9308
9310 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9311 "Try to get field index for non-field.");
9312
9313 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9314 if (!Owner)
9315 return std::nullopt;
9316
9317 unsigned Index = 0;
9318 for (const auto *D : Owner->decls()) {
9319 if (D == F)
9320 return Index;
9321
9323 ++Index;
9324 }
9325
9326 llvm_unreachable("Field was not found in its parent context.");
9327
9328 return std::nullopt;
9329}
9330
9331ASTImporter::FoundDeclsTy
9332ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9333 // We search in the redecl context because of transparent contexts.
9334 // E.g. a simple C language enum is a transparent context:
9335 // enum E { A, B };
9336 // Now if we had a global variable in the TU
9337 // int A;
9338 // then the enum constant 'A' and the variable 'A' violates ODR.
9339 // We can diagnose this only if we search in the redecl context.
9340 DeclContext *ReDC = DC->getRedeclContext();
9341 if (SharedState->getLookupTable()) {
9342 if (ReDC->isNamespace()) {
9343 // Namespaces can be reopened.
9344 // Lookup table does not handle this, we must search here in all linked
9345 // namespaces.
9346 FoundDeclsTy Result;
9347 SmallVector<Decl *, 2> NSChain =
9349 dyn_cast<NamespaceDecl>(ReDC));
9350 for (auto *D : NSChain) {
9352 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9353 Name);
9355 }
9356 return Result;
9357 } else {
9359 SharedState->getLookupTable()->lookup(ReDC, Name);
9360 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9361 }
9362 } else {
9363 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9364 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9365 // We must search by the slow case of localUncachedLookup because that is
9366 // working even if there is no LookupPtr for the DC. We could use
9367 // DC::buildLookup() to create the LookupPtr, but that would load external
9368 // decls again, we must avoid that case.
9369 // Also, even if we had the LookupPtr, we must find Decls which are not
9370 // in the LookupPtr, so we need the slow case.
9371 // These cases are handled in ASTImporterLookupTable, but we cannot use
9372 // that with LLDB since that traverses through the AST which initiates the
9373 // load of external decls again via DC::decls(). And again, we must avoid
9374 // loading external decls during the import.
9375 if (Result.empty())
9376 ReDC->localUncachedLookup(Name, Result);
9377 return Result;
9378 }
9379}
9380
9381void ASTImporter::AddToLookupTable(Decl *ToD) {
9382 SharedState->addDeclToLookup(ToD);
9383}
9384
9386 // Import the decl using ASTNodeImporter.
9387 ASTNodeImporter Importer(*this);
9388 return Importer.Visit(FromD);
9389}
9390
9392 MapImported(FromD, ToD);
9393}
9394
9397 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9398 if (Expected<Expr *> R = Import(CLE))
9400 }
9401
9402 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9403 // ASTNodeImporter.
9404 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9405}
9406
9408 if (!FromT)
9409 return FromT;
9410
9411 // Check whether we've already imported this type.
9412 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9413 ImportedTypes.find(FromT);
9414 if (Pos != ImportedTypes.end())
9415 return Pos->second;
9416
9417 // Import the type.
9418 ASTNodeImporter Importer(*this);
9419 ExpectedType ToTOrErr = Importer.Visit(FromT);
9420 if (!ToTOrErr)
9421 return ToTOrErr.takeError();
9422
9423 // Record the imported type.
9424 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9425
9426 return ToTOrErr->getTypePtr();
9427}
9428
9430 if (FromT.isNull())
9431 return QualType{};
9432
9433 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9434 if (!ToTyOrErr)
9435 return ToTyOrErr.takeError();
9436
9437 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9438}
9439
9441 if (!FromTSI)
9442 return FromTSI;
9443
9444 // FIXME: For now we just create a "trivial" type source info based
9445 // on the type and a single location. Implement a real version of this.
9446 ExpectedType TOrErr = Import(FromTSI->getType());
9447 if (!TOrErr)
9448 return TOrErr.takeError();
9449 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9450 if (!BeginLocOrErr)
9451 return BeginLocOrErr.takeError();
9452
9453 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9454}
9455
9456namespace {
9457// To use this object, it should be created before the new attribute is created,
9458// and destructed after it is created. The construction already performs the
9459// import of the data.
9460template <typename T> struct AttrArgImporter {
9461 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9462 AttrArgImporter(AttrArgImporter<T> &&) = default;
9463 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9464 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9465
9466 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9467 : To(I.importChecked(Err, From)) {}
9468
9469 const T &value() { return To; }
9470
9471private:
9472 T To;
9473};
9474
9475// To use this object, it should be created before the new attribute is created,
9476// and destructed after it is created. The construction already performs the
9477// import of the data. The array data is accessible in a pointer form, this form
9478// is used by the attribute classes. This object should be created once for the
9479// array data to be imported (the array size is not imported, just copied).
9480template <typename T> struct AttrArgArrayImporter {
9481 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9482 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9483 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9484 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9485
9486 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9487 const llvm::iterator_range<T *> &From,
9488 unsigned ArraySize) {
9489 if (Err)
9490 return;
9491 To.reserve(ArraySize);
9492 Err = I.ImportContainerChecked(From, To);
9493 }
9494
9495 T *value() { return To.data(); }
9496
9497private:
9498 llvm::SmallVector<T, 2> To;
9499};
9500
9501class AttrImporter {
9502 Error Err{Error::success()};
9503 Attr *ToAttr = nullptr;
9504 ASTImporter &Importer;
9505 ASTNodeImporter NImporter;
9506
9507public:
9508 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9509
9510 // Useful for accessing the imported attribute.
9511 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9512 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9513
9514 // Create an "importer" for an attribute parameter.
9515 // Result of the 'value()' of that object is to be passed to the function
9516 // 'importAttr', in the order that is expected by the attribute class.
9517 template <class T> AttrArgImporter<T> importArg(const T &From) {
9518 return AttrArgImporter<T>(NImporter, Err, From);
9519 }
9520
9521 // Create an "importer" for an attribute parameter that has array type.
9522 // Result of the 'value()' of that object is to be passed to the function
9523 // 'importAttr', then the size of the array as next argument.
9524 template <typename T>
9525 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9526 unsigned ArraySize) {
9527 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9528 }
9529
9530 // Create an attribute object with the specified arguments.
9531 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9532 // should be values that are passed to the 'Create' function of the attribute.
9533 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9534 // used here.) As much data is copied or imported from the old attribute
9535 // as possible. The passed arguments should be already imported.
9536 // If an import error happens, the internal error is set to it, and any
9537 // further import attempt is ignored.
9538 template <typename T, typename... Arg>
9539 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9540 static_assert(std::is_base_of<Attr, T>::value,
9541 "T should be subclass of Attr.");
9542 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9543
9544 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9545 const IdentifierInfo *ToScopeName =
9546 Importer.Import(FromAttr->getScopeName());
9547 SourceRange ToAttrRange =
9548 NImporter.importChecked(Err, FromAttr->getRange());
9549 SourceLocation ToScopeLoc =
9550 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9551
9552 if (Err)
9553 return;
9554
9555 AttributeCommonInfo ToI(
9556 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9557 FromAttr->getParsedKind(), FromAttr->getForm());
9558 // The "SemanticSpelling" is not needed to be passed to the constructor.
9559 // That value is recalculated from the SpellingListIndex if needed.
9560 ToAttr = T::Create(Importer.getToContext(),
9561 std::forward<Arg>(ImportedArg)..., ToI);
9562
9563 ToAttr->setImplicit(FromAttr->isImplicit());
9564 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9565 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9566 ToInheritableAttr->setInherited(FromAttr->isInherited());
9567 }
9568
9569 // Create a clone of the 'FromAttr' and import its source range only.
9570 // This causes objects with invalid references to be created if the 'FromAttr'
9571 // contains other data that should be imported.
9572 void cloneAttr(const Attr *FromAttr) {
9573 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9574
9575 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9576 if (Err)
9577 return;
9578
9579 ToAttr = FromAttr->clone(Importer.getToContext());
9580 ToAttr->setRange(ToRange);
9581 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9582 }
9583
9584 // Get the result of the previous import attempt (can be used only once).
9585 llvm::Expected<Attr *> getResult() && {
9586 if (Err)
9587 return std::move(Err);
9588 assert(ToAttr && "Attribute should be created.");
9589 return ToAttr;
9590 }
9591};
9592} // namespace
9593
9595 AttrImporter AI(*this);
9596
9597 // FIXME: Is there some kind of AttrVisitor to use here?
9598 switch (FromAttr->getKind()) {
9599 case attr::Aligned: {
9600 auto *From = cast<AlignedAttr>(FromAttr);
9601 if (From->isAlignmentExpr())
9602 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9603 else
9604 AI.importAttr(From, false,
9605 AI.importArg(From->getAlignmentType()).value());
9606 break;
9607 }
9608
9609 case attr::AlignValue: {
9610 auto *From = cast<AlignValueAttr>(FromAttr);
9611 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9612 break;
9613 }
9614
9615 case attr::Format: {
9616 const auto *From = cast<FormatAttr>(FromAttr);
9617 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9618 From->getFirstArg());
9619 break;
9620 }
9621
9622 case attr::EnableIf: {
9623 const auto *From = cast<EnableIfAttr>(FromAttr);
9624 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9625 From->getMessage());
9626 break;
9627 }
9628
9629 case attr::AssertCapability: {
9630 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9631 AI.importAttr(From,
9632 AI.importArrayArg(From->args(), From->args_size()).value(),
9633 From->args_size());
9634 break;
9635 }
9636 case attr::AcquireCapability: {
9637 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9638 AI.importAttr(From,
9639 AI.importArrayArg(From->args(), From->args_size()).value(),
9640 From->args_size());
9641 break;
9642 }
9643 case attr::TryAcquireCapability: {
9644 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9645 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9646 AI.importArrayArg(From->args(), From->args_size()).value(),
9647 From->args_size());
9648 break;
9649 }
9650 case attr::ReleaseCapability: {
9651 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9652 AI.importAttr(From,
9653 AI.importArrayArg(From->args(), From->args_size()).value(),
9654 From->args_size());
9655 break;
9656 }
9657 case attr::RequiresCapability: {
9658 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9659 AI.importAttr(From,
9660 AI.importArrayArg(From->args(), From->args_size()).value(),
9661 From->args_size());
9662 break;
9663 }
9664 case attr::GuardedBy: {
9665 const auto *From = cast<GuardedByAttr>(FromAttr);
9666 AI.importAttr(From, AI.importArg(From->getArg()).value());
9667 break;
9668 }
9669 case attr::PtGuardedBy: {
9670 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9671 AI.importAttr(From, AI.importArg(From->getArg()).value());
9672 break;
9673 }
9674 case attr::AcquiredAfter: {
9675 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9676 AI.importAttr(From,
9677 AI.importArrayArg(From->args(), From->args_size()).value(),
9678 From->args_size());
9679 break;
9680 }
9681 case attr::AcquiredBefore: {
9682 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9683 AI.importAttr(From,
9684 AI.importArrayArg(From->args(), From->args_size()).value(),
9685 From->args_size());
9686 break;
9687 }
9688 case attr::LockReturned: {
9689 const auto *From = cast<LockReturnedAttr>(FromAttr);
9690 AI.importAttr(From, AI.importArg(From->getArg()).value());
9691 break;
9692 }
9693 case attr::LocksExcluded: {
9694 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9695 AI.importAttr(From,
9696 AI.importArrayArg(From->args(), From->args_size()).value(),
9697 From->args_size());
9698 break;
9699 }
9700 default: {
9701 // The default branch works for attributes that have no arguments to import.
9702 // FIXME: Handle every attribute type that has arguments of type to import
9703 // (most often Expr* or Decl* or type) in the switch above.
9704 AI.cloneAttr(FromAttr);
9705 break;
9706 }
9707 }
9708
9709 return std::move(AI).getResult();
9710}
9711
9713 return ImportedDecls.lookup(FromD);
9714}
9715
9717 auto FromDPos = ImportedFromDecls.find(ToD);
9718 if (FromDPos == ImportedFromDecls.end())
9719 return nullptr;
9720 return FromDPos->second->getTranslationUnitDecl();
9721}
9722
9724 if (!FromD)
9725 return nullptr;
9726
9727 // Push FromD to the stack, and remove that when we return.
9728 ImportPath.push(FromD);
9729 auto ImportPathBuilder =
9730 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9731
9732 // Check whether there was a previous failed import.
9733 // If yes return the existing error.
9734 if (auto Error = getImportDeclErrorIfAny(FromD))
9735 return make_error<ASTImportError>(*Error);
9736
9737 // Check whether we've already imported this declaration.
9738 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9739 if (ToD) {
9740 // Already imported (possibly from another TU) and with an error.
9741 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9742 setImportDeclError(FromD, *Error);
9743 return make_error<ASTImportError>(*Error);
9744 }
9745
9746 // If FromD has some updated flags after last import, apply it.
9747 updateFlags(FromD, ToD);
9748 // If we encounter a cycle during an import then we save the relevant part
9749 // of the import path associated to the Decl.
9750 if (ImportPath.hasCycleAtBack())
9751 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9752 return ToD;
9753 }
9754
9755 // Import the declaration.
9756 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9757 if (!ToDOrErr) {
9758 // Failed to import.
9759
9760 auto Pos = ImportedDecls.find(FromD);
9761 if (Pos != ImportedDecls.end()) {
9762 // Import failed after the object was created.
9763 // Remove all references to it.
9764 auto *ToD = Pos->second;
9765 ImportedDecls.erase(Pos);
9766
9767 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9768 // (e.g. with namespaces) that several decls from the 'from' context are
9769 // mapped to the same decl in the 'to' context. If we removed entries
9770 // from the LookupTable here then we may end up removing them multiple
9771 // times.
9772
9773 // The Lookuptable contains decls only which are in the 'to' context.
9774 // Remove from the Lookuptable only if it is *imported* into the 'to'
9775 // context (and do not remove it if it was added during the initial
9776 // traverse of the 'to' context).
9777 auto PosF = ImportedFromDecls.find(ToD);
9778 if (PosF != ImportedFromDecls.end()) {
9779 // In the case of TypedefNameDecl we create the Decl first and only
9780 // then we import and set its DeclContext. So, the DC might not be set
9781 // when we reach here.
9782 if (ToD->getDeclContext())
9783 SharedState->removeDeclFromLookup(ToD);
9784 ImportedFromDecls.erase(PosF);
9785 }
9786
9787 // FIXME: AST may contain remaining references to the failed object.
9788 // However, the ImportDeclErrors in the shared state contains all the
9789 // failed objects together with their error.
9790 }
9791
9792 // Error encountered for the first time.
9793 // After takeError the error is not usable any more in ToDOrErr.
9794 // Get a copy of the error object (any more simple solution for this?).
9795 ASTImportError ErrOut;
9796 handleAllErrors(ToDOrErr.takeError(),
9797 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9798 setImportDeclError(FromD, ErrOut);
9799 // Set the error for the mapped to Decl, which is in the "to" context.
9800 if (Pos != ImportedDecls.end())
9801 SharedState->setImportDeclError(Pos->second, ErrOut);
9802
9803 // Set the error for all nodes which have been created before we
9804 // recognized the error.
9805 for (const auto &Path : SavedImportPaths[FromD]) {
9806 // The import path contains import-dependency nodes first.
9807 // Save the node that was imported as dependency of the current node.
9808 Decl *PrevFromDi = FromD;
9809 for (Decl *FromDi : Path) {
9810 // Begin and end of the path equals 'FromD', skip it.
9811 if (FromDi == FromD)
9812 continue;
9813 // We should not set import error on a node and all following nodes in
9814 // the path if child import errors are ignored.
9815 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9816 PrevFromDi))
9817 break;
9818 PrevFromDi = FromDi;
9819 setImportDeclError(FromDi, ErrOut);
9820 //FIXME Should we remove these Decls from ImportedDecls?
9821 // Set the error for the mapped to Decl, which is in the "to" context.
9822 auto Ii = ImportedDecls.find(FromDi);
9823 if (Ii != ImportedDecls.end())
9824 SharedState->setImportDeclError(Ii->second, ErrOut);
9825 // FIXME Should we remove these Decls from the LookupTable,
9826 // and from ImportedFromDecls?
9827 }
9828 }
9829 SavedImportPaths.erase(FromD);
9830
9831 // Do not return ToDOrErr, error was taken out of it.
9832 return make_error<ASTImportError>(ErrOut);
9833 }
9834
9835 ToD = *ToDOrErr;
9836
9837 // FIXME: Handle the "already imported with error" case. We can get here
9838 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9839 // previously failed create was requested).
9840 // Later GetImportedOrCreateDecl can be updated to return the error.
9841 if (!ToD) {
9842 auto Err = getImportDeclErrorIfAny(FromD);
9843 assert(Err);
9844 return make_error<ASTImportError>(*Err);
9845 }
9846
9847 // We could import from the current TU without error. But previously we
9848 // already had imported a Decl as `ToD` from another TU (with another
9849 // ASTImporter object) and with an error.
9850 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9851 setImportDeclError(FromD, *Error);
9852 return make_error<ASTImportError>(*Error);
9853 }
9854 // Make sure that ImportImpl registered the imported decl.
9855 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9856
9857 if (FromD->hasAttrs())
9858 for (const Attr *FromAttr : FromD->getAttrs()) {
9859 auto ToAttrOrErr = Import(FromAttr);
9860 if (ToAttrOrErr)
9861 ToD->addAttr(*ToAttrOrErr);
9862 else
9863 return ToAttrOrErr.takeError();
9864 }
9865
9866 // Notify subclasses.
9867 Imported(FromD, ToD);
9868
9869 updateFlags(FromD, ToD);
9870 SavedImportPaths.erase(FromD);
9871 return ToDOrErr;
9872}
9873
9876 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9877}
9878
9880 if (!FromDC)
9881 return FromDC;
9882
9883 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9884 if (!ToDCOrErr)
9885 return ToDCOrErr.takeError();
9886 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9887
9888 // When we're using a record/enum/Objective-C class/protocol as a context, we
9889 // need it to have a definition.
9890 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9891 auto *FromRecord = cast<RecordDecl>(FromDC);
9892 if (ToRecord->isCompleteDefinition())
9893 return ToDC;
9894
9895 // If FromRecord is not defined we need to force it to be.
9896 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9897 // it will start the definition but we never finish it.
9898 // If there are base classes they won't be imported and we will
9899 // be missing anything that we inherit from those bases.
9900 if (FromRecord->getASTContext().getExternalSource() &&
9901 !FromRecord->isCompleteDefinition())
9902 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9903
9904 if (FromRecord->isCompleteDefinition())
9905 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9906 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9907 return std::move(Err);
9908 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9909 auto *FromEnum = cast<EnumDecl>(FromDC);
9910 if (ToEnum->isCompleteDefinition()) {
9911 // Do nothing.
9912 } else if (FromEnum->isCompleteDefinition()) {
9913 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9914 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9915 return std::move(Err);
9916 } else {
9917 CompleteDecl(ToEnum);
9918 }
9919 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9920 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9921 if (ToClass->getDefinition()) {
9922 // Do nothing.
9923 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9924 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9925 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9926 return std::move(Err);
9927 } else {
9928 CompleteDecl(ToClass);
9929 }
9930 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9931 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9932 if (ToProto->getDefinition()) {
9933 // Do nothing.
9934 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9935 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9936 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9937 return std::move(Err);
9938 } else {
9939 CompleteDecl(ToProto);
9940 }
9941 }
9942
9943 return ToDC;
9944}
9945
9947 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9948 return cast_or_null<Expr>(*ToSOrErr);
9949 else
9950 return ToSOrErr.takeError();
9951}
9952
9954 if (!FromS)
9955 return nullptr;
9956
9957 // Check whether we've already imported this statement.
9958 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9959 if (Pos != ImportedStmts.end())
9960 return Pos->second;
9961
9962 // Import the statement.
9963 ASTNodeImporter Importer(*this);
9964 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9965 if (!ToSOrErr)
9966 return ToSOrErr;
9967
9968 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9969 auto *FromE = cast<Expr>(FromS);
9970 // Copy ExprBitfields, which may not be handled in Expr subclasses
9971 // constructors.
9972 ToE->setValueKind(FromE->getValueKind());
9973 ToE->setObjectKind(FromE->getObjectKind());
9974 ToE->setDependence(FromE->getDependence());
9975 }
9976
9977 // Record the imported statement object.
9978 ImportedStmts[FromS] = *ToSOrErr;
9979 return ToSOrErr;
9980}
9981
9983 switch (FromNNS.getKind()) {
9986 return FromNNS;
9988 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
9989 auto NSOrErr = Import(Namespace);
9990 if (!NSOrErr)
9991 return NSOrErr.takeError();
9992 auto PrefixOrErr = Import(Prefix);
9993 if (!PrefixOrErr)
9994 return PrefixOrErr.takeError();
9995 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
9996 *PrefixOrErr);
9997 }
9999 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10000 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10001 else
10002 return RDOrErr.takeError();
10004 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10005 return NestedNameSpecifier(*TyOrErr);
10006 } else {
10007 return TyOrErr.takeError();
10008 }
10009 }
10010 llvm_unreachable("Invalid nested name specifier kind");
10011}
10012
10015 // Copied from NestedNameSpecifier mostly.
10017 NestedNameSpecifierLoc NNS = FromNNS;
10018
10019 // Push each of the nested-name-specifiers's onto a stack for
10020 // serialization in reverse order.
10021 while (NNS) {
10022 NestedNames.push_back(NNS);
10023 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10024 }
10025
10027
10028 while (!NestedNames.empty()) {
10029 NNS = NestedNames.pop_back_val();
10030 NestedNameSpecifier Spec = std::nullopt;
10031 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10032 return std::move(Err);
10033
10034 NestedNameSpecifier::Kind Kind = Spec.getKind();
10035
10036 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10038 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10039 return std::move(Err);
10040
10042 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10043 return std::move(Err);
10044 }
10045
10046 switch (Kind) {
10048 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10049 ToLocalBeginLoc, ToLocalEndLoc);
10050 break;
10051
10053 SourceLocation ToTLoc;
10054 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10055 return std::move(Err);
10057 QualType(Spec.getAsType(), 0), ToTLoc);
10058 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10059 break;
10060 }
10061
10063 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10064 break;
10065
10067 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10068 if (!ToSourceRangeOrErr)
10069 return ToSourceRangeOrErr.takeError();
10070
10071 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10072 ToSourceRangeOrErr->getBegin(),
10073 ToSourceRangeOrErr->getEnd());
10074 break;
10075 }
10077 llvm_unreachable("unexpected null nested name specifier");
10078 }
10079 }
10080
10081 return Builder.getWithLocInContext(getToContext());
10082}
10083
10085 switch (From.getKind()) {
10087 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10088 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10089 else
10090 return ToTemplateOrErr.takeError();
10091
10094 UnresolvedSet<2> ToTemplates;
10095 for (auto *I : *FromStorage) {
10096 if (auto ToOrErr = Import(I))
10097 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10098 else
10099 return ToOrErr.takeError();
10100 }
10101 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10102 ToTemplates.end());
10103 }
10104
10107 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10108 if (!DeclNameOrErr)
10109 return DeclNameOrErr.takeError();
10110 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10111 }
10112
10115 auto QualifierOrErr = Import(QTN->getQualifier());
10116 if (!QualifierOrErr)
10117 return QualifierOrErr.takeError();
10118 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10119 if (!TNOrErr)
10120 return TNOrErr.takeError();
10121 return ToContext.getQualifiedTemplateName(
10122 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10123 }
10124
10127 auto QualifierOrErr = Import(DTN->getQualifier());
10128 if (!QualifierOrErr)
10129 return QualifierOrErr.takeError();
10130 return ToContext.getDependentTemplateName(
10131 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10132 }
10133
10137 auto ReplacementOrErr = Import(Subst->getReplacement());
10138 if (!ReplacementOrErr)
10139 return ReplacementOrErr.takeError();
10140
10141 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10142 if (!AssociatedDeclOrErr)
10143 return AssociatedDeclOrErr.takeError();
10144
10145 return ToContext.getSubstTemplateTemplateParm(
10146 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10147 Subst->getPackIndex(), Subst->getFinal());
10148 }
10149
10153 ASTNodeImporter Importer(*this);
10154 auto ArgPackOrErr =
10155 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10156 if (!ArgPackOrErr)
10157 return ArgPackOrErr.takeError();
10158
10159 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10160 if (!AssociatedDeclOrErr)
10161 return AssociatedDeclOrErr.takeError();
10162
10163 return ToContext.getSubstTemplateTemplateParmPack(
10164 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10165 SubstPack->getFinal());
10166 }
10168 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10169 if (!UsingOrError)
10170 return UsingOrError.takeError();
10171 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10172 }
10174 llvm_unreachable("Unexpected DeducedTemplate");
10175 }
10176
10177 llvm_unreachable("Invalid template name kind");
10178}
10179
10181 if (FromLoc.isInvalid())
10182 return SourceLocation{};
10183
10184 SourceManager &FromSM = FromContext.getSourceManager();
10185 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10186
10187 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10188 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10189 if (!ToFileIDOrErr)
10190 return ToFileIDOrErr.takeError();
10191 SourceManager &ToSM = ToContext.getSourceManager();
10192 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10193}
10194
10196 SourceLocation ToBegin, ToEnd;
10197 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10198 return std::move(Err);
10199 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10200 return std::move(Err);
10201
10202 return SourceRange(ToBegin, ToEnd);
10203}
10204
10206 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10207 if (Pos != ImportedFileIDs.end())
10208 return Pos->second;
10209
10210 SourceManager &FromSM = FromContext.getSourceManager();
10211 SourceManager &ToSM = ToContext.getSourceManager();
10212 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10213
10214 // Map the FromID to the "to" source manager.
10215 FileID ToID;
10216 if (FromSLoc.isExpansion()) {
10217 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10218 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10219 if (!ToSpLoc)
10220 return ToSpLoc.takeError();
10221 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10222 if (!ToExLocS)
10223 return ToExLocS.takeError();
10224 unsigned ExLength = FromSM.getFileIDSize(FromID);
10225 SourceLocation MLoc;
10226 if (FromEx.isMacroArgExpansion()) {
10227 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10228 } else {
10229 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10230 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10231 FromEx.isExpansionTokenRange());
10232 else
10233 return ToExLocE.takeError();
10234 }
10235 ToID = ToSM.getFileID(MLoc);
10236 } else {
10237 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10238
10239 if (!IsBuiltin && !Cache->BufferOverridden) {
10240 // Include location of this file.
10241 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10242 if (!ToIncludeLoc)
10243 return ToIncludeLoc.takeError();
10244
10245 // Every FileID that is not the main FileID needs to have a valid include
10246 // location so that the include chain points to the main FileID. When
10247 // importing the main FileID (which has no include location), we need to
10248 // create a fake include location in the main file to keep this property
10249 // intact.
10250 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10251 if (FromID == FromSM.getMainFileID())
10252 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10253
10254 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10255 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10256 // the disk again
10257 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10258 // than mmap the files several times.
10259 auto Entry =
10260 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10261 // FIXME: The filename may be a virtual name that does probably not
10262 // point to a valid file and we get no Entry here. In this case try with
10263 // the memory buffer below.
10264 if (Entry)
10265 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10266 FromSLoc.getFile().getFileCharacteristic());
10267 }
10268 }
10269
10270 if (ToID.isInvalid() || IsBuiltin) {
10271 // FIXME: We want to re-use the existing MemoryBuffer!
10272 std::optional<llvm::MemoryBufferRef> FromBuf =
10273 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10274 FromSM.getFileManager(), SourceLocation{});
10275 if (!FromBuf)
10276 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10277
10278 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10279 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10280 FromBuf->getBufferIdentifier());
10281 ToID = ToSM.createFileID(std::move(ToBuf),
10282 FromSLoc.getFile().getFileCharacteristic());
10283 }
10284 }
10285
10286 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10287
10288 ImportedFileIDs[FromID] = ToID;
10289 return ToID;
10290}
10291
10293 ExpectedExpr ToExprOrErr = Import(From->getInit());
10294 if (!ToExprOrErr)
10295 return ToExprOrErr.takeError();
10296
10297 auto LParenLocOrErr = Import(From->getLParenLoc());
10298 if (!LParenLocOrErr)
10299 return LParenLocOrErr.takeError();
10300
10301 auto RParenLocOrErr = Import(From->getRParenLoc());
10302 if (!RParenLocOrErr)
10303 return RParenLocOrErr.takeError();
10304
10305 if (From->isBaseInitializer()) {
10306 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10307 if (!ToTInfoOrErr)
10308 return ToTInfoOrErr.takeError();
10309
10310 SourceLocation EllipsisLoc;
10311 if (From->isPackExpansion())
10312 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10313 return std::move(Err);
10314
10315 return new (ToContext) CXXCtorInitializer(
10316 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10317 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10318 } else if (From->isMemberInitializer()) {
10319 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10320 if (!ToFieldOrErr)
10321 return ToFieldOrErr.takeError();
10322
10323 auto MemberLocOrErr = Import(From->getMemberLocation());
10324 if (!MemberLocOrErr)
10325 return MemberLocOrErr.takeError();
10326
10327 return new (ToContext) CXXCtorInitializer(
10328 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10329 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10330 } else if (From->isIndirectMemberInitializer()) {
10331 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10332 if (!ToIFieldOrErr)
10333 return ToIFieldOrErr.takeError();
10334
10335 auto MemberLocOrErr = Import(From->getMemberLocation());
10336 if (!MemberLocOrErr)
10337 return MemberLocOrErr.takeError();
10338
10339 return new (ToContext) CXXCtorInitializer(
10340 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10341 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10342 } else if (From->isDelegatingInitializer()) {
10343 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10344 if (!ToTInfoOrErr)
10345 return ToTInfoOrErr.takeError();
10346
10347 return new (ToContext)
10348 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10349 *ToExprOrErr, *RParenLocOrErr);
10350 } else {
10351 // FIXME: assert?
10352 return make_error<ASTImportError>();
10353 }
10354}
10355
10358 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10359 if (Pos != ImportedCXXBaseSpecifiers.end())
10360 return Pos->second;
10361
10362 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10363 if (!ToSourceRange)
10364 return ToSourceRange.takeError();
10366 if (!ToTSI)
10367 return ToTSI.takeError();
10368 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10369 if (!ToEllipsisLoc)
10370 return ToEllipsisLoc.takeError();
10371 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10372 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10373 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10374 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10375 return Imported;
10376}
10377
10379 ASTNodeImporter Importer(*this);
10380 return Importer.ImportAPValue(FromValue);
10381}
10382
10384 ExpectedDecl ToOrErr = Import(From);
10385 if (!ToOrErr)
10386 return ToOrErr.takeError();
10387 Decl *To = *ToOrErr;
10388
10389 auto *FromDC = cast<DeclContext>(From);
10390 ASTNodeImporter Importer(*this);
10391
10392 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10393 if (!ToRecord->getDefinition()) {
10394 return Importer.ImportDefinition(
10395 cast<RecordDecl>(FromDC), ToRecord,
10397 }
10398 }
10399
10400 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10401 if (!ToEnum->getDefinition()) {
10402 return Importer.ImportDefinition(
10404 }
10405 }
10406
10407 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10408 if (!ToIFace->getDefinition()) {
10409 return Importer.ImportDefinition(
10410 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10412 }
10413 }
10414
10415 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10416 if (!ToProto->getDefinition()) {
10417 return Importer.ImportDefinition(
10418 cast<ObjCProtocolDecl>(FromDC), ToProto,
10420 }
10421 }
10422
10423 return Importer.ImportDeclContext(FromDC, true);
10424}
10425
10427 if (!FromName)
10428 return DeclarationName{};
10429
10430 switch (FromName.getNameKind()) {
10432 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10433
10437 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10438 return DeclarationName(*ToSelOrErr);
10439 else
10440 return ToSelOrErr.takeError();
10441
10443 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10444 return ToContext.DeclarationNames.getCXXConstructorName(
10445 ToContext.getCanonicalType(*ToTyOrErr));
10446 else
10447 return ToTyOrErr.takeError();
10448 }
10449
10451 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10452 return ToContext.DeclarationNames.getCXXDestructorName(
10453 ToContext.getCanonicalType(*ToTyOrErr));
10454 else
10455 return ToTyOrErr.takeError();
10456 }
10457
10459 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10460 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10461 cast<TemplateDecl>(*ToTemplateOrErr));
10462 else
10463 return ToTemplateOrErr.takeError();
10464 }
10465
10467 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10468 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10469 ToContext.getCanonicalType(*ToTyOrErr));
10470 else
10471 return ToTyOrErr.takeError();
10472 }
10473
10475 return ToContext.DeclarationNames.getCXXOperatorName(
10476 FromName.getCXXOverloadedOperator());
10477
10479 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10480 Import(FromName.getCXXLiteralIdentifier()));
10481
10483 // FIXME: STATICS!
10485 }
10486
10487 llvm_unreachable("Invalid DeclarationName Kind!");
10488}
10489
10491 if (!FromId)
10492 return nullptr;
10493
10494 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10495
10496 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10497 ToId->setBuiltinID(FromId->getBuiltinID());
10498
10499 return ToId;
10500}
10501
10504 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10505 return Import(FromII);
10506 return FromIO.getOperator();
10507}
10508
10510 if (FromSel.isNull())
10511 return Selector{};
10512
10514 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10515 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10516 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10517 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10518}
10519
10523 llvm::Error Err = llvm::Error::success();
10524 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10525 for (unsigned Idx = 0; Idx < Size; Idx++) {
10526 APValue Tmp = importChecked(Err, From[Idx]);
10527 To[Idx] = Tmp;
10528 }
10529 };
10530 switch (FromValue.getKind()) {
10531 case APValue::None:
10533 case APValue::Int:
10534 case APValue::Float:
10538 Result = FromValue;
10539 break;
10540 case APValue::Vector: {
10541 Result.MakeVector();
10543 Result.setVectorUninit(FromValue.getVectorLength());
10544 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10545 Elts.data(), FromValue.getVectorLength());
10546 break;
10547 }
10548 case APValue::Array:
10549 Result.MakeArray(FromValue.getArrayInitializedElts(),
10550 FromValue.getArraySize());
10551 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10552 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10553 FromValue.getArrayInitializedElts());
10554 break;
10555 case APValue::Struct:
10556 Result.MakeStruct(FromValue.getStructNumBases(),
10557 FromValue.getStructNumFields());
10558 ImportLoop(
10559 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10560 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10561 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10562 break;
10563 case APValue::Union: {
10564 Result.MakeUnion();
10565 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10566 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10567 if (Err)
10568 return std::move(Err);
10569 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10570 break;
10571 }
10573 Result.MakeAddrLabelDiff();
10574 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10575 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10576 if (Err)
10577 return std::move(Err);
10578 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10579 cast<AddrLabelExpr>(ImpRHS));
10580 break;
10581 }
10583 const Decl *ImpMemPtrDecl =
10584 importChecked(Err, FromValue.getMemberPointerDecl());
10585 if (Err)
10586 return std::move(Err);
10588 Result.setMemberPointerUninit(
10589 cast<const ValueDecl>(ImpMemPtrDecl),
10591 FromValue.getMemberPointerPath().size());
10592 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10593 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10594 Idx++) {
10595 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10596 if (Err)
10597 return std::move(Err);
10598 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10599 }
10600 break;
10601 }
10602 case APValue::LValue:
10604 QualType FromElemTy;
10605 if (FromValue.getLValueBase()) {
10606 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10607 "in C++20 dynamic allocation are transient so they shouldn't "
10608 "appear in the AST");
10609 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10610 if (const auto *E =
10611 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10612 FromElemTy = E->getType();
10613 const Expr *ImpExpr = importChecked(Err, E);
10614 if (Err)
10615 return std::move(Err);
10616 Base = APValue::LValueBase(ImpExpr,
10617 FromValue.getLValueBase().getCallIndex(),
10618 FromValue.getLValueBase().getVersion());
10619 } else {
10620 FromElemTy =
10621 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10622 const Decl *ImpDecl = importChecked(
10623 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10624 if (Err)
10625 return std::move(Err);
10627 FromValue.getLValueBase().getCallIndex(),
10628 FromValue.getLValueBase().getVersion());
10629 }
10630 } else {
10631 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10632 const Type *ImpTypeInfo = importChecked(
10633 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10634 QualType ImpType =
10635 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10636 if (Err)
10637 return std::move(Err);
10639 ImpType);
10640 }
10641 }
10642 CharUnits Offset = FromValue.getLValueOffset();
10643 unsigned PathLength = FromValue.getLValuePath().size();
10644 Result.MakeLValue();
10645 if (FromValue.hasLValuePath()) {
10646 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10647 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10648 FromValue.isNullPointer());
10650 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10651 if (FromElemTy->isRecordType()) {
10652 const Decl *FromDecl =
10653 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10654 const Decl *ImpDecl = importChecked(Err, FromDecl);
10655 if (Err)
10656 return std::move(Err);
10657 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10658 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10659 else
10660 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10662 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10663 } else {
10664 FromElemTy =
10665 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10666 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10667 FromPath[LoopIdx].getAsArrayIndex());
10668 }
10669 }
10670 } else
10671 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10672 FromValue.isNullPointer());
10673 }
10674 if (Err)
10675 return std::move(Err);
10676 return Result;
10677}
10678
10680 DeclContext *DC,
10681 unsigned IDNS,
10682 NamedDecl **Decls,
10683 unsigned NumDecls) {
10684 if (ODRHandling == ODRHandlingType::Conservative)
10685 // Report error at any name conflict.
10686 return make_error<ASTImportError>(ASTImportError::NameConflict);
10687 else
10688 // Allow to create the new Decl with the same name.
10689 return Name;
10690}
10691
10693 if (LastDiagFromFrom)
10694 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10695 FromContext.getDiagnostics());
10696 LastDiagFromFrom = false;
10697 return ToContext.getDiagnostics().Report(Loc, DiagID);
10698}
10699
10701 if (!LastDiagFromFrom)
10702 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10703 ToContext.getDiagnostics());
10704 LastDiagFromFrom = true;
10705 return FromContext.getDiagnostics().Report(Loc, DiagID);
10706}
10707
10709 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10710 if (!ID->getDefinition())
10711 ID->startDefinition();
10712 }
10713 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10714 if (!PD->getDefinition())
10715 PD->startDefinition();
10716 }
10717 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10718 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10719 TD->startDefinition();
10720 TD->setCompleteDefinition(true);
10721 }
10722 }
10723 else {
10724 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10725 }
10726}
10727
10729 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10730 assert((Inserted || Pos->second == To) &&
10731 "Try to import an already imported Decl");
10732 if (!Inserted)
10733 return Pos->second;
10734 // This mapping should be maintained only in this function. Therefore do not
10735 // check for additional consistency.
10736 ImportedFromDecls[To] = From;
10737 // In the case of TypedefNameDecl we create the Decl first and only then we
10738 // import and set its DeclContext. So, the DC is still not set when we reach
10739 // here from GetImportedOrCreateDecl.
10740 if (To->getDeclContext())
10741 AddToLookupTable(To);
10742 return To;
10743}
10744
10745std::optional<ASTImportError>
10747 auto Pos = ImportDeclErrors.find(FromD);
10748 if (Pos != ImportDeclErrors.end())
10749 return Pos->second;
10750 else
10751 return std::nullopt;
10752}
10753
10755 auto InsertRes = ImportDeclErrors.insert({From, Error});
10756 (void)InsertRes;
10757 // Either we set the error for the first time, or we already had set one and
10758 // now we want to set the same error.
10759 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10760}
10761
10763 bool Complain) {
10764 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10765 ImportedTypes.find(From.getTypePtr());
10766 if (Pos != ImportedTypes.end()) {
10767 if (ExpectedType ToFromOrErr = Import(From)) {
10768 if (ToContext.hasSameType(*ToFromOrErr, To))
10769 return true;
10770 } else {
10771 llvm::consumeError(ToFromOrErr.takeError());
10772 }
10773 }
10774
10776 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10777 getStructuralEquivalenceKind(*this), false, Complain);
10778 return Ctx.IsEquivalent(From, To);
10779}
Defines the clang::ASTContext interface.
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static ExpectedStmt ImportLoopControlStmt(ASTNodeImporter &NodeImporter, ASTImporter &Importer, StmtClass *S)
static auto getTemplateDefinition(T *D) -> T *
static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D)
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::FileManager interface and associated types.
TokenType getType() const
Returns the token's type, e.g.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the Objective-C statement AST node classes.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
llvm::APInt getValue() const
unsigned getVersion() const
Definition APValue.cpp:113
QualType getTypeInfoType() const
Definition APValue.cpp:117
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition APValue.cpp:55
unsigned getCallIndex() const
Definition APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition APValue.h:207
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition APValue.h:215
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
const LValueBase getLValueBase() const
Definition APValue.cpp:983
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1003
const FieldDecl * getUnionField() const
Definition APValue.h:629
unsigned getStructNumFields() const
Definition APValue.h:608
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition APValue.h:204
ValueKind getKind() const
Definition APValue.h:461
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:988
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1073
unsigned getArrayInitializedElts() const
Definition APValue.h:595
unsigned getStructNumBases() const
Definition APValue.h:604
bool hasLValuePath() const
Definition APValue.cpp:998
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1066
APValue & getUnionValue()
Definition APValue.h:633
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:649
CharUnits & getLValueOffset()
Definition APValue.cpp:993
unsigned getVectorLength() const
Definition APValue.h:571
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1080
unsigned getArraySize() const
Definition APValue.h:599
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:129
bool isNullPointer() const
Definition APValue.cpp:1019
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:645
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
Definition ASTContext.h:926
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType CharTy
CanQualType SignedCharTy
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
CanQualType UnsignedCharTy
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
CanQualType WCharTy
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 importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition ASTImporter.h:65
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
StringRef ImportASTStringRef(StringRef FromStr)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedDecl VisitRequiresExprBodyDecl(RequiresExprBodyDecl *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitRequiresExpr(RequiresExpr *E)
ExpectedDecl VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitConceptDecl(ConceptDecl *D)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
SmallVector< TemplateArgument, 8 > TemplateArgsTy
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
Expected< concepts::Requirement * > ImportNestedRequirement(concepts::NestedRequirement *From)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
bool hasReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the given function has a return type that contains a reference (in any way) t...
ASTNodeImporter(ASTImporter &Importer)
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitConceptSpecializationExpr(ConceptSpecializationExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
Expected< concepts::Requirement * > ImportExprRequirement(concepts::ExprRequirement *From)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
Error ImportConstraintSatisfaction(const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
Expected< concepts::Requirement * > ImportTypeRequirement(concepts::TypeRequirement *From)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedStmt VisitBreakStmt(BreakStmt *S)
DesignatedInitExpr::Designator Designator
SourceLocation getColonLoc() const
Definition Expr.h:4315
SourceLocation getQuestionLoc() const
Definition Expr.h:4314
Represents an access specifier followed by colon ':'.
Definition DeclCXX.h:86
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition DeclCXX.h:108
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition Expr.h:4484
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4499
SourceLocation getLabelLoc() const
Definition Expr.h:4501
LabelDecl * getLabel() const
Definition Expr.h:4507
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition TypeBase.h:3489
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:5955
Represents a loop initializing the elements of an array.
Definition Expr.h:5902
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5917
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5922
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition TypeBase.h:3892
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2721
SourceLocation getRBracketLoc() const
Definition Expr.h:2769
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2750
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:2998
uint64_t getValue() const
Definition ExprCXX.h:3046
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3036
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3038
Expr * getDimensionExpression() const
Definition ExprCXX.h:3048
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3044
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3035
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3722
bool isVolatile() const
Definition Stmt.h:3272
outputs_range outputs()
Definition Stmt.h:3369
SourceLocation getAsmLoc() const
Definition Stmt.h:3266
inputs_range inputs()
Definition Stmt.h:3340
unsigned getNumClobbers() const
Definition Stmt.h:3317
unsigned getNumOutputs() const
Definition Stmt.h:3285
unsigned getNumInputs() const
Definition Stmt.h:3307
bool isSimple() const
Definition Stmt.h:3269
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6814
Expr ** getSubExprs()
Definition Expr.h:6889
SourceLocation getRParenLoc() const
Definition Expr.h:6943
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5151
AtomicOp getOp() const
Definition Expr.h:6877
SourceLocation getBuiltinLoc() const
Definition Expr.h:6942
Attr - This represents one attribute.
Definition Attr.h:44
attr::Kind getKind() const
Definition Attr.h:90
void setPackExpansion(bool PE)
Definition Attr.h:106
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition Attr.h:104
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition Stmt.h:2203
Stmt * getSubStmt()
Definition Stmt.h:2239
SourceLocation getAttrLoc() const
Definition Stmt.h:2234
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2235
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition Stmt.cpp:436
Represents a C++ declaration that introduces decls from somewhere else.
Definition DeclCXX.h:3496
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3403
shadow_range shadows() const
Definition DeclCXX.h:3562
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4387
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4441
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4425
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4429
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4434
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4422
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
Expr * getLHS() const
Definition Expr.h:4022
SourceLocation getOperatorLoc() const
Definition Expr.h:4014
Expr * getRHS() const
Definition Expr.h:4024
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:4977
Opcode getOpcode() const
Definition Expr.h:4017
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4192
A binding in a decomposition declaration.
Definition DeclCXX.h:4185
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4218
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4211
void setBinding(QualType DeclaredType, Expr *Binding)
Set the binding for this BindingDecl, along with its declared type (which should be a possibly-cv-qua...
Definition DeclCXX.h:4223
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4229
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8130
Pointer to a block type.
Definition TypeBase.h:3542
BreakStmt - This represents a break.
Definition Stmt.h:3135
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5478
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
BuiltinTemplateKind getBuiltinTemplateKind() const
This class is used for builtin types like 'int'.
Definition TypeBase.h:3164
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition Expr.cpp:2099
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:1494
CXXTemporary * getTemporary()
Definition ExprCXX.h:1512
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition ExprCXX.cpp:1118
const Expr * getSubExpr() const
Definition ExprCXX.h:1516
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:723
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition ExprCXX.h:735
bool getValue() const
Definition ExprCXX.h:740
SourceLocation getLocation() const
Definition ExprCXX.h:746
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:28
SourceLocation getCatchLoc() const
Definition StmtCXX.h:48
Stmt * getHandlerBlock() const
Definition StmtCXX.h:51
VarDecl * getExceptionDecl() const
Definition StmtCXX.h:49
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:892
Represents a call to a C++ constructor.
Definition ExprCXX.h:1549
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1730
void setIsImmediateEscalating(bool Set)
Definition ExprCXX.h:1711
bool isElidable() const
Whether this construction is elidable.
Definition ExprCXX.h:1618
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition ExprCXX.h:1623
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition ExprCXX.cpp:1180
arg_range arguments()
Definition ExprCXX.h:1673
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1642
bool isImmediateEscalating() const
Definition ExprCXX.h:1707
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition ExprCXX.h:1651
SourceLocation getLocation() const
Definition ExprCXX.h:1614
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1612
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1631
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1689
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1660
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2943
Represents a C++ base or member initializer.
Definition DeclCXX.h:2369
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2509
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2469
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2571
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2568
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2479
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2567
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2474
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2503
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2447
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2441
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2453
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2529
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2523
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2495
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1979
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2063
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1271
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition ExprCXX.h:1345
const ParmVarDecl * getParam() const
Definition ExprCXX.h:1313
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1341
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1039
bool hasRewrittenInit() const
Definition ExprCXX.h:1316
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1378
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Definition ExprCXX.cpp:1093
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1435
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition ExprCXX.h:1423
bool hasRewrittenInit() const
Definition ExprCXX.h:1407
FieldDecl * getField()
Get the field whose initializer will be used.
Definition ExprCXX.h:1412
SourceLocation getBeginLoc() const
Definition ExprCXX.h:1442
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2628
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2667
bool isArrayForm() const
Definition ExprCXX.h:2654
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2678
bool isGlobalDelete() const
Definition ExprCXX.h:2653
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2663
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2655
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3872
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:3971
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:3974
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition ExprCXX.cpp:1550
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:4026
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4018
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4005
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4045
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4014
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4034
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4010
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:3998
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:3962
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:3985
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:3954
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4073
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3112
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:806
Represents a folding of a pack over an operator.
Definition ExprCXX.h:5034
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5056
Expr * getRHS() const
Definition ExprCXX.h:5060
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5076
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5078
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5081
Expr * getLHS() const
Definition ExprCXX.h:5059
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5077
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5079
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
DeclStmt * getBeginStmt()
Definition StmtCXX.h:163
DeclStmt * getLoopVarStmt()
Definition StmtCXX.h:169
DeclStmt * getEndStmt()
Definition StmtCXX.h:166
SourceLocation getForLoc() const
Definition StmtCXX.h:202
DeclStmt * getRangeStmt()
Definition StmtCXX.h:162
SourceLocation getRParenLoc() const
Definition StmtCXX.h:205
SourceLocation getColonLoc() const
Definition StmtCXX.h:204
SourceLocation getCoawaitLoc() const
Definition StmtCXX.h:203
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, SourceLocation RPLoc)
Definition ExprCXX.cpp:918
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1753
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1794
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1790
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1806
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1804
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:179
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition ExprCXX.cpp:692
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2129
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2755
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2778
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2225
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:375
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:406
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:413
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:409
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2357
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, const ImplicitAllocationParameters &IAP, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition ExprCXX.cpp:293
SourceRange getDirectInitRange() const
Definition ExprCXX.h:2611
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2574
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:2471
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2529
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2564
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2463
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2496
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2440
SourceRange getSourceRange() const
Definition ExprCXX.h:2612
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2518
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2558
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2461
bool isGlobalNew() const
Definition ExprCXX.h:2523
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2535
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4311
bool getValue() const
Definition ExprCXX.h:4334
SourceLocation getEndLoc() const
Definition ExprCXX.h:4331
Expr * getOperand() const
Definition ExprCXX.h:4328
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4330
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:768
SourceLocation getLocation() const
Definition ExprCXX.h:782
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL)
Definition ExprCXX.cpp:624
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2747
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2841
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2811
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2825
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2832
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2800
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2856
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2829
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2814
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:2848
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition DeclCXX.h:539
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition DeclCXX.cpp:2020
method_range methods() const
Definition DeclCXX.h:650
CXXRecordDecl * getDefinition() const
Definition DeclCXX.h:548
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition DeclCXX.cpp:141
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition DeclCXX.cpp:2050
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2033
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2046
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition DeclCXX.cpp:1834
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition DeclCXX.cpp:2027
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2061
CXXRecordDecl * getPreviousDecl()
Definition DeclCXX.h:530
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:870
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:286
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:304
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition ExprCXX.h:322
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2198
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2217
SourceLocation getRParenLoc() const
Definition ExprCXX.h:2221
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:780
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:800
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1901
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition ExprCXX.cpp:1146
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:1930
Represents a C++ temporary.
Definition ExprCXX.h:1460
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition ExprCXX.cpp:1113
Represents the this expression in C++.
Definition ExprCXX.h:1155
bool isImplicit() const
Definition ExprCXX.h:1178
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition ExprCXX.cpp:1585
SourceLocation getLocation() const
Definition ExprCXX.h:1172
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1209
const Expr * getSubExpr() const
Definition ExprCXX.h:1229
SourceLocation getThrowLoc() const
Definition ExprCXX.h:1232
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition ExprCXX.h:1239
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:69
SourceLocation getTryLoc() const
Definition StmtCXX.h:95
CXXCatchStmt * getHandler(unsigned i)
Definition StmtCXX.h:108
unsigned getNumHandlers() const
Definition StmtCXX.h:107
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition StmtCXX.cpp:25
CompoundStmt * getTryBlock()
Definition StmtCXX.h:100
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:848
bool isTypeOperand() const
Definition ExprCXX.h:884
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition ExprCXX.h:891
Expr * getExprOperand() const
Definition ExprCXX.h:895
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:902
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3746
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3790
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3801
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition ExprCXX.cpp:1488
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3784
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3795
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3804
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2877
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1513
ADLCallKind getADLCallKind() const
Definition Expr.h:3028
Expr * getCallee()
Definition Expr.h:3024
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3176
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3068
arg_range arguments()
Definition Expr.h:3129
SourceLocation getRParenLoc() const
Definition Expr.h:3208
CaseStmt - Represent a case statement.
Definition Stmt.h:1920
Stmt * getSubStmt()
Definition Stmt.h:2033
Expr * getLHS()
Definition Stmt.h:2003
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:1989
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition Stmt.cpp:1268
SourceLocation getCaseLoc() const
Definition Stmt.h:1985
Expr * getRHS()
Definition Stmt.h:2015
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3610
path_iterator path_begin()
Definition Expr.h:3680
CastKind getCastKind() const
Definition Expr.h:3654
path_iterator path_end()
Definition Expr.h:3681
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3730
Expr * getSubExpr()
Definition Expr.h:3660
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1621
unsigned getValue() const
Definition Expr.h:1629
CharacterLiteralKind getKind() const
Definition Expr.h:1622
How to handle import errors that occur when import of a child declaration of a DeclContext fails.
bool ignoreChildErrorOnParent(Decl *FromChildD) const
Determine if import failure of a child does not cause import failure of its parent.
ChildErrorHandlingStrategy(const Decl *FromD)
void handleChildImportResult(Error &ResultErr, Error &&ChildErr)
Process the import result of a child (of the current declaration).
ChildErrorHandlingStrategy(const DeclContext *FromDC)
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4782
SourceLocation getBuiltinLoc() const
Definition Expr.h:4829
Expr * getLHS() const
Definition Expr.h:4824
bool isConditionDependent() const
Definition Expr.h:4812
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4805
Expr * getRHS() const
Definition Expr.h:4826
SourceLocation getRParenLoc() const
Definition Expr.h:4832
Expr * getCond() const
Definition Expr.h:4822
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3275
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4234
QualType getComputationLHSType() const
Definition Expr.h:4268
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition Expr.cpp:4999
QualType getComputationResultType() const
Definition Expr.h:4271
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3539
SourceLocation getLParenLoc() const
Definition Expr.h:3574
bool isFileScope() const
Definition Expr.h:3571
const Expr * getInitializer() const
Definition Expr.h:3567
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3577
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1720
unsigned size() const
Definition Stmt.h:1765
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1770
body_range body()
Definition Stmt.h:1783
SourceLocation getLBracLoc() const
Definition Stmt.h:1857
bool hasStoredFPFeatures() const
Definition Stmt.h:1767
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition Stmt.cpp:394
SourceLocation getRBracLoc() const
Definition Stmt.h:1858
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
A reference to a concept and its template args, as it appears in the code.
Definition ASTConcept.h:130
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ASTConcept.h:170
NamedDecl * getFoundDecl() const
Definition ASTConcept.h:197
const DeclarationNameInfo & getConceptNameInfo() const
Definition ASTConcept.h:174
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:203
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
TemplateDecl * getNamedConcept() const
Definition ASTConcept.h:201
SourceLocation getTemplateKWLoc() const
Definition ASTConcept.h:180
Represents the specialization of a concept - evaluates to a prvalue of type bool.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
ConceptReference * getConceptReference() const
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
ConditionalOperator - The ?
Definition Expr.h:4325
Expr * getLHS() const
Definition Expr.h:4359
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4348
Expr * getRHS() const
Definition Expr.h:4360
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3760
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1082
APValue getAPValueResult() const
Definition Expr.cpp:409
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:346
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:47
llvm::SmallVector< UnsatisfiedConstraintRecord, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition ASTConcept.h:67
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition DeclCXX.h:3677
ContinueStmt - This represents a continue.
Definition Stmt.h:3119
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4653
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4721
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4757
static ConvertVectorExpr * Create(const ASTContext &C, Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5552
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4754
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4746
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4743
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition TypeBase.h:3436
Represents a pointer type decayed from an array or function type.
Definition TypeBase.h:3525
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
AccessSpecifier getAccess() const
The results of name lookup within a DeclContext.
Definition DeclBase.h:1382
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2109
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h:2577
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2198
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isRecord() const
Definition DeclBase.h:2189
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
void removeDecl(Decl *D)
Removes a declaration from this context.
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition DeclBase.h:2688
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition DeclBase.h:2373
bool isFunctionOrMethod() const
Definition DeclBase.h:2161
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition DeclGroup.h:64
iterator begin()
Definition DeclGroup.h:95
bool isNull() const
Definition DeclGroup.h:75
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1270
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1381
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1425
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1474
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1397
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition Expr.cpp:484
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1405
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1363
ValueDecl * getDecl()
Definition Expr.h:1338
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1451
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1468
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1457
SourceLocation getLocation() const
Definition Expr.h:1346
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1413
bool isImmediateEscalating() const
Definition Expr.h:1478
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1611
SourceLocation getEndLoc() const
Definition Stmt.h:1634
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1629
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1637
A simple visitor class that helps create declaration visitors.
Definition DeclVisitor.h:68
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:435
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition DeclBase.cpp:285
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition DeclBase.h:1226
bool hasAttrs() const
Definition DeclBase.h:518
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
void addAttr(Attr *A)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:593
@ FOK_None
Not a friend object.
Definition DeclBase.h:1217
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition DeclBase.h:1180
void setAccess(AccessSpecifier AS)
Definition DeclBase.h:502
SourceLocation getLocation() const
Definition DeclBase.h:439
const char * getDeclKindName() const
Definition DeclBase.cpp:169
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
void setImplicit(bool I=true)
Definition DeclBase.h:594
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition DeclBase.h:608
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:575
DeclContext * getDeclContext()
Definition DeclBase.h:448
AccessSpecifier getAccess() const
Definition DeclBase.h:507
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:439
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:431
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:531
AttrVec & getAttrs()
Definition DeclBase.h:524
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:382
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:918
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:386
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:978
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:831
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:814
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2000
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:845
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
A decomposition declaration.
Definition DeclCXX.h:4249
SourceLocation getDefaultLoc() const
Definition Stmt.h:2085
Stmt * getSubStmt()
Definition Stmt.h:2081
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3512
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition ExprCXX.cpp:544
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3586
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3560
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3578
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3620
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3596
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3570
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3551
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3548
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4011
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4101
IdentifierOrOverloadedOperator getName() const
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
bool hasTemplateKeyword() const
Was this template name was preceeded by the template keyword?
Represents a single C99 designator.
Definition Expr.h:5528
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5655
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5609
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5645
SourceLocation getFieldLoc() const
Definition Expr.h:5636
SourceLocation getRBracketLoc() const
Definition Expr.h:5684
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4669
SourceLocation getEllipsisLoc() const
Definition Expr.h:5678
SourceLocation getDotLoc() const
Definition Expr.h:5631
SourceLocation getLBracketLoc() const
Definition Expr.h:5672
Represents a C99 designated initializer expression.
Definition Expr.h:5485
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5767
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5749
MutableArrayRef< Designator > designators()
Definition Expr.h:5718
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5753
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5715
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5740
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5765
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4710
A little helper class used to produce diagnostics.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2832
Stmt * getBody()
Definition Stmt.h:2857
Expr * getCond()
Definition Stmt.h:2850
SourceLocation getWhileLoc() const
Definition Stmt.h:2863
SourceLocation getDoLoc() const
Definition Stmt.h:2861
SourceLocation getRParenLoc() const
Definition Stmt.h:2865
Symbolic representation of a dynamic allocation.
Definition APValue.h:65
Represents an empty-declaration.
Definition Decl.h:5161
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3423
llvm::APSInt getInitVal() const
Definition Decl.h:3443
const Expr * getInitExpr() const
Definition Decl.h:3441
Represents an enum.
Definition Decl.h:4007
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4270
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4216
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4208
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4219
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4180
EnumDecl * getMostRecentDecl()
Definition Decl.h:4103
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4225
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5021
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4171
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5081
EnumDecl * getDefinition() const
Definition Decl.h:4110
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4197
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4163
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3862
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3884
Store information needed for an explicit specifier.
Definition DeclCXX.h:1924
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1932
const Expr * getExpr() const
Definition DeclCXX.h:1933
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3663
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3698
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3687
unsigned getNumObjects() const
Definition ExprCXX.h:3691
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3669
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition ExprCXX.cpp:1464
This represents one expression.
Definition Expr.h:112
void setType(QualType t)
Definition Expr.h:145
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:444
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:241
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:451
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:223
QualType getType() const
Definition Expr.h:144
ExprDependence getDependence() const
Definition Expr.h:164
An expression trait intrinsic.
Definition ExprCXX.h:3071
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3103
Expr * getQueriedExpression() const
Definition ExprCXX.h:3110
ExpressionTrait getTrait() const
Definition ExprCXX.h:3106
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3104
ExtVectorType - Extended vector type.
Definition TypeBase.h:4267
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Definition Decl.h:3160
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3260
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4714
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3340
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3334
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4724
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3276
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3384
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4824
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:53
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1581
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1575
SourceLocation getLocation() const
Definition Expr.h:1707
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1072
llvm::APFloat getValue() const
Definition Expr.h:1666
bool isExact() const
Definition Expr.h:1699
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2888
Stmt * getInit()
Definition Stmt.h:2903
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1082
SourceLocation getRParenLoc() const
Definition Stmt.h:2948
Stmt * getBody()
Definition Stmt.h:2932
Expr * getInc()
Definition Stmt.h:2931
SourceLocation getForLoc() const
Definition Stmt.h:2944
Expr * getCond()
Definition Stmt.h:2930
SourceLocation getLParenLoc() const
Definition Stmt.h:2946
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:54
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition DeclFriend.h:58
SourceLocation getFriendLoc() const
Retrieves the location of the 'friend' keyword.
Definition DeclFriend.h:144
SourceLocation getEllipsisLoc() const
Retrieves the location of the '...', if present.
Definition DeclFriend.h:149
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:139
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:125
const Expr * getSubExpr() const
Definition Expr.h:1062
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3129
Represents a function declaration or definition.
Definition Decl.h:2000
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3268
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2476
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4187
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4182
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3287
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3149
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2701
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3540
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2758
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:2909
SourceLocation getDefaultLoc() const
Definition Decl.h:2398
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2774
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2389
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2377
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2448
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4161
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4312
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2402
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2326
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4378
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2016
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2019
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2888
void setTrivial(bool IT)
Definition Decl.h:2378
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2707
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4133
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4200
bool isDeletedAsWritten() const
Definition Decl.h:2544
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition Decl.cpp:4367
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2353
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition Decl.h:2349
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3544
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2282
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3548
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3552
void setRangeEnd(SourceLocation E)
Definition Decl.h:2218
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2385
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4206
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4406
void setDefaulted(bool D=true)
Definition Decl.h:2386
void setBody(Stmt *B)
Definition Decl.cpp:3280
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2344
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3158
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2394
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4154
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2211
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3188
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition Decl.h:2899
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4832
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5254
QualType desugar() const
Definition TypeBase.h:5835
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5543
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5708
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5694
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary pattern.
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition TypeBase.h:4806
QualType getReturnType() const
Definition TypeBase.h:4790
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3395
unsigned getNumLabels() const
Definition Stmt.h:3545
labels_range labels()
Definition Stmt.h:3568
SourceLocation getRParenLoc() const
Definition Stmt.h:3417
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3510
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3497
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3523
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3486
const Expr * getAsmStringExpr() const
Definition Stmt.h:3422
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3602
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4857
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4874
Represents a C11 generic selection.
Definition Expr.h:6112
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6387
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6407
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6368
SourceLocation getGenericLoc() const
Definition Expr.h:6465
SourceLocation getRParenLoc() const
Definition Expr.h:6469
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6357
SourceLocation getDefaultLoc() const
Definition Expr.h:6468
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
Definition Expr.cpp:4599
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6364
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6375
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6412
GotoStmt - This represents a direct goto.
Definition Stmt.h:2969
SourceLocation getLabelLoc() const
Definition Stmt.h:2987
SourceLocation getGotoLoc() const
Definition Stmt.h:2985
LabelDecl * getLabel() const
Definition Stmt.h:2982
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:2259
Stmt * getThen()
Definition Stmt.h:2348
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition Stmt.cpp:1006
SourceLocation getIfLoc() const
Definition Stmt.h:2425
IfStatementKind getStatementKind() const
Definition Stmt.h:2460
SourceLocation getElseLoc() const
Definition Stmt.h:2428
Stmt * getInit()
Definition Stmt.h:2409
SourceLocation getLParenLoc() const
Definition Stmt.h:2477
Expr * getCond()
Definition Stmt.h:2336
Stmt * getElse()
Definition Stmt.h:2357
SourceLocation getRParenLoc() const
Definition Stmt.h:2479
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1030
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1731
const Expr * getSubExpr() const
Definition Expr.h:1743
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3787
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2068
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1780
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:5991
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5035
Represents a C array with an unspecified size.
Definition TypeBase.h:3909
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3467
unsigned getChainingSize() const
Definition Decl.h:3492
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3488
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3008
SourceLocation getGotoLoc() const
Definition Stmt.h:3024
SourceLocation getStarLoc() const
Definition Stmt.h:3026
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2575
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2588
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2587
Describes an C or C++ initializer list.
Definition Expr.h:5233
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5345
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5410
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5359
unsigned getNumInits() const
Definition Expr.h:5263
SourceLocation getLBraceLoc() const
Definition Expr.h:5394
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2433
InitListExpr * getSyntacticForm() const
Definition Expr.h:5406
bool hadArrayRangeDesignator() const
Definition Expr.h:5417
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5335
SourceLocation getRBraceLoc() const
Definition Expr.h:5396
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5365
ArrayRef< Expr * > inits()
Definition Expr.h:5283
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5420
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:971
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1536
An lvalue reference type, per C++11 [dcl.ref].
Definition TypeBase.h:3617
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:2146
LabelDecl * getDecl() const
Definition Stmt.h:2164
Stmt * getSubStmt()
Definition Stmt.h:2168
SourceLocation getIdentLoc() const
Definition Stmt.h:2161
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool capturesVariable() const
Determine whether this capture handles a variable.
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition ExprCXX.cpp:1264
ValueDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
SourceLocation getLocation() const
Retrieve the source location of the capture.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1970
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition ExprCXX.cpp:1312
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2188
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition ExprCXX.h:2173
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition ExprCXX.h:2121
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2051
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition ExprCXX.cpp:1404
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition ExprCXX.h:2176
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition ExprCXX.h:2028
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2085
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition ExprCXX.h:2023
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1400
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition DeclCXX.h:3308
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3354
Represents a linkage specification.
Definition DeclCXX.h:3015
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3057
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3038
SourceLocation getExternLoc() const
Definition DeclCXX.h:3054
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3055
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3049
Represents the results of name lookup.
Definition Lookup.h:147
iterator end() const
Definition Lookup.h:359
iterator begin() const
Definition Lookup.h:358
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition TypeBase.h:6133
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4922
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4939
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:4991
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:4962
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3298
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3470
SourceLocation getOperatorLoc() const
Definition Expr.h:3480
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3415
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3400
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3381
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3442
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3522
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition Expr.cpp:1746
Expr * getBase() const
Definition Expr.h:3375
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3431
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3423
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3475
bool isArrow() const
Definition Expr.h:3482
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3385
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3653
Provides information a specialization of a member of a class template, which may be a member function...
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
This represents a decl that may have a name.
Definition Decl.h:274
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1182
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents a C++ namespace alias.
Definition DeclCXX.h:3201
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3262
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3284
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3287
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3290
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3271
Represent a C++ namespace.
Definition Decl.h:592
SourceLocation getRBraceLoc() const
Definition Decl.h:692
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:691
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:675
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:657
void setRBraceLoc(SourceLocation L)
Definition Decl.h:694
Class that aids in the construction of nested-name-specifiers along with source-location information ...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1683
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1697
SourceLocation getSemiLoc() const
Definition Stmt.h:1694
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:1643
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
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition TypeBase.h:7840
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 a pointer to an Objective C object.
Definition TypeBase.h:7896
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:896
SourceLocation getGetterNameLoc() const
Definition DeclObjC.h:886
ObjCMethodDecl * getGetterMethodDecl() const
Definition DeclObjC.h:901
bool isInstanceProperty() const
Definition DeclObjC.h:854
ObjCMethodDecl * getSetterMethodDecl() const
Definition DeclObjC.h:904
SourceLocation getSetterNameLoc() const
Definition DeclObjC.h:894
SourceLocation getAtLoc() const
Definition DeclObjC.h:796
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:819
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:924
Selector getSetterName() const
Definition DeclObjC.h:893
TypeSourceInfo * getTypeSourceInfo() const
Definition DeclObjC.h:802
QualType getType() const
Definition DeclObjC.h:804
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:831
Selector getGetterName() const
Definition DeclObjC.h:885
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition DeclObjC.h:920
SourceLocation getLParenLoc() const
Definition DeclObjC.h:799
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:905
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition DeclObjC.h:827
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition DeclObjC.h:815
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:888
PropertyControl getPropertyImplementation() const
Definition DeclObjC.h:912
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:902
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2805
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:2879
SourceLocation getPropertyIvarDeclLoc() const
Definition DeclObjC.h:2882
Kind getPropertyImplementation() const
Definition DeclObjC.h:2875
ObjCPropertyDecl * getPropertyDecl() const
Definition DeclObjC.h:2870
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclObjC.h:2867
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2084
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition DeclObjC.h:2261
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:2209
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition DeclObjC.h:2250
void startDefinition()
Starts the definition of this Objective-C protocol.
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2158
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2165
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2179
protocol_iterator protocol_end() const
Definition DeclObjC.h:2172
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2186
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:578
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition DeclObjC.h:636
const Type * getTypeForDecl() const
Definition Decl.h:3538
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition DeclObjC.h:644
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition DeclObjC.h:623
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition DeclObjC.h:633
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:662
SourceLocation getRAngleLoc() const
Definition DeclObjC.h:711
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
SourceLocation getLAngleLoc() const
Definition DeclObjC.h:710
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2527
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2586
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2560
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2574
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1649
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2567
unsigned getNumExpressions() const
Definition Expr.h:2598
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2564
unsigned getNumComponents() const
Definition Expr.h:2582
Helper class for OffsetOfExpr.
Definition Expr.h:2421
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2479
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2485
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1684
@ Array
An index into an array.
Definition Expr.h:2426
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2430
@ Field
A field.
Definition Expr.h:2428
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2433
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2507
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2475
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2508
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2495
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1178
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1228
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1200
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3282
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3264
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3237
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3243
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3256
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3252
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3229
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition ExprCXX.h:3344
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3240
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3272
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3339
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:4365
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4394
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4405
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4401
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2182
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2207
const Expr * getSubExpr() const
Definition Expr.h:2199
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2211
ArrayRef< Expr * > exprs()
Definition Expr.h:6057
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4849
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6044
SourceLocation getLParenLoc() const
Definition Expr.h:6059
SourceLocation getRParenLoc() const
Definition Expr.h:6060
Sugar for parentheses used when specifying types.
Definition TypeBase.h:3302
Represents a parameter to a function.
Definition Decl.h:1790
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1871
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1850
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1858
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3011
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1886
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1931
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1919
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3036
bool isObjCMethodParameter() const
Definition Decl.h:1833
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1854
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1823
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1923
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1818
bool hasInheritedDefaultArg() const
Definition Decl.h:1935
void setKNRPromoted(bool promoted)
Definition Decl.h:1874
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1882
Expr * getDefaultArg()
Definition Decl.cpp:2999
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3041
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3047
unsigned getFunctionScopeDepth() const
Definition Decl.h:1840
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1939
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3328
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2005
SourceLocation getBeginLoc() const
Definition Expr.h:2070
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:629
bool isTransparent() const
Definition Expr.h:2044
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2040
StringLiteral * getFunctionName()
Definition Expr.h:2049
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2696
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8278
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8310
Represents a template name as written in source code.
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
An rvalue reference type, per C++11 [dcl.ref].
Definition TypeBase.h:3635
Represents a struct/union/class.
Definition Decl.h:4312
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5173
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4368
field_range fields() const
Definition Decl.h:4515
RecordDecl * getMostRecentDecl()
Definition Decl.h:4338
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5218
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4496
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4364
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:5312
Represents the body of a requires-expression.
Definition DeclCXX.h:2098
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
SourceLocation getRBraceLoc() const
SourceLocation getRequiresKWLoc() const
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
RequiresExprBodyDecl * getBody() const
ArrayRef< concepts::Requirement * > getRequirements() const
ArrayRef< ParmVarDecl * > getLocalParameters() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3160
SourceLocation getReturnLoc() const
Definition Stmt.h:3209
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3196
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition Stmt.cpp:1252
Expr * getRetValue()
Definition Stmt.h:3187
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4577
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4613
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4610
SourceLocation getRParenLoc() const
Definition Expr.h:4597
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4600
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4443
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4505
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4528
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1709
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4533
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4502
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4508
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4511
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4517
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:4951
SourceLocation getBeginLoc() const
Definition Expr.h:4996
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:4992
SourceLocation getEndLoc() const
Definition Expr.h:4997
SourceLocIdentKind getIdentKind() const
Definition Expr.h:4971
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4136
bool isFailed() const
Definition DeclCXX.h:4165
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4167
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4529
CompoundStmt * getSubStmt()
Definition Expr.h:4546
unsigned getTemplateDepth() const
Definition Expr.h:4558
SourceLocation getRParenLoc() const
Definition Expr.h:4555
SourceLocation getLParenLoc() const
Definition Expr.h:4553
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:85
child_iterator child_begin()
Definition Stmt.h:1571
StmtClass getStmtClass() const
Definition Stmt.h:1472
child_iterator child_end()
Definition Stmt.h:1572
const char * getStmtClassName() const
Definition Stmt.cpp:87
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:350
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1799
bool isPascal() const
Definition Expr.h:1922
tokloc_iterator tokloc_begin() const
Definition Expr.h:1965
tokloc_iterator tokloc_end() const
Definition Expr.h:1969
StringLiteralKind getKind() const
Definition Expr.h:1912
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
Definition Expr.cpp:1184
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1875
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1940
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4666
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4711
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4717
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4715
SourceLocation getNameLoc() const
Definition ExprCXX.h:4701
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:1895
SourceLocation getColonLoc() const
Definition Stmt.h:1899
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1893
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2509
SourceLocation getSwitchLoc() const
Definition Stmt.h:2644
SourceLocation getLParenLoc() const
Definition Stmt.h:2646
SourceLocation getRParenLoc() const
Definition Stmt.h:2648
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition Stmt.cpp:1129
Expr * getCond()
Definition Stmt.h:2572
Stmt * getBody()
Definition Stmt.h:2584
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1148
Stmt * getInit()
Definition Stmt.h:2589
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2640
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3717
SourceRange getBraceRange() const
Definition Decl.h:3788
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3832
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4918
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3807
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3812
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:3965
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3948
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4895
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4890
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4932
TagKind getTagKind() const
Definition Decl.h:3911
void setBraceRange(SourceRange R)
Definition Decl.h:3789
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3815
A convenient class for passing around template argument information.
SourceLocation getRAngleLoc() const
void addArgument(const TemplateArgumentLoc &Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
SourceLocation getLAngleLoc() const
A template argument list.
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
TemplateArgumentLocInfo getLocInfo() const
const TemplateArgument & getArgument() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
UnsignedOrNone getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isCanonicalExpr() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
SourceLocation getRAngleLoc() const
SourceLocation getLAngleLoc() const
SourceLocation getTemplateLoc() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
TemplateNameKind templateParameterKind() const
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
unsigned getIndex() const
Retrieve the index of the template parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
The top declaration context.
Definition Decl.h:105
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3688
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3706
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition ASTConcept.h:227
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3547
Symbolic representation of typeid(T) for some type T.
Definition APValue.h:44
const Type * getType() const
Definition APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition TypeLoc.cpp:193
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition TypeBase.h:6165
A container of type source information.
Definition TypeBase.h:8249
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:267
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8260
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2898
bool getBoolValue() const
Definition ExprCXX.h:2949
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2969
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
Definition ExprCXX.cpp:1914
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2974
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2960
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2941
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2973
const APValue & getAPValue() const
Definition ExprCXX.h:2954
bool isStoredAsBoolean() const
Definition ExprCXX.h:2945
An operation on a type.
Definition TypeVisitor.h:64
The base class of the type hierarchy.
Definition TypeBase.h:1833
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isArrayType() const
Definition TypeBase.h:8614
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:752
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2782
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9044
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2435
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition TypeBase.h:2411
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9091
bool isRecordType() const
Definition TypeBase.h:8642
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3667
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3612
QualType getUnderlyingType() const
Definition Decl.h:3617
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2625
SourceLocation getRParenLoc() const
Definition Expr.h:2701
SourceLocation getOperatorLoc() const
Definition Expr.h:2698
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2671
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2657
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2289
Expr * getSubExpr() const
Definition Expr.h:2285
Opcode getOpcode() const
Definition Expr.h:2280
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2381
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2384
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5013
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2298
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3392
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3466
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3461
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition ExprCXX.cpp:432
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4128
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4220
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4223
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4214
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4201
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition ExprCXX.cpp:1652
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Definition ExprCXX.cpp:1645
void addDecl(NamedDecl *D)
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition TypeBase.h:5970
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4037
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4067
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4071
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4064
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4088
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3940
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3971
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3981
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3988
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:3998
Represents a C++ using-declaration.
Definition DeclCXX.h:3591
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3640
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3625
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3632
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3618
Represents C++ using-directive.
Definition DeclCXX.h:3096
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3167
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3244
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3163
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3171
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3174
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3141
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3792
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3816
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3828
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3812
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3873
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3902
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3906
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3399
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3463
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3374
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4891
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:4915
SourceLocation getBuiltinLoc() const
Definition Expr.h:4918
SourceLocation getRParenLoc() const
Definition Expr.h:4921
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4912
const Expr * getSubExpr() const
Definition Expr.h:4907
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
void setType(QualType newType)
Definition Decl.h:724
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2810
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1569
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2935
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:2260
bool isInlineSpecified() const
Definition Decl.h:1554
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2366
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2571
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2557
void setInlineSpecified()
Definition Decl.h:1558
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2772
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1342
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1173
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1551
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1177
const Expr * getInit() const
Definition Decl.h:1368
void setConstexpr(bool IC)
Definition Decl.h:1572
void setInit(Expr *I)
Definition Decl.cpp:2477
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2815
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1168
void setImplicitlyInline()
Definition Decl.h:1563
VarDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1358
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2898
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()
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:3966
Represents a GCC generic vector type.
Definition TypeBase.h:4175
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2697
Expr * getCond()
Definition Stmt.h:2749
SourceLocation getWhileLoc() const
Definition Stmt.h:2802
SourceLocation getRParenLoc() const
Definition Stmt.h:2807
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1209
SourceLocation getLParenLoc() const
Definition Stmt.h:2805
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition Stmt.cpp:1191
Stmt * getBody()
Definition Stmt.h:2761
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
ConceptSpecializationExpr * getReturnTypeRequirementSubstitutedConstraintExpr() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SatisfactionStatus getSatisfactionStatus() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
RequirementKind getKind() const
A requires-expression requirement which queries the existence of a type name or type template special...
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
Definition SPIR.cpp:35
Definition SPIR.cpp:47
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
Definition Address.h:330
llvm::Expected< SourceLocation > ExpectedSLoc
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
llvm::Expected< const Type * > ExpectedTypePtr
CanThrowResult
Possible results from evaluation of a noexcept expression.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:149
std::pair< FileID, unsigned > FileIDAndOffset
llvm::Expected< DeclarationName > ExpectedName
llvm::Expected< Decl * > ExpectedDecl
@ Property
The type of a property.
Definition TypeBase.h:911
@ Result
The result type of a method or function.
Definition TypeBase.h:905
const FunctionProtoType * T
llvm::Expected< QualType > ExpectedType
@ Template
We are parsing a template declaration.
Definition Parser.h:81
@ VarTemplate
The name was classified as a variable template name.
Definition Sema.h:583
std::pair< SourceLocation, StringRef > ConstraintSubstitutionDiagnostic
Unsatisfied constraint expressions if the template arguments could be substituted into them,...
Definition ASTConcept.h:40
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:132
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:149
llvm::Expected< Expr * > ExpectedExpr
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition DeclBase.h:1288
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:188
U cast(CodeGen::Address addr)
Definition Address.h:327
bool isLambdaMethod(const DeclContext *DC)
Definition ASTLambda.h:39
llvm::Expected< Stmt * > ExpectedStmt
static void updateFlags(const Decl *From, Decl *To)
unsigned int uint32_t
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
const UnsatisfiedConstraintRecord * end() const
Definition ASTConcept.h:100
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
const UnsatisfiedConstraintRecord * begin() const
Definition ASTConcept.h:96
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
const Expr * ConstraintExpr
Definition Decl.h:88
Information about how a lambda is numbered within its context.
Definition DeclCXX.h:1796
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition Decl.h:887
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:905
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:898
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5323
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5327
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5313
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5316
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5319
Extra information about a function prototype.
Definition TypeBase.h:5339
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
const NamespaceBaseDecl * Namespace
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Location information for a TemplateArgument.
SourceLocation getTemplateEllipsisLoc() const
SourceLocation getTemplateKwLoc() const
TypeSourceInfo * getAsTypeSourceInfo() const
SourceLocation getTemplateNameLoc() const