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 (Expr *E = Record->dyn_cast<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 = Record->dyn_cast<std::pair<SourceLocation, StringRef> *>();
1079
1080 ExpectedSLoc ToPairFirst = import(Pair->first);
1081 if (!ToPairFirst)
1082 return ToPairFirst.takeError();
1083 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1084 ToSat.Details.emplace_back(
1085 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->getOriginalDecl();
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->getOriginalDecl() == 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->getOriginalDecl();
2412 ToRecordDecl = RecordTo->getOriginalDecl();
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->getOriginalDecl();
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->getOriginalDecl();
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 =
3761 dyn_cast<ClassTemplateSpecializationDecl>(T->getOriginalDecl()))
3762 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3763 if (checkTemplateArgument(Arg))
3764 return true;
3765 return isAncestorDeclContextOf(ParentDC, T->getOriginalDecl());
3766 }
3767
3768 std::optional<bool> VisitPointerType(const PointerType *T) {
3769 return CheckType(T->getPointeeType());
3770 }
3771
3772 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3773 return CheckType(T->getPointeeTypeAsWritten());
3774 }
3775
3776 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3777 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3778 }
3779
3780 std::optional<bool> VisitUsingType(const UsingType *T) {
3781 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3782 }
3783
3784 std::optional<bool>
3785 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3786 for (const auto &Arg : T->template_arguments())
3787 if (checkTemplateArgument(Arg))
3788 return true;
3789 // This type is a "sugar" to a record type, it can have a desugared type.
3790 return {};
3791 }
3792
3793 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3794 return CheckType(T->getBaseType());
3795 }
3796
3797 std::optional<bool>
3798 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3799 // The "associated declaration" can be the same as ParentDC.
3800 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3801 return true;
3802 return {};
3803 }
3804
3805 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3806 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3807 return true;
3808
3809 return CheckType(T->getElementType());
3810 }
3811
3812 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3813 llvm_unreachable(
3814 "Variable array should not occur in deduced return type of a function");
3815 }
3816
3817 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3818 llvm_unreachable("Incomplete array should not occur in deduced return type "
3819 "of a function");
3820 }
3821
3822 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3823 llvm_unreachable("Dependent array should not occur in deduced return type "
3824 "of a function");
3825 }
3826
3827private:
3828 const DeclContext *const ParentDC;
3829
3830 bool checkTemplateArgument(const TemplateArgument &Arg) {
3831 switch (Arg.getKind()) {
3833 return false;
3835 return CheckType(Arg.getIntegralType());
3837 return CheckType(Arg.getAsType());
3839 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3841 // FIXME: The declaration in this case is not allowed to be in a function?
3842 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3844 // FIXME: The type is not allowed to be in the function?
3845 return CheckType(Arg.getNullPtrType());
3847 return CheckType(Arg.getStructuralValueType());
3849 for (const auto &PackArg : Arg.getPackAsArray())
3850 if (checkTemplateArgument(PackArg))
3851 return true;
3852 return false;
3854 // Templates can not be defined locally in functions.
3855 // A template passed as argument can be not in ParentDC.
3856 return false;
3858 // Templates can not be defined locally in functions.
3859 // A template passed as argument can be not in ParentDC.
3860 return false;
3861 }
3862 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3863 };
3864};
3865} // namespace
3866
3867/// This function checks if the given function has a return type that contains
3868/// a reference (in any way) to a declaration inside the same function.
3870 QualType FromTy = D->getType();
3871 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3872 assert(FromFPT && "Must be called on FunctionProtoType");
3873
3874 auto IsCXX11Lambda = [&]() {
3875 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3876 return false;
3877
3878 return isLambdaMethod(D);
3879 };
3880
3881 QualType RetT = FromFPT->getReturnType();
3882 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3883 FunctionDecl *Def = D->getDefinition();
3884 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3885 return Visitor.CheckType(RetT);
3886 }
3887
3888 return false;
3889}
3890
3892ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3893 Expr *ExplicitExpr = ESpec.getExpr();
3894 if (ExplicitExpr)
3895 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3896 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3897}
3898
3900
3902 auto RedeclIt = Redecls.begin();
3903 // Import the first part of the decl chain. I.e. import all previous
3904 // declarations starting from the canonical decl.
3905 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3906 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3907 if (!ToRedeclOrErr)
3908 return ToRedeclOrErr.takeError();
3909 }
3910 assert(*RedeclIt == D);
3911
3912 // Import the major distinguishing characteristics of this function.
3913 DeclContext *DC, *LexicalDC;
3914 DeclarationName Name;
3915 SourceLocation Loc;
3916 NamedDecl *ToD;
3917 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3918 return std::move(Err);
3919 if (ToD)
3920 return ToD;
3921
3922 FunctionDecl *FoundByLookup = nullptr;
3924
3925 // If this is a function template specialization, then try to find the same
3926 // existing specialization in the "to" context. The lookup below will not
3927 // find any specialization, but would find the primary template; thus, we
3928 // have to skip normal lookup in case of specializations.
3929 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3930 if (D->getTemplatedKind() ==
3932 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3933 if (!FoundFunctionOrErr)
3934 return FoundFunctionOrErr.takeError();
3935 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3936 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3937 return Def;
3938 FoundByLookup = FoundFunction;
3939 }
3940 }
3941 // Try to find a function in our own ("to") context with the same name, same
3942 // type, and in the same context as the function we're importing.
3943 else if (!LexicalDC->isFunctionOrMethod()) {
3944 SmallVector<NamedDecl *, 4> ConflictingDecls;
3946 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3947 for (auto *FoundDecl : FoundDecls) {
3948 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3949 continue;
3950
3951 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3952 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3953 continue;
3954
3955 if (IsStructuralMatch(D, FoundFunction)) {
3956 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3957 return Def;
3958 FoundByLookup = FoundFunction;
3959 break;
3960 }
3961 // FIXME: Check for overloading more carefully, e.g., by boosting
3962 // Sema::IsOverload out to the AST library.
3963
3964 // Function overloading is okay in C++.
3965 if (Importer.getToContext().getLangOpts().CPlusPlus)
3966 continue;
3967
3968 // Complain about inconsistent function types.
3969 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3970 << Name << D->getType() << FoundFunction->getType();
3971 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3972 << FoundFunction->getType();
3973 ConflictingDecls.push_back(FoundDecl);
3974 }
3975 }
3976
3977 if (!ConflictingDecls.empty()) {
3978 ExpectedName NameOrErr = Importer.HandleNameConflict(
3979 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3980 if (NameOrErr)
3981 Name = NameOrErr.get();
3982 else
3983 return NameOrErr.takeError();
3984 }
3985 }
3986
3987 // We do not allow more than one in-class declaration of a function. This is
3988 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3989 // assumes there is only one in-class declaration. Building a redecl
3990 // chain would result in more than one in-class declaration for
3991 // overrides (even if they are part of the same redecl chain inside the
3992 // derived class.)
3993 if (FoundByLookup) {
3994 if (isa<CXXMethodDecl>(FoundByLookup)) {
3995 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3996 if (!D->doesThisDeclarationHaveABody()) {
3997 if (FunctionTemplateDecl *DescribedD =
3999 // Handle a "templated" function together with its described
4000 // template. This avoids need for a similar check at import of the
4001 // described template.
4002 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4003 "Templated function mapped to non-templated?");
4004 Importer.MapImported(DescribedD,
4005 FoundByLookup->getDescribedFunctionTemplate());
4006 }
4007 return Importer.MapImported(D, FoundByLookup);
4008 } else {
4009 // Let's continue and build up the redecl chain in this case.
4010 // FIXME Merge the functions into one decl.
4011 }
4012 }
4013 }
4014 }
4015
4016 DeclarationNameInfo NameInfo(Name, Loc);
4017 // Import additional name location/type info.
4018 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4019 return std::move(Err);
4020
4021 QualType FromTy = D->getType();
4022 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4023 // Set to true if we do not import the type of the function as is. There are
4024 // cases when the original type would result in an infinite recursion during
4025 // the import. To avoid an infinite recursion when importing, we create the
4026 // FunctionDecl with a simplified function type and update it only after the
4027 // relevant AST nodes are already imported.
4028 // The type is related to TypeSourceInfo (it references the type), so we must
4029 // do the same with TypeSourceInfo.
4030 bool UsedDifferentProtoType = false;
4031 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4032 QualType FromReturnTy = FromFPT->getReturnType();
4033 // Functions with auto return type may define a struct inside their body
4034 // and the return type could refer to that struct.
4035 // E.g.: auto foo() { struct X{}; return X(); }
4036 // To avoid an infinite recursion when importing, create the FunctionDecl
4037 // with a simplified return type.
4039 FromReturnTy = Importer.getFromContext().VoidTy;
4040 UsedDifferentProtoType = true;
4041 }
4042 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4043 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4044 // FunctionDecl that we are importing the FunctionProtoType for.
4045 // To avoid an infinite recursion when importing, create the FunctionDecl
4046 // with a simplified function type.
4047 if (FromEPI.ExceptionSpec.SourceDecl ||
4048 FromEPI.ExceptionSpec.SourceTemplate ||
4049 FromEPI.ExceptionSpec.NoexceptExpr) {
4051 FromEPI = DefaultEPI;
4052 UsedDifferentProtoType = true;
4053 }
4054 FromTy = Importer.getFromContext().getFunctionType(
4055 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4056 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4057 FromTy, D->getBeginLoc());
4058 }
4059
4060 Error Err = Error::success();
4061 auto T = importChecked(Err, FromTy);
4062 auto TInfo = importChecked(Err, FromTSI);
4063 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4064 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4065 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4066 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4067 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4068 TrailingRequiresClause.ConstraintExpr =
4069 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4070 if (Err)
4071 return std::move(Err);
4072
4073 // Import the function parameters.
4075 for (auto *P : D->parameters()) {
4076 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4077 Parameters.push_back(*ToPOrErr);
4078 else
4079 return ToPOrErr.takeError();
4080 }
4081
4082 // Create the imported function.
4083 FunctionDecl *ToFunction = nullptr;
4084 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4085 ExplicitSpecifier ESpec =
4086 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4087 if (Err)
4088 return std::move(Err);
4089 auto ToInheritedConstructor = InheritedConstructor();
4090 if (FromConstructor->isInheritingConstructor()) {
4091 Expected<InheritedConstructor> ImportedInheritedCtor =
4092 import(FromConstructor->getInheritedConstructor());
4093 if (!ImportedInheritedCtor)
4094 return ImportedInheritedCtor.takeError();
4095 ToInheritedConstructor = *ImportedInheritedCtor;
4096 }
4097 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4098 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4099 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4101 ToInheritedConstructor, TrailingRequiresClause))
4102 return ToFunction;
4103 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4104
4105 Error Err = Error::success();
4106 auto ToOperatorDelete = importChecked(
4107 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4108 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4109 if (Err)
4110 return std::move(Err);
4111
4112 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4113 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4114 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4116 TrailingRequiresClause))
4117 return ToFunction;
4118
4119 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4120
4121 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4122 } else if (CXXConversionDecl *FromConversion =
4123 dyn_cast<CXXConversionDecl>(D)) {
4124 ExplicitSpecifier ESpec =
4125 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4126 if (Err)
4127 return std::move(Err);
4128 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4129 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4130 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4131 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4132 SourceLocation(), TrailingRequiresClause))
4133 return ToFunction;
4134 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4135 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4136 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4137 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4138 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4139 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4140 return ToFunction;
4141 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4142 ExplicitSpecifier ESpec =
4143 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4144 CXXConstructorDecl *Ctor =
4145 importChecked(Err, Guide->getCorrespondingConstructor());
4146 const CXXDeductionGuideDecl *SourceDG =
4147 importChecked(Err, Guide->getSourceDeductionGuide());
4148 if (Err)
4149 return std::move(Err);
4150 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4151 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4152 NameInfo, T, TInfo, ToEndLoc, Ctor,
4153 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4154 SourceDG, Guide->getSourceDeductionGuideKind()))
4155 return ToFunction;
4156 } else {
4157 if (GetImportedOrCreateDecl(
4158 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4159 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4161 D->getConstexprKind(), TrailingRequiresClause))
4162 return ToFunction;
4163 }
4164
4165 // Connect the redecl chain.
4166 if (FoundByLookup) {
4167 auto *Recent = const_cast<FunctionDecl *>(
4168 FoundByLookup->getMostRecentDecl());
4169 ToFunction->setPreviousDecl(Recent);
4170 // FIXME Probably we should merge exception specifications. E.g. In the
4171 // "To" context the existing function may have exception specification with
4172 // noexcept-unevaluated, while the newly imported function may have an
4173 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4174 // decl and its redeclarations may be required.
4175 }
4176
4177 StringLiteral *Msg = D->getDeletedMessage();
4178 if (Msg) {
4179 auto Imported = import(Msg);
4180 if (!Imported)
4181 return Imported.takeError();
4182 Msg = *Imported;
4183 }
4184
4185 ToFunction->setQualifierInfo(ToQualifierLoc);
4186 ToFunction->setAccess(D->getAccess());
4187 ToFunction->setLexicalDeclContext(LexicalDC);
4188 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4189 ToFunction->setTrivial(D->isTrivial());
4190 ToFunction->setIsPureVirtual(D->isPureVirtual());
4191 ToFunction->setDefaulted(D->isDefaulted());
4193 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4199 ToFunction->setRangeEnd(ToEndLoc);
4200 ToFunction->setDefaultLoc(ToDefaultLoc);
4201
4202 if (Msg)
4203 ToFunction->setDefaultedOrDeletedInfo(
4205 Importer.getToContext(), {}, Msg));
4206
4207 // Set the parameters.
4208 for (auto *Param : Parameters) {
4209 Param->setOwningFunction(ToFunction);
4210 ToFunction->addDeclInternal(Param);
4211 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4212 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4213 }
4214 ToFunction->setParams(Parameters);
4215
4216 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4217 // params it refers to.
4218 if (TInfo) {
4219 if (auto ProtoLoc =
4220 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4221 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4222 ProtoLoc.setParam(I, Parameters[I]);
4223 }
4224 }
4225
4226 // Import the describing template function, if any.
4227 if (FromFT) {
4228 auto ToFTOrErr = import(FromFT);
4229 if (!ToFTOrErr)
4230 return ToFTOrErr.takeError();
4231 }
4232
4233 // Import Ctor initializers.
4234 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4235 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4236 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4237 // Import first, then allocate memory and copy if there was no error.
4238 if (Error Err = ImportContainerChecked(
4239 FromConstructor->inits(), CtorInitializers))
4240 return std::move(Err);
4241 auto **Memory =
4242 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4243 llvm::copy(CtorInitializers, Memory);
4244 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4245 ToCtor->setCtorInitializers(Memory);
4246 ToCtor->setNumCtorInitializers(NumInitializers);
4247 }
4248 }
4249
4250 // If it is a template, import all related things.
4251 if (Error Err = ImportTemplateInformation(D, ToFunction))
4252 return std::move(Err);
4253
4254 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4256 FromCXXMethod))
4257 return std::move(Err);
4258
4260 Error Err = ImportFunctionDeclBody(D, ToFunction);
4261
4262 if (Err)
4263 return std::move(Err);
4264 }
4265
4266 // Import and set the original type in case we used another type.
4267 if (UsedDifferentProtoType) {
4268 if (ExpectedType TyOrErr = import(D->getType()))
4269 ToFunction->setType(*TyOrErr);
4270 else
4271 return TyOrErr.takeError();
4272 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4273 ToFunction->setTypeSourceInfo(*TSIOrErr);
4274 else
4275 return TSIOrErr.takeError();
4276 }
4277
4278 // FIXME: Other bits to merge?
4279
4280 addDeclToContexts(D, ToFunction);
4281
4282 // Import the rest of the chain. I.e. import all subsequent declarations.
4283 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4284 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4285 if (!ToRedeclOrErr)
4286 return ToRedeclOrErr.takeError();
4287 }
4288
4289 return ToFunction;
4290}
4291
4295
4299
4303
4307
4312
4314 // Import the major distinguishing characteristics of a variable.
4315 DeclContext *DC, *LexicalDC;
4316 DeclarationName Name;
4317 SourceLocation Loc;
4318 NamedDecl *ToD;
4319 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4320 return std::move(Err);
4321 if (ToD)
4322 return ToD;
4323
4324 // Determine whether we've already imported this field.
4325 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4326 for (auto *FoundDecl : FoundDecls) {
4327 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4328 // For anonymous fields, match up by index.
4329 if (!Name &&
4331 ASTImporter::getFieldIndex(FoundField))
4332 continue;
4333
4334 if (Importer.IsStructurallyEquivalent(D->getType(),
4335 FoundField->getType())) {
4336 Importer.MapImported(D, FoundField);
4337 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4338 // initializer of a FieldDecl might not had been instantiated in the
4339 // "To" context. However, the "From" context might instantiated that,
4340 // thus we have to merge that.
4341 // Note: `hasInClassInitializer()` is not the same as non-null
4342 // `getInClassInitializer()` value.
4343 if (Expr *FromInitializer = D->getInClassInitializer()) {
4344 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4345 // Import of the FromInitializer may result in the setting of
4346 // InClassInitializer. If not, set it here.
4347 assert(FoundField->hasInClassInitializer() &&
4348 "Field should have an in-class initializer if it has an "
4349 "expression for it.");
4350 if (!FoundField->getInClassInitializer())
4351 FoundField->setInClassInitializer(*ToInitializerOrErr);
4352 } else {
4353 return ToInitializerOrErr.takeError();
4354 }
4355 }
4356 return FoundField;
4357 }
4358
4359 // FIXME: Why is this case not handled with calling HandleNameConflict?
4360 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4361 << Name << D->getType() << FoundField->getType();
4362 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4363 << FoundField->getType();
4364
4365 return make_error<ASTImportError>(ASTImportError::NameConflict);
4366 }
4367 }
4368
4369 Error Err = Error::success();
4370 auto ToType = importChecked(Err, D->getType());
4371 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4372 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4373 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4374 if (Err)
4375 return std::move(Err);
4376 const Type *ToCapturedVLAType = nullptr;
4377 if (Error Err = Importer.importInto(
4378 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4379 return std::move(Err);
4380
4381 FieldDecl *ToField;
4382 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4383 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4384 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4385 D->getInClassInitStyle()))
4386 return ToField;
4387
4388 ToField->setAccess(D->getAccess());
4389 ToField->setLexicalDeclContext(LexicalDC);
4390 ToField->setImplicit(D->isImplicit());
4391 if (ToCapturedVLAType)
4392 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4393 LexicalDC->addDeclInternal(ToField);
4394 // Import initializer only after the field was created, it may have recursive
4395 // reference to the field.
4396 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4397 if (Err)
4398 return std::move(Err);
4399 if (ToInitializer) {
4400 auto *AlreadyImported = ToField->getInClassInitializer();
4401 if (AlreadyImported)
4402 assert(ToInitializer == AlreadyImported &&
4403 "Duplicate import of in-class initializer.");
4404 else
4405 ToField->setInClassInitializer(ToInitializer);
4406 }
4407
4408 return ToField;
4409}
4410
4412 // Import the major distinguishing characteristics of a variable.
4413 DeclContext *DC, *LexicalDC;
4414 DeclarationName Name;
4415 SourceLocation Loc;
4416 NamedDecl *ToD;
4417 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4418 return std::move(Err);
4419 if (ToD)
4420 return ToD;
4421
4422 // Determine whether we've already imported this field.
4423 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4424 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4425 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4426 // For anonymous indirect fields, match up by index.
4427 if (!Name &&
4429 ASTImporter::getFieldIndex(FoundField))
4430 continue;
4431
4432 if (Importer.IsStructurallyEquivalent(D->getType(),
4433 FoundField->getType(),
4434 !Name.isEmpty())) {
4435 Importer.MapImported(D, FoundField);
4436 return FoundField;
4437 }
4438
4439 // If there are more anonymous fields to check, continue.
4440 if (!Name && I < N-1)
4441 continue;
4442
4443 // FIXME: Why is this case not handled with calling HandleNameConflict?
4444 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4445 << Name << D->getType() << FoundField->getType();
4446 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4447 << FoundField->getType();
4448
4449 return make_error<ASTImportError>(ASTImportError::NameConflict);
4450 }
4451 }
4452
4453 // Import the type.
4454 auto TypeOrErr = import(D->getType());
4455 if (!TypeOrErr)
4456 return TypeOrErr.takeError();
4457
4458 auto **NamedChain =
4459 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4460
4461 unsigned i = 0;
4462 for (auto *PI : D->chain())
4463 if (Expected<NamedDecl *> ToD = import(PI))
4464 NamedChain[i++] = *ToD;
4465 else
4466 return ToD.takeError();
4467
4468 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4469 IndirectFieldDecl *ToIndirectField;
4470 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4471 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4472 // FIXME here we leak `NamedChain` which is allocated before
4473 return ToIndirectField;
4474
4475 ToIndirectField->setAccess(D->getAccess());
4476 ToIndirectField->setLexicalDeclContext(LexicalDC);
4477 LexicalDC->addDeclInternal(ToIndirectField);
4478 return ToIndirectField;
4479}
4480
4481/// Used as return type of getFriendCountAndPosition.
4483 /// Number of similar looking friends.
4484 unsigned int TotalCount;
4485 /// Index of the specific FriendDecl.
4486 unsigned int IndexOfDecl;
4487};
4488
4489static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4490 FriendDecl *FD2) {
4491 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4492 return false;
4493
4494 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4495 return Importer.IsStructurallyEquivalent(
4496 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4497
4498 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4500 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4501 FD2->getASTContext(), NonEquivalentDecls,
4503 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4504 return Ctx.IsEquivalent(FD1, FD2);
4505}
4506
4508 FriendDecl *FD) {
4509 unsigned int FriendCount = 0;
4510 UnsignedOrNone FriendPosition = std::nullopt;
4511 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4512
4513 for (FriendDecl *FoundFriend : RD->friends()) {
4514 if (FoundFriend == FD) {
4515 FriendPosition = FriendCount;
4516 ++FriendCount;
4517 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4518 ++FriendCount;
4519 }
4520 }
4521
4522 assert(FriendPosition && "Friend decl not found in own parent.");
4523
4524 return {FriendCount, *FriendPosition};
4525}
4526
4528 // Import the major distinguishing characteristics of a declaration.
4529 DeclContext *DC, *LexicalDC;
4530 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4531 return std::move(Err);
4532
4533 // Determine whether we've already imported this decl.
4534 // FriendDecl is not a NamedDecl so we cannot use lookup.
4535 // We try to maintain order and count of redundant friend declarations.
4536 const auto *RD = cast<CXXRecordDecl>(DC);
4537 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4538 for (FriendDecl *ImportedFriend : RD->friends())
4539 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4540 ImportedEquivalentFriends.push_back(ImportedFriend);
4541
4542 FriendCountAndPosition CountAndPosition =
4543 getFriendCountAndPosition(Importer, D);
4544
4545 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4546 "Class with non-matching friends is imported, ODR check wrong?");
4547 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4548 return Importer.MapImported(
4549 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4550
4551 // Not found. Create it.
4552 // The declarations will be put into order later by ImportDeclContext.
4554 if (NamedDecl *FriendD = D->getFriendDecl()) {
4555 NamedDecl *ToFriendD;
4556 if (Error Err = importInto(ToFriendD, FriendD))
4557 return std::move(Err);
4558
4559 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4560 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4561 ToFriendD->setObjectOfFriendDecl(false);
4562
4563 ToFU = ToFriendD;
4564 } else { // The friend is a type, not a decl.
4565 if (auto TSIOrErr = import(D->getFriendType()))
4566 ToFU = *TSIOrErr;
4567 else
4568 return TSIOrErr.takeError();
4569 }
4570
4571 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4572 auto **FromTPLists = D->getTrailingObjects();
4573 for (unsigned I = 0; I < D->NumTPLists; I++) {
4574 if (auto ListOrErr = import(FromTPLists[I]))
4575 ToTPLists[I] = *ListOrErr;
4576 else
4577 return ListOrErr.takeError();
4578 }
4579
4580 auto LocationOrErr = import(D->getLocation());
4581 if (!LocationOrErr)
4582 return LocationOrErr.takeError();
4583 auto FriendLocOrErr = import(D->getFriendLoc());
4584 if (!FriendLocOrErr)
4585 return FriendLocOrErr.takeError();
4586 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4587 if (!EllipsisLocOrErr)
4588 return EllipsisLocOrErr.takeError();
4589
4590 FriendDecl *FrD;
4591 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4592 *LocationOrErr, ToFU, *FriendLocOrErr,
4593 *EllipsisLocOrErr, ToTPLists))
4594 return FrD;
4595
4596 FrD->setAccess(D->getAccess());
4597 FrD->setLexicalDeclContext(LexicalDC);
4598 LexicalDC->addDeclInternal(FrD);
4599 return FrD;
4600}
4601
4603 // Import the major distinguishing characteristics of an ivar.
4604 DeclContext *DC, *LexicalDC;
4605 DeclarationName Name;
4606 SourceLocation Loc;
4607 NamedDecl *ToD;
4608 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4609 return std::move(Err);
4610 if (ToD)
4611 return ToD;
4612
4613 // Determine whether we've already imported this ivar
4614 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4615 for (auto *FoundDecl : FoundDecls) {
4616 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4617 if (Importer.IsStructurallyEquivalent(D->getType(),
4618 FoundIvar->getType())) {
4619 Importer.MapImported(D, FoundIvar);
4620 return FoundIvar;
4621 }
4622
4623 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4624 << Name << D->getType() << FoundIvar->getType();
4625 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4626 << FoundIvar->getType();
4627
4628 return make_error<ASTImportError>(ASTImportError::NameConflict);
4629 }
4630 }
4631
4632 Error Err = Error::success();
4633 auto ToType = importChecked(Err, D->getType());
4634 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4635 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4636 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4637 if (Err)
4638 return std::move(Err);
4639
4640 ObjCIvarDecl *ToIvar;
4641 if (GetImportedOrCreateDecl(
4642 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4643 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4644 ToType, ToTypeSourceInfo,
4645 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4646 return ToIvar;
4647
4648 ToIvar->setLexicalDeclContext(LexicalDC);
4649 LexicalDC->addDeclInternal(ToIvar);
4650 return ToIvar;
4651}
4652
4654
4656 auto RedeclIt = Redecls.begin();
4657 // Import the first part of the decl chain. I.e. import all previous
4658 // declarations starting from the canonical decl.
4659 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4660 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4661 if (!RedeclOrErr)
4662 return RedeclOrErr.takeError();
4663 }
4664 assert(*RedeclIt == D);
4665
4666 // Import the major distinguishing characteristics of a variable.
4667 DeclContext *DC, *LexicalDC;
4668 DeclarationName Name;
4669 SourceLocation Loc;
4670 NamedDecl *ToD;
4671 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4672 return std::move(Err);
4673 if (ToD)
4674 return ToD;
4675
4676 // Try to find a variable in our own ("to") context with the same name and
4677 // in the same context as the variable we're importing.
4678 VarDecl *FoundByLookup = nullptr;
4679 if (D->isFileVarDecl()) {
4680 SmallVector<NamedDecl *, 4> ConflictingDecls;
4681 unsigned IDNS = Decl::IDNS_Ordinary;
4682 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4683 for (auto *FoundDecl : FoundDecls) {
4684 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4685 continue;
4686
4687 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4688 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4689 continue;
4690 if (Importer.IsStructurallyEquivalent(D->getType(),
4691 FoundVar->getType())) {
4692
4693 // The VarDecl in the "From" context has a definition, but in the
4694 // "To" context we already have a definition.
4695 VarDecl *FoundDef = FoundVar->getDefinition();
4696 if (D->isThisDeclarationADefinition() && FoundDef)
4697 // FIXME Check for ODR error if the two definitions have
4698 // different initializers?
4699 return Importer.MapImported(D, FoundDef);
4700
4701 // The VarDecl in the "From" context has an initializer, but in the
4702 // "To" context we already have an initializer.
4703 const VarDecl *FoundDInit = nullptr;
4704 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4705 // FIXME Diagnose ODR error if the two initializers are different?
4706 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4707
4708 FoundByLookup = FoundVar;
4709 break;
4710 }
4711
4712 const ArrayType *FoundArray
4713 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4714 const ArrayType *TArray
4715 = Importer.getToContext().getAsArrayType(D->getType());
4716 if (FoundArray && TArray) {
4717 if (isa<IncompleteArrayType>(FoundArray) &&
4718 isa<ConstantArrayType>(TArray)) {
4719 // Import the type.
4720 if (auto TyOrErr = import(D->getType()))
4721 FoundVar->setType(*TyOrErr);
4722 else
4723 return TyOrErr.takeError();
4724
4725 FoundByLookup = FoundVar;
4726 break;
4727 } else if (isa<IncompleteArrayType>(TArray) &&
4728 isa<ConstantArrayType>(FoundArray)) {
4729 FoundByLookup = FoundVar;
4730 break;
4731 }
4732 }
4733
4734 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4735 << Name << D->getType() << FoundVar->getType();
4736 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4737 << FoundVar->getType();
4738 ConflictingDecls.push_back(FoundDecl);
4739 }
4740 }
4741
4742 if (!ConflictingDecls.empty()) {
4743 ExpectedName NameOrErr = Importer.HandleNameConflict(
4744 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4745 if (NameOrErr)
4746 Name = NameOrErr.get();
4747 else
4748 return NameOrErr.takeError();
4749 }
4750 }
4751
4752 Error Err = Error::success();
4753 auto ToType = importChecked(Err, D->getType());
4754 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4755 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4756 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4757 if (Err)
4758 return std::move(Err);
4759
4760 VarDecl *ToVar;
4761 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4762 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4763 if (Error Err =
4764 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4765 return std::move(Err);
4766 DecompositionDecl *ToDecomp;
4767 if (GetImportedOrCreateDecl(
4768 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4769 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4770 return ToDecomp;
4771 ToVar = ToDecomp;
4772 } else {
4773 // Create the imported variable.
4774 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4775 ToInnerLocStart, Loc,
4776 Name.getAsIdentifierInfo(), ToType,
4777 ToTypeSourceInfo, D->getStorageClass()))
4778 return ToVar;
4779 }
4780
4781 ToVar->setTSCSpec(D->getTSCSpec());
4782 ToVar->setQualifierInfo(ToQualifierLoc);
4783 ToVar->setAccess(D->getAccess());
4784 ToVar->setLexicalDeclContext(LexicalDC);
4785 if (D->isInlineSpecified())
4786 ToVar->setInlineSpecified();
4787 if (D->isInline())
4788 ToVar->setImplicitlyInline();
4789
4790 if (FoundByLookup) {
4791 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4792 ToVar->setPreviousDecl(Recent);
4793 }
4794
4795 // Import the described template, if any.
4796 if (D->getDescribedVarTemplate()) {
4797 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4798 if (!ToVTOrErr)
4799 return ToVTOrErr.takeError();
4801 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4803 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4804 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4805 else
4806 return ToInstOrErr.takeError();
4807 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4809 else
4810 return POIOrErr.takeError();
4811 }
4812
4813 if (Error Err = ImportInitializer(D, ToVar))
4814 return std::move(Err);
4815
4816 if (D->isConstexpr())
4817 ToVar->setConstexpr(true);
4818
4819 addDeclToContexts(D, ToVar);
4820
4821 // Import the rest of the chain. I.e. import all subsequent declarations.
4822 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4823 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4824 if (!RedeclOrErr)
4825 return RedeclOrErr.takeError();
4826 }
4827
4828 return ToVar;
4829}
4830
4832 // Parameters are created in the translation unit's context, then moved
4833 // into the function declaration's context afterward.
4834 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4835
4836 Error Err = Error::success();
4837 auto ToDeclName = importChecked(Err, D->getDeclName());
4838 auto ToLocation = importChecked(Err, D->getLocation());
4839 auto ToType = importChecked(Err, D->getType());
4840 if (Err)
4841 return std::move(Err);
4842
4843 // Create the imported parameter.
4844 ImplicitParamDecl *ToParm = nullptr;
4845 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4846 ToLocation, ToDeclName.getAsIdentifierInfo(),
4847 ToType, D->getParameterKind()))
4848 return ToParm;
4849 return ToParm;
4850}
4851
4853 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4854
4855 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4856 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4857 else
4858 return LocOrErr.takeError();
4859
4861 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4862
4863 if (FromParam->hasUninstantiatedDefaultArg()) {
4864 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4865 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4866 else
4867 return ToDefArgOrErr.takeError();
4868 } else if (FromParam->hasUnparsedDefaultArg()) {
4869 ToParam->setUnparsedDefaultArg();
4870 } else if (FromParam->hasDefaultArg()) {
4871 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4872 ToParam->setDefaultArg(*ToDefArgOrErr);
4873 else
4874 return ToDefArgOrErr.takeError();
4875 }
4876
4877 return Error::success();
4878}
4879
4882 Error Err = Error::success();
4883 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4884 ConstructorUsingShadowDecl *ToShadow =
4885 importChecked(Err, From.getShadowDecl());
4886 if (Err)
4887 return std::move(Err);
4888 return InheritedConstructor(ToShadow, ToBaseCtor);
4889}
4890
4892 // Parameters are created in the translation unit's context, then moved
4893 // into the function declaration's context afterward.
4894 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4895
4896 Error Err = Error::success();
4897 auto ToDeclName = importChecked(Err, D->getDeclName());
4898 auto ToLocation = importChecked(Err, D->getLocation());
4899 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4900 auto ToType = importChecked(Err, D->getType());
4901 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4902 if (Err)
4903 return std::move(Err);
4904
4905 ParmVarDecl *ToParm;
4906 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4907 ToInnerLocStart, ToLocation,
4908 ToDeclName.getAsIdentifierInfo(), ToType,
4909 ToTypeSourceInfo, D->getStorageClass(),
4910 /*DefaultArg*/ nullptr))
4911 return ToParm;
4912
4913 // Set the default argument. It should be no problem if it was already done.
4914 // Do not import the default expression before GetImportedOrCreateDecl call
4915 // to avoid possible infinite import loop because circular dependency.
4916 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4917 return std::move(Err);
4918
4919 if (D->isObjCMethodParameter()) {
4922 } else {
4925 }
4926
4927 return ToParm;
4928}
4929
4931 // Import the major distinguishing characteristics of a method.
4932 DeclContext *DC, *LexicalDC;
4933 DeclarationName Name;
4934 SourceLocation Loc;
4935 NamedDecl *ToD;
4936 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4937 return std::move(Err);
4938 if (ToD)
4939 return ToD;
4940
4941 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4942 for (auto *FoundDecl : FoundDecls) {
4943 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4944 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4945 continue;
4946
4947 // Check return types.
4948 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4949 FoundMethod->getReturnType())) {
4950 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4951 << D->isInstanceMethod() << Name << D->getReturnType()
4952 << FoundMethod->getReturnType();
4953 Importer.ToDiag(FoundMethod->getLocation(),
4954 diag::note_odr_objc_method_here)
4955 << D->isInstanceMethod() << Name;
4956
4957 return make_error<ASTImportError>(ASTImportError::NameConflict);
4958 }
4959
4960 // Check the number of parameters.
4961 if (D->param_size() != FoundMethod->param_size()) {
4962 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4963 << D->isInstanceMethod() << Name
4964 << D->param_size() << FoundMethod->param_size();
4965 Importer.ToDiag(FoundMethod->getLocation(),
4966 diag::note_odr_objc_method_here)
4967 << D->isInstanceMethod() << Name;
4968
4969 return make_error<ASTImportError>(ASTImportError::NameConflict);
4970 }
4971
4972 // Check parameter types.
4974 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4975 P != PEnd; ++P, ++FoundP) {
4976 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4977 (*FoundP)->getType())) {
4978 Importer.FromDiag((*P)->getLocation(),
4979 diag::warn_odr_objc_method_param_type_inconsistent)
4980 << D->isInstanceMethod() << Name
4981 << (*P)->getType() << (*FoundP)->getType();
4982 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4983 << (*FoundP)->getType();
4984
4985 return make_error<ASTImportError>(ASTImportError::NameConflict);
4986 }
4987 }
4988
4989 // Check variadic/non-variadic.
4990 // Check the number of parameters.
4991 if (D->isVariadic() != FoundMethod->isVariadic()) {
4992 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4993 << D->isInstanceMethod() << Name;
4994 Importer.ToDiag(FoundMethod->getLocation(),
4995 diag::note_odr_objc_method_here)
4996 << D->isInstanceMethod() << Name;
4997
4998 return make_error<ASTImportError>(ASTImportError::NameConflict);
4999 }
5000
5001 // FIXME: Any other bits we need to merge?
5002 return Importer.MapImported(D, FoundMethod);
5003 }
5004 }
5005
5006 Error Err = Error::success();
5007 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5008 auto ToReturnType = importChecked(Err, D->getReturnType());
5009 auto ToReturnTypeSourceInfo =
5011 if (Err)
5012 return std::move(Err);
5013
5014 ObjCMethodDecl *ToMethod;
5015 if (GetImportedOrCreateDecl(
5016 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5017 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5021 return ToMethod;
5022
5023 // FIXME: When we decide to merge method definitions, we'll need to
5024 // deal with implicit parameters.
5025
5026 // Import the parameters
5028 for (auto *FromP : D->parameters()) {
5029 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5030 ToParams.push_back(*ToPOrErr);
5031 else
5032 return ToPOrErr.takeError();
5033 }
5034
5035 // Set the parameters.
5036 for (auto *ToParam : ToParams) {
5037 ToParam->setOwningFunction(ToMethod);
5038 ToMethod->addDeclInternal(ToParam);
5039 }
5040
5042 D->getSelectorLocs(FromSelLocs);
5043 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5044 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5045 return std::move(Err);
5046
5047 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5048
5049 ToMethod->setLexicalDeclContext(LexicalDC);
5050 LexicalDC->addDeclInternal(ToMethod);
5051
5052 // Implicit params are declared when Sema encounters the definition but this
5053 // never happens when the method is imported. Manually declare the implicit
5054 // params now that the MethodDecl knows its class interface.
5055 if (D->getSelfDecl())
5056 ToMethod->createImplicitParams(Importer.getToContext(),
5057 ToMethod->getClassInterface());
5058
5059 return ToMethod;
5060}
5061
5063 // Import the major distinguishing characteristics of a category.
5064 DeclContext *DC, *LexicalDC;
5065 DeclarationName Name;
5066 SourceLocation Loc;
5067 NamedDecl *ToD;
5068 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5069 return std::move(Err);
5070 if (ToD)
5071 return ToD;
5072
5073 Error Err = Error::success();
5074 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5075 auto ToLocation = importChecked(Err, D->getLocation());
5076 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5077 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5078 if (Err)
5079 return std::move(Err);
5080
5082 if (GetImportedOrCreateDecl(
5083 Result, D, Importer.getToContext(), DC, D->getVariance(),
5084 ToVarianceLoc, D->getIndex(),
5085 ToLocation, Name.getAsIdentifierInfo(),
5086 ToColonLoc, ToTypeSourceInfo))
5087 return Result;
5088
5089 // Only import 'ObjCTypeParamType' after the decl is created.
5090 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5091 if (Err)
5092 return std::move(Err);
5093 Result->setTypeForDecl(ToTypeForDecl);
5094 Result->setLexicalDeclContext(LexicalDC);
5095 return Result;
5096}
5097
5099 // Import the major distinguishing characteristics of a category.
5100 DeclContext *DC, *LexicalDC;
5101 DeclarationName Name;
5102 SourceLocation Loc;
5103 NamedDecl *ToD;
5104 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5105 return std::move(Err);
5106 if (ToD)
5107 return ToD;
5108
5109 ObjCInterfaceDecl *ToInterface;
5110 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5111 return std::move(Err);
5112
5113 // Determine if we've already encountered this category.
5114 ObjCCategoryDecl *MergeWithCategory
5115 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5116 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5117 if (!ToCategory) {
5118
5119 Error Err = Error::success();
5120 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5121 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5122 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5123 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5124 if (Err)
5125 return std::move(Err);
5126
5127 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5128 ToAtStartLoc, Loc,
5129 ToCategoryNameLoc,
5130 Name.getAsIdentifierInfo(), ToInterface,
5131 /*TypeParamList=*/nullptr,
5132 ToIvarLBraceLoc,
5133 ToIvarRBraceLoc))
5134 return ToCategory;
5135
5136 ToCategory->setLexicalDeclContext(LexicalDC);
5137 LexicalDC->addDeclInternal(ToCategory);
5138 // Import the type parameter list after MapImported, to avoid
5139 // loops when bringing in their DeclContext.
5140 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5141 ToCategory->setTypeParamList(*PListOrErr);
5142 else
5143 return PListOrErr.takeError();
5144
5145 // Import protocols
5147 SmallVector<SourceLocation, 4> ProtocolLocs;
5149 = D->protocol_loc_begin();
5151 FromProtoEnd = D->protocol_end();
5152 FromProto != FromProtoEnd;
5153 ++FromProto, ++FromProtoLoc) {
5154 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5155 Protocols.push_back(*ToProtoOrErr);
5156 else
5157 return ToProtoOrErr.takeError();
5158
5159 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5160 ProtocolLocs.push_back(*ToProtoLocOrErr);
5161 else
5162 return ToProtoLocOrErr.takeError();
5163 }
5164
5165 // FIXME: If we're merging, make sure that the protocol list is the same.
5166 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5167 ProtocolLocs.data(), Importer.getToContext());
5168
5169 } else {
5170 Importer.MapImported(D, ToCategory);
5171 }
5172
5173 // Import all of the members of this category.
5174 if (Error Err = ImportDeclContext(D))
5175 return std::move(Err);
5176
5177 // If we have an implementation, import it as well.
5178 if (D->getImplementation()) {
5179 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5180 import(D->getImplementation()))
5181 ToCategory->setImplementation(*ToImplOrErr);
5182 else
5183 return ToImplOrErr.takeError();
5184 }
5185
5186 return ToCategory;
5187}
5188
5191 if (To->getDefinition()) {
5193 if (Error Err = ImportDeclContext(From))
5194 return Err;
5195 return Error::success();
5196 }
5197
5198 // Start the protocol definition
5199 To->startDefinition();
5200
5201 // Import protocols
5203 SmallVector<SourceLocation, 4> ProtocolLocs;
5205 From->protocol_loc_begin();
5206 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5207 FromProtoEnd = From->protocol_end();
5208 FromProto != FromProtoEnd;
5209 ++FromProto, ++FromProtoLoc) {
5210 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5211 Protocols.push_back(*ToProtoOrErr);
5212 else
5213 return ToProtoOrErr.takeError();
5214
5215 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5216 ProtocolLocs.push_back(*ToProtoLocOrErr);
5217 else
5218 return ToProtoLocOrErr.takeError();
5219
5220 }
5221
5222 // FIXME: If we're merging, make sure that the protocol list is the same.
5223 To->setProtocolList(Protocols.data(), Protocols.size(),
5224 ProtocolLocs.data(), Importer.getToContext());
5225
5226 if (shouldForceImportDeclContext(Kind)) {
5227 // Import all of the members of this protocol.
5228 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5229 return Err;
5230 }
5231 return Error::success();
5232}
5233
5235 // If this protocol has a definition in the translation unit we're coming
5236 // from, but this particular declaration is not that definition, import the
5237 // definition and map to that.
5239 if (Definition && Definition != D) {
5240 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5241 return Importer.MapImported(D, *ImportedDefOrErr);
5242 else
5243 return ImportedDefOrErr.takeError();
5244 }
5245
5246 // Import the major distinguishing characteristics of a protocol.
5247 DeclContext *DC, *LexicalDC;
5248 DeclarationName Name;
5249 SourceLocation Loc;
5250 NamedDecl *ToD;
5251 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5252 return std::move(Err);
5253 if (ToD)
5254 return ToD;
5255
5256 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5257 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5258 for (auto *FoundDecl : FoundDecls) {
5259 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5260 continue;
5261
5262 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5263 break;
5264 }
5265
5266 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5267 if (!ToProto) {
5268 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5269 if (!ToAtBeginLocOrErr)
5270 return ToAtBeginLocOrErr.takeError();
5271
5272 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5273 Name.getAsIdentifierInfo(), Loc,
5274 *ToAtBeginLocOrErr,
5275 /*PrevDecl=*/nullptr))
5276 return ToProto;
5277 ToProto->setLexicalDeclContext(LexicalDC);
5278 LexicalDC->addDeclInternal(ToProto);
5279 }
5280
5281 Importer.MapImported(D, ToProto);
5282
5284 if (Error Err = ImportDefinition(D, ToProto))
5285 return std::move(Err);
5286
5287 return ToProto;
5288}
5289
5291 DeclContext *DC, *LexicalDC;
5292 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5293 return std::move(Err);
5294
5295 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5296 if (!ExternLocOrErr)
5297 return ExternLocOrErr.takeError();
5298
5299 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5300 if (!LangLocOrErr)
5301 return LangLocOrErr.takeError();
5302
5303 bool HasBraces = D->hasBraces();
5304
5305 LinkageSpecDecl *ToLinkageSpec;
5306 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5307 *ExternLocOrErr, *LangLocOrErr,
5308 D->getLanguage(), HasBraces))
5309 return ToLinkageSpec;
5310
5311 if (HasBraces) {
5312 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5313 if (!RBraceLocOrErr)
5314 return RBraceLocOrErr.takeError();
5315 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5316 }
5317
5318 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5319 LexicalDC->addDeclInternal(ToLinkageSpec);
5320
5321 return ToLinkageSpec;
5322}
5323
5325 BaseUsingDecl *ToSI) {
5326 for (UsingShadowDecl *FromShadow : D->shadows()) {
5327 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5328 ToSI->addShadowDecl(*ToShadowOrErr);
5329 else
5330 // FIXME: We return error here but the definition is already created
5331 // and available with lookups. How to fix this?..
5332 return ToShadowOrErr.takeError();
5333 }
5334 return ToSI;
5335}
5336
5338 DeclContext *DC, *LexicalDC;
5339 DeclarationName Name;
5340 SourceLocation Loc;
5341 NamedDecl *ToD = nullptr;
5342 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5343 return std::move(Err);
5344 if (ToD)
5345 return ToD;
5346
5347 Error Err = Error::success();
5348 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5349 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5350 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5351 if (Err)
5352 return std::move(Err);
5353
5354 DeclarationNameInfo NameInfo(Name, ToLoc);
5355 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5356 return std::move(Err);
5357
5358 UsingDecl *ToUsing;
5359 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5360 ToUsingLoc, ToQualifierLoc, NameInfo,
5361 D->hasTypename()))
5362 return ToUsing;
5363
5364 ToUsing->setLexicalDeclContext(LexicalDC);
5365 LexicalDC->addDeclInternal(ToUsing);
5366
5367 if (NamedDecl *FromPattern =
5368 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5369 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5370 Importer.getToContext().setInstantiatedFromUsingDecl(
5371 ToUsing, *ToPatternOrErr);
5372 else
5373 return ToPatternOrErr.takeError();
5374 }
5375
5376 return ImportUsingShadowDecls(D, ToUsing);
5377}
5378
5380 DeclContext *DC, *LexicalDC;
5381 DeclarationName Name;
5382 SourceLocation Loc;
5383 NamedDecl *ToD = nullptr;
5384 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5385 return std::move(Err);
5386 if (ToD)
5387 return ToD;
5388
5389 Error Err = Error::success();
5390 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5391 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5392 auto ToNameLoc = importChecked(Err, D->getLocation());
5393 auto *ToEnumType = importChecked(Err, D->getEnumType());
5394 if (Err)
5395 return std::move(Err);
5396
5397 UsingEnumDecl *ToUsingEnum;
5398 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5399 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5400 return ToUsingEnum;
5401
5402 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5403 LexicalDC->addDeclInternal(ToUsingEnum);
5404
5405 if (UsingEnumDecl *FromPattern =
5406 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5407 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5408 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5409 *ToPatternOrErr);
5410 else
5411 return ToPatternOrErr.takeError();
5412 }
5413
5414 return ImportUsingShadowDecls(D, ToUsingEnum);
5415}
5416
5418 DeclContext *DC, *LexicalDC;
5419 DeclarationName Name;
5420 SourceLocation Loc;
5421 NamedDecl *ToD = nullptr;
5422 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5423 return std::move(Err);
5424 if (ToD)
5425 return ToD;
5426
5427 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5428 if (!ToIntroducerOrErr)
5429 return ToIntroducerOrErr.takeError();
5430
5431 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5432 if (!ToTargetOrErr)
5433 return ToTargetOrErr.takeError();
5434
5435 UsingShadowDecl *ToShadow;
5436 if (auto *FromConstructorUsingShadow =
5437 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5438 Error Err = Error::success();
5440 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5441 if (Err)
5442 return std::move(Err);
5443 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5444 // is really the "NominatedBaseClassShadowDecl" value if it exists
5445 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5446 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5447 // get the correct values.
5448 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5449 ToShadow, D, Importer.getToContext(), DC, Loc,
5450 cast<UsingDecl>(*ToIntroducerOrErr),
5451 Nominated ? Nominated : *ToTargetOrErr,
5452 FromConstructorUsingShadow->constructsVirtualBase()))
5453 return ToShadow;
5454 } else {
5455 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5456 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5457 return ToShadow;
5458 }
5459
5460 ToShadow->setLexicalDeclContext(LexicalDC);
5461 ToShadow->setAccess(D->getAccess());
5462
5463 if (UsingShadowDecl *FromPattern =
5464 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5465 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5466 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5467 ToShadow, *ToPatternOrErr);
5468 else
5469 // FIXME: We return error here but the definition is already created
5470 // and available with lookups. How to fix this?..
5471 return ToPatternOrErr.takeError();
5472 }
5473
5474 LexicalDC->addDeclInternal(ToShadow);
5475
5476 return ToShadow;
5477}
5478
5480 DeclContext *DC, *LexicalDC;
5481 DeclarationName Name;
5482 SourceLocation Loc;
5483 NamedDecl *ToD = nullptr;
5484 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5485 return std::move(Err);
5486 if (ToD)
5487 return ToD;
5488
5489 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5490 if (!ToComAncestorOrErr)
5491 return ToComAncestorOrErr.takeError();
5492
5493 Error Err = Error::success();
5494 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5495 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5496 auto ToNamespaceKeyLocation =
5498 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5499 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5500 if (Err)
5501 return std::move(Err);
5502
5503 UsingDirectiveDecl *ToUsingDir;
5504 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5505 ToUsingLoc,
5506 ToNamespaceKeyLocation,
5507 ToQualifierLoc,
5508 ToIdentLocation,
5509 ToNominatedNamespace, *ToComAncestorOrErr))
5510 return ToUsingDir;
5511
5512 ToUsingDir->setLexicalDeclContext(LexicalDC);
5513 LexicalDC->addDeclInternal(ToUsingDir);
5514
5515 return ToUsingDir;
5516}
5517
5519 DeclContext *DC, *LexicalDC;
5520 DeclarationName Name;
5521 SourceLocation Loc;
5522 NamedDecl *ToD = nullptr;
5523 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5524 return std::move(Err);
5525 if (ToD)
5526 return ToD;
5527
5528 auto ToInstantiatedFromUsingOrErr =
5529 Importer.Import(D->getInstantiatedFromUsingDecl());
5530 if (!ToInstantiatedFromUsingOrErr)
5531 return ToInstantiatedFromUsingOrErr.takeError();
5532 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5533 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5534 return std::move(Err);
5535
5536 UsingPackDecl *ToUsingPack;
5537 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5538 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5539 Expansions))
5540 return ToUsingPack;
5541
5542 addDeclToContexts(D, ToUsingPack);
5543
5544 return ToUsingPack;
5545}
5546
5549 DeclContext *DC, *LexicalDC;
5550 DeclarationName Name;
5551 SourceLocation Loc;
5552 NamedDecl *ToD = nullptr;
5553 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5554 return std::move(Err);
5555 if (ToD)
5556 return ToD;
5557
5558 Error Err = Error::success();
5559 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5560 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5561 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5562 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5563 if (Err)
5564 return std::move(Err);
5565
5566 DeclarationNameInfo NameInfo(Name, ToLoc);
5567 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5568 return std::move(Err);
5569
5570 UnresolvedUsingValueDecl *ToUsingValue;
5571 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5572 ToUsingLoc, ToQualifierLoc, NameInfo,
5573 ToEllipsisLoc))
5574 return ToUsingValue;
5575
5576 ToUsingValue->setAccess(D->getAccess());
5577 ToUsingValue->setLexicalDeclContext(LexicalDC);
5578 LexicalDC->addDeclInternal(ToUsingValue);
5579
5580 return ToUsingValue;
5581}
5582
5585 DeclContext *DC, *LexicalDC;
5586 DeclarationName Name;
5587 SourceLocation Loc;
5588 NamedDecl *ToD = nullptr;
5589 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5590 return std::move(Err);
5591 if (ToD)
5592 return ToD;
5593
5594 Error Err = Error::success();
5595 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5596 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5597 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5598 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5599 if (Err)
5600 return std::move(Err);
5601
5603 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5604 ToUsingLoc, ToTypenameLoc,
5605 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5606 return ToUsing;
5607
5608 ToUsing->setAccess(D->getAccess());
5609 ToUsing->setLexicalDeclContext(LexicalDC);
5610 LexicalDC->addDeclInternal(ToUsing);
5611
5612 return ToUsing;
5613}
5614
5616 Decl* ToD = nullptr;
5617 switch (D->getBuiltinTemplateKind()) {
5618#define BuiltinTemplate(BTName) \
5619 case BuiltinTemplateKind::BTK##BTName: \
5620 ToD = Importer.getToContext().get##BTName##Decl(); \
5621 break;
5622#include "clang/Basic/BuiltinTemplates.inc"
5623 }
5624 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5625 Importer.MapImported(D, ToD);
5626 return ToD;
5627}
5628
5631 if (To->getDefinition()) {
5632 // Check consistency of superclass.
5633 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5634 if (FromSuper) {
5635 if (auto FromSuperOrErr = import(FromSuper))
5636 FromSuper = *FromSuperOrErr;
5637 else
5638 return FromSuperOrErr.takeError();
5639 }
5640
5641 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5642 if ((bool)FromSuper != (bool)ToSuper ||
5643 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5644 Importer.ToDiag(To->getLocation(),
5645 diag::warn_odr_objc_superclass_inconsistent)
5646 << To->getDeclName();
5647 if (ToSuper)
5648 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5649 << To->getSuperClass()->getDeclName();
5650 else
5651 Importer.ToDiag(To->getLocation(),
5652 diag::note_odr_objc_missing_superclass);
5653 if (From->getSuperClass())
5654 Importer.FromDiag(From->getSuperClassLoc(),
5655 diag::note_odr_objc_superclass)
5656 << From->getSuperClass()->getDeclName();
5657 else
5658 Importer.FromDiag(From->getLocation(),
5659 diag::note_odr_objc_missing_superclass);
5660 }
5661
5663 if (Error Err = ImportDeclContext(From))
5664 return Err;
5665 return Error::success();
5666 }
5667
5668 // Start the definition.
5669 To->startDefinition();
5670
5671 // If this class has a superclass, import it.
5672 if (From->getSuperClass()) {
5673 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5674 To->setSuperClass(*SuperTInfoOrErr);
5675 else
5676 return SuperTInfoOrErr.takeError();
5677 }
5678
5679 // Import protocols
5681 SmallVector<SourceLocation, 4> ProtocolLocs;
5683 From->protocol_loc_begin();
5684
5686 FromProtoEnd = From->protocol_end();
5687 FromProto != FromProtoEnd;
5688 ++FromProto, ++FromProtoLoc) {
5689 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5690 Protocols.push_back(*ToProtoOrErr);
5691 else
5692 return ToProtoOrErr.takeError();
5693
5694 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5695 ProtocolLocs.push_back(*ToProtoLocOrErr);
5696 else
5697 return ToProtoLocOrErr.takeError();
5698
5699 }
5700
5701 // FIXME: If we're merging, make sure that the protocol list is the same.
5702 To->setProtocolList(Protocols.data(), Protocols.size(),
5703 ProtocolLocs.data(), Importer.getToContext());
5704
5705 // Import categories. When the categories themselves are imported, they'll
5706 // hook themselves into this interface.
5707 for (auto *Cat : From->known_categories()) {
5708 auto ToCatOrErr = import(Cat);
5709 if (!ToCatOrErr)
5710 return ToCatOrErr.takeError();
5711 }
5712
5713 // If we have an @implementation, import it as well.
5714 if (From->getImplementation()) {
5715 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5716 import(From->getImplementation()))
5717 To->setImplementation(*ToImplOrErr);
5718 else
5719 return ToImplOrErr.takeError();
5720 }
5721
5722 // Import all of the members of this class.
5723 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5724 return Err;
5725
5726 return Error::success();
5727}
5728
5731 if (!list)
5732 return nullptr;
5733
5735 for (auto *fromTypeParam : *list) {
5736 if (auto toTypeParamOrErr = import(fromTypeParam))
5737 toTypeParams.push_back(*toTypeParamOrErr);
5738 else
5739 return toTypeParamOrErr.takeError();
5740 }
5741
5742 auto LAngleLocOrErr = import(list->getLAngleLoc());
5743 if (!LAngleLocOrErr)
5744 return LAngleLocOrErr.takeError();
5745
5746 auto RAngleLocOrErr = import(list->getRAngleLoc());
5747 if (!RAngleLocOrErr)
5748 return RAngleLocOrErr.takeError();
5749
5750 return ObjCTypeParamList::create(Importer.getToContext(),
5751 *LAngleLocOrErr,
5752 toTypeParams,
5753 *RAngleLocOrErr);
5754}
5755
5757 // If this class has a definition in the translation unit we're coming from,
5758 // but this particular declaration is not that definition, import the
5759 // definition and map to that.
5761 if (Definition && Definition != D) {
5762 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5763 return Importer.MapImported(D, *ImportedDefOrErr);
5764 else
5765 return ImportedDefOrErr.takeError();
5766 }
5767
5768 // Import the major distinguishing characteristics of an @interface.
5769 DeclContext *DC, *LexicalDC;
5770 DeclarationName Name;
5771 SourceLocation Loc;
5772 NamedDecl *ToD;
5773 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5774 return std::move(Err);
5775 if (ToD)
5776 return ToD;
5777
5778 // Look for an existing interface with the same name.
5779 ObjCInterfaceDecl *MergeWithIface = nullptr;
5780 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5781 for (auto *FoundDecl : FoundDecls) {
5782 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5783 continue;
5784
5785 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5786 break;
5787 }
5788
5789 // Create an interface declaration, if one does not already exist.
5790 ObjCInterfaceDecl *ToIface = MergeWithIface;
5791 if (!ToIface) {
5792 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5793 if (!AtBeginLocOrErr)
5794 return AtBeginLocOrErr.takeError();
5795
5796 if (GetImportedOrCreateDecl(
5797 ToIface, D, Importer.getToContext(), DC,
5798 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5799 /*TypeParamList=*/nullptr,
5800 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5801 return ToIface;
5802 ToIface->setLexicalDeclContext(LexicalDC);
5803 LexicalDC->addDeclInternal(ToIface);
5804 }
5805 Importer.MapImported(D, ToIface);
5806 // Import the type parameter list after MapImported, to avoid
5807 // loops when bringing in their DeclContext.
5808 if (auto ToPListOrErr =
5810 ToIface->setTypeParamList(*ToPListOrErr);
5811 else
5812 return ToPListOrErr.takeError();
5813
5815 if (Error Err = ImportDefinition(D, ToIface))
5816 return std::move(Err);
5817
5818 return ToIface;
5819}
5820
5823 ObjCCategoryDecl *Category;
5824 if (Error Err = importInto(Category, D->getCategoryDecl()))
5825 return std::move(Err);
5826
5827 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5828 if (!ToImpl) {
5829 DeclContext *DC, *LexicalDC;
5830 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5831 return std::move(Err);
5832
5833 Error Err = Error::success();
5834 auto ToLocation = importChecked(Err, D->getLocation());
5835 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5836 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5837 if (Err)
5838 return std::move(Err);
5839
5840 if (GetImportedOrCreateDecl(
5841 ToImpl, D, Importer.getToContext(), DC,
5842 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5843 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5844 return ToImpl;
5845
5846 ToImpl->setLexicalDeclContext(LexicalDC);
5847 LexicalDC->addDeclInternal(ToImpl);
5848 Category->setImplementation(ToImpl);
5849 }
5850
5851 Importer.MapImported(D, ToImpl);
5852 if (Error Err = ImportDeclContext(D))
5853 return std::move(Err);
5854
5855 return ToImpl;
5856}
5857
5860 // Find the corresponding interface.
5861 ObjCInterfaceDecl *Iface;
5862 if (Error Err = importInto(Iface, D->getClassInterface()))
5863 return std::move(Err);
5864
5865 // Import the superclass, if any.
5866 ObjCInterfaceDecl *Super;
5867 if (Error Err = importInto(Super, D->getSuperClass()))
5868 return std::move(Err);
5869
5871 if (!Impl) {
5872 // We haven't imported an implementation yet. Create a new @implementation
5873 // now.
5874 DeclContext *DC, *LexicalDC;
5875 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5876 return std::move(Err);
5877
5878 Error Err = Error::success();
5879 auto ToLocation = importChecked(Err, D->getLocation());
5880 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5881 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5882 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5883 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5884 if (Err)
5885 return std::move(Err);
5886
5887 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5888 DC, Iface, Super,
5889 ToLocation,
5890 ToAtStartLoc,
5891 ToSuperClassLoc,
5892 ToIvarLBraceLoc,
5893 ToIvarRBraceLoc))
5894 return Impl;
5895
5896 Impl->setLexicalDeclContext(LexicalDC);
5897
5898 // Associate the implementation with the class it implements.
5899 Iface->setImplementation(Impl);
5900 Importer.MapImported(D, Iface->getImplementation());
5901 } else {
5902 Importer.MapImported(D, Iface->getImplementation());
5903
5904 // Verify that the existing @implementation has the same superclass.
5905 if ((Super && !Impl->getSuperClass()) ||
5906 (!Super && Impl->getSuperClass()) ||
5907 (Super && Impl->getSuperClass() &&
5909 Impl->getSuperClass()))) {
5910 Importer.ToDiag(Impl->getLocation(),
5911 diag::warn_odr_objc_superclass_inconsistent)
5912 << Iface->getDeclName();
5913 // FIXME: It would be nice to have the location of the superclass
5914 // below.
5915 if (Impl->getSuperClass())
5916 Importer.ToDiag(Impl->getLocation(),
5917 diag::note_odr_objc_superclass)
5918 << Impl->getSuperClass()->getDeclName();
5919 else
5920 Importer.ToDiag(Impl->getLocation(),
5921 diag::note_odr_objc_missing_superclass);
5922 if (D->getSuperClass())
5923 Importer.FromDiag(D->getLocation(),
5924 diag::note_odr_objc_superclass)
5925 << D->getSuperClass()->getDeclName();
5926 else
5927 Importer.FromDiag(D->getLocation(),
5928 diag::note_odr_objc_missing_superclass);
5929
5930 return make_error<ASTImportError>(ASTImportError::NameConflict);
5931 }
5932 }
5933
5934 // Import all of the members of this @implementation.
5935 if (Error Err = ImportDeclContext(D))
5936 return std::move(Err);
5937
5938 return Impl;
5939}
5940
5942 // Import the major distinguishing characteristics of an @property.
5943 DeclContext *DC, *LexicalDC;
5944 DeclarationName Name;
5945 SourceLocation Loc;
5946 NamedDecl *ToD;
5947 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5948 return std::move(Err);
5949 if (ToD)
5950 return ToD;
5951
5952 // Check whether we have already imported this property.
5953 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5954 for (auto *FoundDecl : FoundDecls) {
5955 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5956 // Instance and class properties can share the same name but are different
5957 // declarations.
5958 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5959 continue;
5960
5961 // Check property types.
5962 if (!Importer.IsStructurallyEquivalent(D->getType(),
5963 FoundProp->getType())) {
5964 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5965 << Name << D->getType() << FoundProp->getType();
5966 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5967 << FoundProp->getType();
5968
5969 return make_error<ASTImportError>(ASTImportError::NameConflict);
5970 }
5971
5972 // FIXME: Check property attributes, getters, setters, etc.?
5973
5974 // Consider these properties to be equivalent.
5975 Importer.MapImported(D, FoundProp);
5976 return FoundProp;
5977 }
5978 }
5979
5980 Error Err = Error::success();
5981 auto ToType = importChecked(Err, D->getType());
5982 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5983 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5984 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5985 if (Err)
5986 return std::move(Err);
5987
5988 // Create the new property.
5989 ObjCPropertyDecl *ToProperty;
5990 if (GetImportedOrCreateDecl(
5991 ToProperty, D, Importer.getToContext(), DC, Loc,
5992 Name.getAsIdentifierInfo(), ToAtLoc,
5993 ToLParenLoc, ToType,
5994 ToTypeSourceInfo, D->getPropertyImplementation()))
5995 return ToProperty;
5996
5997 auto ToGetterName = importChecked(Err, D->getGetterName());
5998 auto ToSetterName = importChecked(Err, D->getSetterName());
5999 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6000 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6001 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6002 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6003 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6004 if (Err)
6005 return std::move(Err);
6006
6007 ToProperty->setLexicalDeclContext(LexicalDC);
6008 LexicalDC->addDeclInternal(ToProperty);
6009
6013 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6014 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6015 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6016 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6017 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6018 return ToProperty;
6019}
6020
6024 if (Error Err = importInto(Property, D->getPropertyDecl()))
6025 return std::move(Err);
6026
6027 DeclContext *DC, *LexicalDC;
6028 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6029 return std::move(Err);
6030
6031 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6032
6033 // Import the ivar (for an @synthesize).
6034 ObjCIvarDecl *Ivar = nullptr;
6035 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6036 return std::move(Err);
6037
6038 ObjCPropertyImplDecl *ToImpl
6039 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6040 Property->getQueryKind());
6041 if (!ToImpl) {
6042
6043 Error Err = Error::success();
6044 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6045 auto ToLocation = importChecked(Err, D->getLocation());
6046 auto ToPropertyIvarDeclLoc =
6048 if (Err)
6049 return std::move(Err);
6050
6051 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6052 ToBeginLoc,
6053 ToLocation, Property,
6054 D->getPropertyImplementation(), Ivar,
6055 ToPropertyIvarDeclLoc))
6056 return ToImpl;
6057
6058 ToImpl->setLexicalDeclContext(LexicalDC);
6059 LexicalDC->addDeclInternal(ToImpl);
6060 } else {
6061 // Check that we have the same kind of property implementation (@synthesize
6062 // vs. @dynamic).
6064 Importer.ToDiag(ToImpl->getLocation(),
6065 diag::warn_odr_objc_property_impl_kind_inconsistent)
6066 << Property->getDeclName()
6067 << (ToImpl->getPropertyImplementation()
6069 Importer.FromDiag(D->getLocation(),
6070 diag::note_odr_objc_property_impl_kind)
6071 << D->getPropertyDecl()->getDeclName()
6073
6074 return make_error<ASTImportError>(ASTImportError::NameConflict);
6075 }
6076
6077 // For @synthesize, check that we have the same
6079 Ivar != ToImpl->getPropertyIvarDecl()) {
6080 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6081 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6082 << Property->getDeclName()
6083 << ToImpl->getPropertyIvarDecl()->getDeclName()
6084 << Ivar->getDeclName();
6085 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6086 diag::note_odr_objc_synthesize_ivar_here)
6088
6089 return make_error<ASTImportError>(ASTImportError::NameConflict);
6090 }
6091
6092 // Merge the existing implementation with the new implementation.
6093 Importer.MapImported(D, ToImpl);
6094 }
6095
6096 return ToImpl;
6097}
6098
6101 // For template arguments, we adopt the translation unit as our declaration
6102 // context. This context will be fixed when (during) the actual template
6103 // declaration is created.
6104
6105 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6106 if (!BeginLocOrErr)
6107 return BeginLocOrErr.takeError();
6108
6109 ExpectedSLoc LocationOrErr = import(D->getLocation());
6110 if (!LocationOrErr)
6111 return LocationOrErr.takeError();
6112
6113 TemplateTypeParmDecl *ToD = nullptr;
6114 if (GetImportedOrCreateDecl(
6115 ToD, D, Importer.getToContext(),
6116 Importer.getToContext().getTranslationUnitDecl(),
6117 *BeginLocOrErr, *LocationOrErr,
6118 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6120 D->hasTypeConstraint()))
6121 return ToD;
6122
6123 // Import the type-constraint
6124 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6125
6126 Error Err = Error::success();
6127 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6128 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6129 if (Err)
6130 return std::move(Err);
6131
6132 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6133 }
6134
6135 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6136 return Err;
6137
6138 return ToD;
6139}
6140
6143
6144 Error Err = Error::success();
6145 auto ToDeclName = importChecked(Err, D->getDeclName());
6146 auto ToLocation = importChecked(Err, D->getLocation());
6147 auto ToType = importChecked(Err, D->getType());
6148 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6149 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6150 if (Err)
6151 return std::move(Err);
6152
6153 NonTypeTemplateParmDecl *ToD = nullptr;
6154 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6155 Importer.getToContext().getTranslationUnitDecl(),
6156 ToInnerLocStart, ToLocation, D->getDepth(),
6157 D->getPosition(),
6158 ToDeclName.getAsIdentifierInfo(), ToType,
6159 D->isParameterPack(), ToTypeSourceInfo))
6160 return ToD;
6161
6162 Err = importTemplateParameterDefaultArgument(D, ToD);
6163 if (Err)
6164 return Err;
6165
6166 return ToD;
6167}
6168
6171 bool IsCanonical = false;
6172 if (auto *CanonD = Importer.getFromContext()
6173 .findCanonicalTemplateTemplateParmDeclInternal(D);
6174 CanonD == D)
6175 IsCanonical = true;
6176
6177 // Import the name of this declaration.
6178 auto NameOrErr = import(D->getDeclName());
6179 if (!NameOrErr)
6180 return NameOrErr.takeError();
6181
6182 // Import the location of this declaration.
6183 ExpectedSLoc LocationOrErr = import(D->getLocation());
6184 if (!LocationOrErr)
6185 return LocationOrErr.takeError();
6186
6187 // Import template parameters.
6188 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6189 if (!TemplateParamsOrErr)
6190 return TemplateParamsOrErr.takeError();
6191
6192 TemplateTemplateParmDecl *ToD = nullptr;
6193 if (GetImportedOrCreateDecl(
6194 ToD, D, Importer.getToContext(),
6195 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6196 D->getDepth(), D->getPosition(), D->isParameterPack(),
6197 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6198 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6199 return ToD;
6200
6201 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6202 return Err;
6203
6204 if (IsCanonical)
6205 return Importer.getToContext()
6206 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6207
6208 return ToD;
6209}
6210
6211// Returns the definition for a (forward) declaration of a TemplateDecl, if
6212// it has any definition in the redecl chain.
6213template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6214 assert(D->getTemplatedDecl() && "Should be called on templates only");
6215 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6216 if (!ToTemplatedDef)
6217 return nullptr;
6218 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6219 return cast_or_null<T>(TemplateWithDef);
6220}
6221
6223
6224 // Import the major distinguishing characteristics of this class template.
6225 DeclContext *DC, *LexicalDC;
6226 DeclarationName Name;
6227 SourceLocation Loc;
6228 NamedDecl *ToD;
6229 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6230 return std::move(Err);
6231 if (ToD)
6232 return ToD;
6233
6234 // Should check if a declaration is friend in a dependent context.
6235 // Such templates are not linked together in a declaration chain.
6236 // The ASTImporter strategy is to map existing forward declarations to
6237 // imported ones only if strictly necessary, otherwise import these as new
6238 // forward declarations. In case of the "dependent friend" declarations, new
6239 // declarations are created, but not linked in a declaration chain.
6240 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6241 return TD->getFriendObjectKind() != Decl::FOK_None &&
6242 TD->getLexicalDeclContext()->isDependentContext();
6243 };
6244 bool DependentFriend = IsDependentFriend(D);
6245
6246 ClassTemplateDecl *FoundByLookup = nullptr;
6247
6248 // We may already have a template of the same name; try to find and match it.
6249 if (!DC->isFunctionOrMethod()) {
6250 SmallVector<NamedDecl *, 4> ConflictingDecls;
6251 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6252 for (auto *FoundDecl : FoundDecls) {
6253 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6255 continue;
6256
6257 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6258 if (FoundTemplate) {
6259 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6260 continue;
6261
6262 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6263 bool IgnoreTemplateParmDepth =
6264 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6266 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6267 IgnoreTemplateParmDepth)) {
6268 if (DependentFriend || IsDependentFriend(FoundTemplate))
6269 continue;
6270
6271 ClassTemplateDecl *TemplateWithDef =
6272 getTemplateDefinition(FoundTemplate);
6273 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6274 return Importer.MapImported(D, TemplateWithDef);
6275 if (!FoundByLookup)
6276 FoundByLookup = FoundTemplate;
6277 // Search in all matches because there may be multiple decl chains,
6278 // see ASTTests test ImportExistingFriendClassTemplateDef.
6279 continue;
6280 }
6281 // When importing a friend, it is possible that multiple declarations
6282 // with same name can co-exist in specific cases (if a template contains
6283 // a friend template and has a specialization). For this case the
6284 // declarations should match, except that the "template depth" is
6285 // different. No linking of previous declaration is needed in this case.
6286 // FIXME: This condition may need refinement.
6287 if (D->getFriendObjectKind() != Decl::FOK_None &&
6288 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6289 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6290 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6291 /*IgnoreTemplateParmDepth=*/true))
6292 continue;
6293
6294 ConflictingDecls.push_back(FoundDecl);
6295 }
6296 }
6297
6298 if (!ConflictingDecls.empty()) {
6299 ExpectedName NameOrErr = Importer.HandleNameConflict(
6300 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6301 ConflictingDecls.size());
6302 if (NameOrErr)
6303 Name = NameOrErr.get();
6304 else
6305 return NameOrErr.takeError();
6306 }
6307 }
6308
6309 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6310
6311 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6312 if (!TemplateParamsOrErr)
6313 return TemplateParamsOrErr.takeError();
6314
6315 // Create the declaration that is being templated.
6316 CXXRecordDecl *ToTemplated;
6317 if (Error Err = importInto(ToTemplated, FromTemplated))
6318 return std::move(Err);
6319
6320 // Create the class template declaration itself.
6322 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6323 *TemplateParamsOrErr, ToTemplated))
6324 return D2;
6325
6326 ToTemplated->setDescribedClassTemplate(D2);
6327
6328 D2->setAccess(D->getAccess());
6329 D2->setLexicalDeclContext(LexicalDC);
6330
6331 addDeclToContexts(D, D2);
6332 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6333
6334 if (FoundByLookup) {
6335 auto *Recent =
6336 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6337
6338 // It is possible that during the import of the class template definition
6339 // we start the import of a fwd friend decl of the very same class template
6340 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6341 // had been created earlier and by that time the lookup could not find
6342 // anything existing, so it has no previous decl. Later, (still during the
6343 // import of the fwd friend decl) we start to import the definition again
6344 // and this time the lookup finds the previous fwd friend class template.
6345 // In this case we must set up the previous decl for the templated decl.
6346 if (!ToTemplated->getPreviousDecl()) {
6347 assert(FoundByLookup->getTemplatedDecl() &&
6348 "Found decl must have its templated decl set");
6349 CXXRecordDecl *PrevTemplated =
6350 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6351 if (ToTemplated != PrevTemplated)
6352 ToTemplated->setPreviousDecl(PrevTemplated);
6353 }
6354
6355 D2->setPreviousDecl(Recent);
6356 }
6357
6358 return D2;
6359}
6360
6363 ClassTemplateDecl *ClassTemplate;
6364 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6365 return std::move(Err);
6366
6367 // Import the context of this declaration.
6368 DeclContext *DC, *LexicalDC;
6369 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6370 return std::move(Err);
6371
6372 // Import template arguments.
6374 if (Error Err =
6375 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6376 return std::move(Err);
6377 // Try to find an existing specialization with these template arguments and
6378 // template parameter list.
6379 void *InsertPos = nullptr;
6380 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6382 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6383
6384 // Import template parameters.
6385 TemplateParameterList *ToTPList = nullptr;
6386
6387 if (PartialSpec) {
6388 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6389 if (!ToTPListOrErr)
6390 return ToTPListOrErr.takeError();
6391 ToTPList = *ToTPListOrErr;
6392 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6393 *ToTPListOrErr,
6394 InsertPos);
6395 } else
6396 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6397
6398 if (PrevDecl) {
6399 if (IsStructuralMatch(D, PrevDecl)) {
6400 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6401 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6402 Importer.MapImported(D, PrevDefinition);
6403 // Import those default field initializers which have been
6404 // instantiated in the "From" context, but not in the "To" context.
6405 for (auto *FromField : D->fields()) {
6406 auto ToOrErr = import(FromField);
6407 if (!ToOrErr)
6408 return ToOrErr.takeError();
6409 }
6410
6411 // Import those methods which have been instantiated in the
6412 // "From" context, but not in the "To" context.
6413 for (CXXMethodDecl *FromM : D->methods()) {
6414 auto ToOrErr = import(FromM);
6415 if (!ToOrErr)
6416 return ToOrErr.takeError();
6417 }
6418
6419 // TODO Import instantiated default arguments.
6420 // TODO Import instantiated exception specifications.
6421 //
6422 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6423 // what else could be fused during an AST merge.
6424 return PrevDefinition;
6425 }
6426 } else { // ODR violation.
6427 // FIXME HandleNameConflict
6428 return make_error<ASTImportError>(ASTImportError::NameConflict);
6429 }
6430 }
6431
6432 // Import the location of this declaration.
6433 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6434 if (!BeginLocOrErr)
6435 return BeginLocOrErr.takeError();
6436 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6437 if (!IdLocOrErr)
6438 return IdLocOrErr.takeError();
6439
6440 // Import TemplateArgumentListInfo.
6441 TemplateArgumentListInfo ToTAInfo;
6442 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6443 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6444 return std::move(Err);
6445 }
6446
6447 // Create the specialization.
6448 ClassTemplateSpecializationDecl *D2 = nullptr;
6449 if (PartialSpec) {
6450 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6451 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6452 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6453 /*CanonInjectedTST=*/CanQualType(),
6454 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6455 return D2;
6456
6457 // Update InsertPos, because preceding import calls may have invalidated
6458 // it by adding new specializations.
6460 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6461 InsertPos))
6462 // Add this partial specialization to the class template.
6463 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6465 import(PartialSpec->getInstantiatedFromMember()))
6466 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6467 else
6468 return ToInstOrErr.takeError();
6469
6470 updateLookupTableForTemplateParameters(*ToTPList);
6471 } else { // Not a partial specialization.
6472 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6473 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6474 TemplateArgs, D->hasStrictPackMatch(),
6475 PrevDecl))
6476 return D2;
6477
6478 // Update InsertPos, because preceding import calls may have invalidated
6479 // it by adding new specializations.
6480 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6481 // Add this specialization to the class template.
6482 ClassTemplate->AddSpecialization(D2, InsertPos);
6483 }
6484
6486
6487 // Set the context of this specialization/instantiation.
6488 D2->setLexicalDeclContext(LexicalDC);
6489
6490 // Add to the DC only if it was an explicit specialization/instantiation.
6492 LexicalDC->addDeclInternal(D2);
6493 }
6494
6495 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6496 D2->setBraceRange(*BraceRangeOrErr);
6497 else
6498 return BraceRangeOrErr.takeError();
6499
6500 if (Error Err = ImportTemplateParameterLists(D, D2))
6501 return std::move(Err);
6502
6503 // Import the qualifier, if any.
6504 if (auto LocOrErr = import(D->getQualifierLoc()))
6505 D2->setQualifierInfo(*LocOrErr);
6506 else
6507 return LocOrErr.takeError();
6508
6509 if (D->getTemplateArgsAsWritten())
6510 D2->setTemplateArgsAsWritten(ToTAInfo);
6511
6512 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6513 D2->setTemplateKeywordLoc(*LocOrErr);
6514 else
6515 return LocOrErr.takeError();
6516
6517 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6518 D2->setExternKeywordLoc(*LocOrErr);
6519 else
6520 return LocOrErr.takeError();
6521
6522 if (D->getPointOfInstantiation().isValid()) {
6523 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6524 D2->setPointOfInstantiation(*POIOrErr);
6525 else
6526 return POIOrErr.takeError();
6527 }
6528
6530
6531 if (auto P = D->getInstantiatedFrom()) {
6532 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6533 if (auto CTDorErr = import(CTD))
6534 D2->setInstantiationOf(*CTDorErr);
6535 } else {
6537 auto CTPSDOrErr = import(CTPSD);
6538 if (!CTPSDOrErr)
6539 return CTPSDOrErr.takeError();
6541 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6542 for (unsigned I = 0; I < DArgs.size(); ++I) {
6543 const TemplateArgument &DArg = DArgs[I];
6544 if (auto ArgOrErr = import(DArg))
6545 D2ArgsVec[I] = *ArgOrErr;
6546 else
6547 return ArgOrErr.takeError();
6548 }
6550 *CTPSDOrErr,
6551 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6552 }
6553 }
6554
6555 if (D->isCompleteDefinition())
6556 if (Error Err = ImportDefinition(D, D2))
6557 return std::move(Err);
6558
6559 return D2;
6560}
6561
6563 // Import the major distinguishing characteristics of this variable template.
6564 DeclContext *DC, *LexicalDC;
6565 DeclarationName Name;
6566 SourceLocation Loc;
6567 NamedDecl *ToD;
6568 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6569 return std::move(Err);
6570 if (ToD)
6571 return ToD;
6572
6573 // We may already have a template of the same name; try to find and match it.
6574 assert(!DC->isFunctionOrMethod() &&
6575 "Variable templates cannot be declared at function scope");
6576
6577 SmallVector<NamedDecl *, 4> ConflictingDecls;
6578 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6579 VarTemplateDecl *FoundByLookup = nullptr;
6580 for (auto *FoundDecl : FoundDecls) {
6581 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6582 continue;
6583
6584 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6585 // Use the templated decl, some linkage flags are set only there.
6586 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6587 D->getTemplatedDecl()))
6588 continue;
6589 if (IsStructuralMatch(D, FoundTemplate)) {
6590 // FIXME Check for ODR error if the two definitions have
6591 // different initializers?
6592 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6593 if (D->getDeclContext()->isRecord()) {
6594 assert(FoundTemplate->getDeclContext()->isRecord() &&
6595 "Member variable template imported as non-member, "
6596 "inconsistent imported AST?");
6597 if (FoundDef)
6598 return Importer.MapImported(D, FoundDef);
6600 return Importer.MapImported(D, FoundTemplate);
6601 } else {
6602 if (FoundDef && D->isThisDeclarationADefinition())
6603 return Importer.MapImported(D, FoundDef);
6604 }
6605 FoundByLookup = FoundTemplate;
6606 break;
6607 }
6608 ConflictingDecls.push_back(FoundDecl);
6609 }
6610 }
6611
6612 if (!ConflictingDecls.empty()) {
6613 ExpectedName NameOrErr = Importer.HandleNameConflict(
6614 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6615 ConflictingDecls.size());
6616 if (NameOrErr)
6617 Name = NameOrErr.get();
6618 else
6619 return NameOrErr.takeError();
6620 }
6621
6622 VarDecl *DTemplated = D->getTemplatedDecl();
6623
6624 // Import the type.
6625 // FIXME: Value not used?
6626 ExpectedType TypeOrErr = import(DTemplated->getType());
6627 if (!TypeOrErr)
6628 return TypeOrErr.takeError();
6629
6630 // Create the declaration that is being templated.
6631 VarDecl *ToTemplated;
6632 if (Error Err = importInto(ToTemplated, DTemplated))
6633 return std::move(Err);
6634
6635 // Create the variable template declaration itself.
6636 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6637 if (!TemplateParamsOrErr)
6638 return TemplateParamsOrErr.takeError();
6639
6640 VarTemplateDecl *ToVarTD;
6641 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6642 Name, *TemplateParamsOrErr, ToTemplated))
6643 return ToVarTD;
6644
6645 ToTemplated->setDescribedVarTemplate(ToVarTD);
6646
6647 ToVarTD->setAccess(D->getAccess());
6648 ToVarTD->setLexicalDeclContext(LexicalDC);
6649 LexicalDC->addDeclInternal(ToVarTD);
6650 if (DC != Importer.getToContext().getTranslationUnitDecl())
6651 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6652
6653 if (FoundByLookup) {
6654 auto *Recent =
6655 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6656 if (!ToTemplated->getPreviousDecl()) {
6657 auto *PrevTemplated =
6658 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6659 if (ToTemplated != PrevTemplated)
6660 ToTemplated->setPreviousDecl(PrevTemplated);
6661 }
6662 ToVarTD->setPreviousDecl(Recent);
6663 }
6664
6665 return ToVarTD;
6666}
6667
6670 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6671 // in an analog way (but specialized for this case).
6672
6674 auto RedeclIt = Redecls.begin();
6675 // Import the first part of the decl chain. I.e. import all previous
6676 // declarations starting from the canonical decl.
6677 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6678 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6679 if (!RedeclOrErr)
6680 return RedeclOrErr.takeError();
6681 }
6682 assert(*RedeclIt == D);
6683
6684 VarTemplateDecl *VarTemplate = nullptr;
6685 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6686 return std::move(Err);
6687
6688 // Import the context of this declaration.
6689 DeclContext *DC, *LexicalDC;
6690 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6691 return std::move(Err);
6692
6693 // Import the location of this declaration.
6694 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6695 if (!BeginLocOrErr)
6696 return BeginLocOrErr.takeError();
6697
6698 auto IdLocOrErr = import(D->getLocation());
6699 if (!IdLocOrErr)
6700 return IdLocOrErr.takeError();
6701
6702 // Import template arguments.
6704 if (Error Err =
6705 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6706 return std::move(Err);
6707
6708 // Try to find an existing specialization with these template arguments.
6709 void *InsertPos = nullptr;
6710 VarTemplateSpecializationDecl *FoundSpecialization =
6711 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6712 if (FoundSpecialization) {
6713 if (IsStructuralMatch(D, FoundSpecialization)) {
6714 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6715 if (D->getDeclContext()->isRecord()) {
6716 // In a record, it is allowed only to have one optional declaration and
6717 // one definition of the (static or constexpr) variable template.
6718 assert(
6719 FoundSpecialization->getDeclContext()->isRecord() &&
6720 "Member variable template specialization imported as non-member, "
6721 "inconsistent imported AST?");
6722 if (FoundDef)
6723 return Importer.MapImported(D, FoundDef);
6725 return Importer.MapImported(D, FoundSpecialization);
6726 } else {
6727 // If definition is imported and there is already one, map to it.
6728 // Otherwise create a new variable and link it to the existing.
6729 if (FoundDef && D->isThisDeclarationADefinition())
6730 return Importer.MapImported(D, FoundDef);
6731 }
6732 } else {
6733 return make_error<ASTImportError>(ASTImportError::NameConflict);
6734 }
6735 }
6736
6737 VarTemplateSpecializationDecl *D2 = nullptr;
6738
6739 TemplateArgumentListInfo ToTAInfo;
6740 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6741 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6742 return std::move(Err);
6743 }
6744
6745 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6746 // Create a new specialization.
6747 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6748 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6749 if (!ToTPListOrErr)
6750 return ToTPListOrErr.takeError();
6751
6752 PartVarSpecDecl *ToPartial;
6753 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6754 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6755 VarTemplate, QualType(), nullptr,
6756 D->getStorageClass(), TemplateArgs))
6757 return ToPartial;
6758
6759 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6760 import(FromPartial->getInstantiatedFromMember()))
6761 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6762 else
6763 return ToInstOrErr.takeError();
6764
6765 if (FromPartial->isMemberSpecialization())
6766 ToPartial->setMemberSpecialization();
6767
6768 D2 = ToPartial;
6769
6770 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6771 // to adopt template parameters.
6772 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6773 } else { // Full specialization
6774 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6775 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6776 QualType(), nullptr, D->getStorageClass(),
6777 TemplateArgs))
6778 return D2;
6779 }
6780
6781 // Update InsertPos, because preceding import calls may have invalidated
6782 // it by adding new specializations.
6783 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6784 VarTemplate->AddSpecialization(D2, InsertPos);
6785
6786 QualType T;
6787 if (Error Err = importInto(T, D->getType()))
6788 return std::move(Err);
6789 D2->setType(T);
6790
6791 auto TInfoOrErr = import(D->getTypeSourceInfo());
6792 if (!TInfoOrErr)
6793 return TInfoOrErr.takeError();
6794 D2->setTypeSourceInfo(*TInfoOrErr);
6795
6796 if (D->getPointOfInstantiation().isValid()) {
6797 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6798 D2->setPointOfInstantiation(*POIOrErr);
6799 else
6800 return POIOrErr.takeError();
6801 }
6802
6804
6805 if (D->getTemplateArgsAsWritten())
6806 D2->setTemplateArgsAsWritten(ToTAInfo);
6807
6808 if (auto LocOrErr = import(D->getQualifierLoc()))
6809 D2->setQualifierInfo(*LocOrErr);
6810 else
6811 return LocOrErr.takeError();
6812
6813 if (D->isConstexpr())
6814 D2->setConstexpr(true);
6815
6816 D2->setAccess(D->getAccess());
6817
6818 if (Error Err = ImportInitializer(D, D2))
6819 return std::move(Err);
6820
6821 if (FoundSpecialization)
6822 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6823
6824 addDeclToContexts(D, D2);
6825
6826 // Import the rest of the chain. I.e. import all subsequent declarations.
6827 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6828 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6829 if (!RedeclOrErr)
6830 return RedeclOrErr.takeError();
6831 }
6832
6833 return D2;
6834}
6835
6838 DeclContext *DC, *LexicalDC;
6839 DeclarationName Name;
6840 SourceLocation Loc;
6841 NamedDecl *ToD;
6842
6843 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6844 return std::move(Err);
6845
6846 if (ToD)
6847 return ToD;
6848
6849 const FunctionTemplateDecl *FoundByLookup = nullptr;
6850
6851 // Try to find a function in our own ("to") context with the same name, same
6852 // type, and in the same context as the function we're importing.
6853 // FIXME Split this into a separate function.
6854 if (!LexicalDC->isFunctionOrMethod()) {
6856 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6857 for (auto *FoundDecl : FoundDecls) {
6858 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6859 continue;
6860
6861 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6862 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6863 continue;
6864 if (IsStructuralMatch(D, FoundTemplate)) {
6865 FunctionTemplateDecl *TemplateWithDef =
6866 getTemplateDefinition(FoundTemplate);
6867 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6868 return Importer.MapImported(D, TemplateWithDef);
6869
6870 FoundByLookup = FoundTemplate;
6871 break;
6872 // TODO: handle conflicting names
6873 }
6874 }
6875 }
6876 }
6877
6878 auto ParamsOrErr = import(D->getTemplateParameters());
6879 if (!ParamsOrErr)
6880 return ParamsOrErr.takeError();
6881 TemplateParameterList *Params = *ParamsOrErr;
6882
6883 FunctionDecl *TemplatedFD;
6884 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6885 return std::move(Err);
6886
6887 // At creation of the template the template parameters are "adopted"
6888 // (DeclContext is changed). After this possible change the lookup table
6889 // must be updated.
6890 // At deduction guides the DeclContext of the template parameters may be
6891 // different from what we would expect, it may be the class template, or a
6892 // probably different CXXDeductionGuideDecl. This may come from the fact that
6893 // the template parameter objects may be shared between deduction guides or
6894 // the class template, and at creation of multiple FunctionTemplateDecl
6895 // objects (for deduction guides) the same parameters are re-used. The
6896 // "adoption" happens multiple times with different parent, even recursively
6897 // for TemplateTemplateParmDecl. The same happens at import when the
6898 // FunctionTemplateDecl objects are created, but in different order.
6899 // In this way the DeclContext of these template parameters is not necessarily
6900 // the same as in the "from" context.
6902 OldParamDC.reserve(Params->size());
6903 llvm::transform(*Params, std::back_inserter(OldParamDC),
6904 [](NamedDecl *ND) { return ND->getDeclContext(); });
6905
6906 FunctionTemplateDecl *ToFunc;
6907 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6908 Params, TemplatedFD))
6909 return ToFunc;
6910
6911 // Fail if TemplatedFD is already part of a template.
6912 // The template should have been found by structural equivalence check before,
6913 // or ToFunc should be already imported.
6914 // If not, there is AST incompatibility that can be caused by previous import
6915 // errors. (NameConflict is not exact here.)
6916 if (TemplatedFD->getDescribedTemplate())
6917 return make_error<ASTImportError>(ASTImportError::NameConflict);
6918
6919 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6920
6921 ToFunc->setAccess(D->getAccess());
6922 ToFunc->setLexicalDeclContext(LexicalDC);
6923 addDeclToContexts(D, ToFunc);
6924
6925 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6926 if (LT && !OldParamDC.empty()) {
6927 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6928 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6929 }
6930
6931 if (FoundByLookup) {
6932 auto *Recent =
6933 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6934 if (!TemplatedFD->getPreviousDecl()) {
6935 assert(FoundByLookup->getTemplatedDecl() &&
6936 "Found decl must have its templated decl set");
6937 auto *PrevTemplated =
6938 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6939 if (TemplatedFD != PrevTemplated)
6940 TemplatedFD->setPreviousDecl(PrevTemplated);
6941 }
6942 ToFunc->setPreviousDecl(Recent);
6943 }
6944
6945 return ToFunc;
6946}
6947
6949 DeclContext *DC, *LexicalDC;
6950 Error Err = ImportDeclContext(D, DC, LexicalDC);
6951 auto LocationOrErr = importChecked(Err, D->getLocation());
6952 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6953 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6954 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6955 if (Err)
6956 return std::move(Err);
6957
6958 ConceptDecl *To;
6959 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6960 NameDeclOrErr, ToTemplateParameters,
6961 ConstraintExpr))
6962 return To;
6963 To->setLexicalDeclContext(LexicalDC);
6964 LexicalDC->addDeclInternal(To);
6965 return To;
6966}
6967
6970 DeclContext *DC, *LexicalDC;
6971 Error Err = ImportDeclContext(D, DC, LexicalDC);
6972 auto RequiresLoc = importChecked(Err, D->getLocation());
6973 if (Err)
6974 return std::move(Err);
6975
6977 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
6978 return To;
6979 To->setLexicalDeclContext(LexicalDC);
6980 LexicalDC->addDeclInternal(To);
6981 return To;
6982}
6983
6986 DeclContext *DC, *LexicalDC;
6987 Error Err = ImportDeclContext(D, DC, LexicalDC);
6988 auto ToSL = importChecked(Err, D->getLocation());
6989 if (Err)
6990 return std::move(Err);
6991
6993 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
6994 return std::move(Err);
6995
6997 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
6998 return To;
6999 To->setLexicalDeclContext(LexicalDC);
7000 LexicalDC->addDeclInternal(To);
7001 return To;
7002}
7003
7004//----------------------------------------------------------------------------
7005// Import Statements
7006//----------------------------------------------------------------------------
7007
7009 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7010 << S->getStmtClassName();
7011 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7012}
7013
7014
7016 if (Importer.returnWithErrorInTest())
7017 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7019 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7020 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7021 // ToII is nullptr when no symbolic name is given for output operand
7022 // see ParseStmtAsm::ParseAsmOperandsOpt
7023 Names.push_back(ToII);
7024 }
7025
7026 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7027 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7028 // ToII is nullptr when no symbolic name is given for input operand
7029 // see ParseStmtAsm::ParseAsmOperandsOpt
7030 Names.push_back(ToII);
7031 }
7032
7033 SmallVector<Expr *, 4> Clobbers;
7034 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7035 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7036 Clobbers.push_back(*ClobberOrErr);
7037 else
7038 return ClobberOrErr.takeError();
7039
7040 }
7041
7042 SmallVector<Expr *, 4> Constraints;
7043 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7044 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7045 Constraints.push_back(*OutputOrErr);
7046 else
7047 return OutputOrErr.takeError();
7048 }
7049
7050 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7051 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7052 Constraints.push_back(*InputOrErr);
7053 else
7054 return InputOrErr.takeError();
7055 }
7056
7058 S->getNumLabels());
7059 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7060 return std::move(Err);
7061
7062 if (Error Err =
7063 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7064 return std::move(Err);
7065
7066 if (Error Err = ImportArrayChecked(
7067 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7068 return std::move(Err);
7069
7070 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7071 if (!AsmLocOrErr)
7072 return AsmLocOrErr.takeError();
7073 auto AsmStrOrErr = import(S->getAsmStringExpr());
7074 if (!AsmStrOrErr)
7075 return AsmStrOrErr.takeError();
7076 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7077 if (!RParenLocOrErr)
7078 return RParenLocOrErr.takeError();
7079
7080 return new (Importer.getToContext()) GCCAsmStmt(
7081 Importer.getToContext(),
7082 *AsmLocOrErr,
7083 S->isSimple(),
7084 S->isVolatile(),
7085 S->getNumOutputs(),
7086 S->getNumInputs(),
7087 Names.data(),
7088 Constraints.data(),
7089 Exprs.data(),
7090 *AsmStrOrErr,
7091 S->getNumClobbers(),
7092 Clobbers.data(),
7093 S->getNumLabels(),
7094 *RParenLocOrErr);
7095}
7096
7098
7099 Error Err = Error::success();
7100 auto ToDG = importChecked(Err, S->getDeclGroup());
7101 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7102 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7103 if (Err)
7104 return std::move(Err);
7105 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7106}
7107
7109 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7110 if (!ToSemiLocOrErr)
7111 return ToSemiLocOrErr.takeError();
7112 return new (Importer.getToContext()) NullStmt(
7113 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7114}
7115
7117 SmallVector<Stmt *, 8> ToStmts(S->size());
7118
7119 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7120 return std::move(Err);
7121
7122 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7123 if (!ToLBracLocOrErr)
7124 return ToLBracLocOrErr.takeError();
7125
7126 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7127 if (!ToRBracLocOrErr)
7128 return ToRBracLocOrErr.takeError();
7129
7130 FPOptionsOverride FPO =
7132 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7133 *ToLBracLocOrErr, *ToRBracLocOrErr);
7134}
7135
7137
7138 Error Err = Error::success();
7139 auto ToLHS = importChecked(Err, S->getLHS());
7140 auto ToRHS = importChecked(Err, S->getRHS());
7141 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7142 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7143 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7144 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7145 if (Err)
7146 return std::move(Err);
7147
7148 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7149 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7150 ToStmt->setSubStmt(ToSubStmt);
7151
7152 return ToStmt;
7153}
7154
7156
7157 Error Err = Error::success();
7158 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7159 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7160 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7161 if (Err)
7162 return std::move(Err);
7163
7164 return new (Importer.getToContext()) DefaultStmt(
7165 ToDefaultLoc, ToColonLoc, ToSubStmt);
7166}
7167
7169
7170 Error Err = Error::success();
7171 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7172 auto ToLabelDecl = importChecked(Err, S->getDecl());
7173 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7174 if (Err)
7175 return std::move(Err);
7176
7177 return new (Importer.getToContext()) LabelStmt(
7178 ToIdentLoc, ToLabelDecl, ToSubStmt);
7179}
7180
7182 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7183 if (!ToAttrLocOrErr)
7184 return ToAttrLocOrErr.takeError();
7185 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7186 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7187 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7188 return std::move(Err);
7189 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7190 if (!ToSubStmtOrErr)
7191 return ToSubStmtOrErr.takeError();
7192
7194 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7195}
7196
7198
7199 Error Err = Error::success();
7200 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7201 auto ToInit = importChecked(Err, S->getInit());
7202 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7203 auto ToCond = importChecked(Err, S->getCond());
7204 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7205 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7206 auto ToThen = importChecked(Err, S->getThen());
7207 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7208 auto ToElse = importChecked(Err, S->getElse());
7209 if (Err)
7210 return std::move(Err);
7211
7212 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7213 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7214 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7215}
7216
7218
7219 Error Err = Error::success();
7220 auto ToInit = importChecked(Err, S->getInit());
7221 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7222 auto ToCond = importChecked(Err, S->getCond());
7223 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7224 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7225 auto ToBody = importChecked(Err, S->getBody());
7226 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7227 if (Err)
7228 return std::move(Err);
7229
7230 auto *ToStmt =
7231 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7232 ToCond, ToLParenLoc, ToRParenLoc);
7233 ToStmt->setBody(ToBody);
7234 ToStmt->setSwitchLoc(ToSwitchLoc);
7235
7236 // Now we have to re-chain the cases.
7237 SwitchCase *LastChainedSwitchCase = nullptr;
7238 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7239 SC = SC->getNextSwitchCase()) {
7240 Expected<SwitchCase *> ToSCOrErr = import(SC);
7241 if (!ToSCOrErr)
7242 return ToSCOrErr.takeError();
7243 if (LastChainedSwitchCase)
7244 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7245 else
7246 ToStmt->setSwitchCaseList(*ToSCOrErr);
7247 LastChainedSwitchCase = *ToSCOrErr;
7248 }
7249
7250 return ToStmt;
7251}
7252
7254
7255 Error Err = Error::success();
7256 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7257 auto ToCond = importChecked(Err, S->getCond());
7258 auto ToBody = importChecked(Err, S->getBody());
7259 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7260 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7261 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7262 if (Err)
7263 return std::move(Err);
7264
7265 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7266 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7267}
7268
7270
7271 Error Err = Error::success();
7272 auto ToBody = importChecked(Err, S->getBody());
7273 auto ToCond = importChecked(Err, S->getCond());
7274 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7275 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7276 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7277 if (Err)
7278 return std::move(Err);
7279
7280 return new (Importer.getToContext()) DoStmt(
7281 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7282}
7283
7285
7286 Error Err = Error::success();
7287 auto ToInit = importChecked(Err, S->getInit());
7288 auto ToCond = importChecked(Err, S->getCond());
7289 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7290 auto ToInc = importChecked(Err, S->getInc());
7291 auto ToBody = importChecked(Err, S->getBody());
7292 auto ToForLoc = importChecked(Err, S->getForLoc());
7293 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7294 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7295 if (Err)
7296 return std::move(Err);
7297
7298 return new (Importer.getToContext()) ForStmt(
7299 Importer.getToContext(),
7300 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7301 ToRParenLoc);
7302}
7303
7305
7306 Error Err = Error::success();
7307 auto ToLabel = importChecked(Err, S->getLabel());
7308 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7309 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7310 if (Err)
7311 return std::move(Err);
7312
7313 return new (Importer.getToContext()) GotoStmt(
7314 ToLabel, ToGotoLoc, ToLabelLoc);
7315}
7316
7318
7319 Error Err = Error::success();
7320 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7321 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7322 auto ToTarget = importChecked(Err, S->getTarget());
7323 if (Err)
7324 return std::move(Err);
7325
7326 return new (Importer.getToContext()) IndirectGotoStmt(
7327 ToGotoLoc, ToStarLoc, ToTarget);
7328}
7329
7330template <typename StmtClass>
7332 ASTImporter &Importer, StmtClass *S) {
7333 Error Err = Error::success();
7334 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7335 auto ToLabelLoc = S->hasLabelTarget()
7336 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7337 : SourceLocation();
7338 auto ToDecl = S->hasLabelTarget()
7339 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7340 : nullptr;
7341 if (Err)
7342 return std::move(Err);
7343 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7344}
7345
7349
7353
7355
7356 Error Err = Error::success();
7357 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7358 auto ToRetValue = importChecked(Err, S->getRetValue());
7359 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7360 if (Err)
7361 return std::move(Err);
7362
7363 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7364 ToNRVOCandidate);
7365}
7366
7368
7369 Error Err = Error::success();
7370 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7371 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7372 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7373 if (Err)
7374 return std::move(Err);
7375
7376 return new (Importer.getToContext()) CXXCatchStmt (
7377 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7378}
7379
7381 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7382 if (!ToTryLocOrErr)
7383 return ToTryLocOrErr.takeError();
7384
7385 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7386 if (!ToTryBlockOrErr)
7387 return ToTryBlockOrErr.takeError();
7388
7389 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7390 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7391 CXXCatchStmt *FromHandler = S->getHandler(HI);
7392 if (auto ToHandlerOrErr = import(FromHandler))
7393 ToHandlers[HI] = *ToHandlerOrErr;
7394 else
7395 return ToHandlerOrErr.takeError();
7396 }
7397
7398 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7399 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7400}
7401
7403
7404 Error Err = Error::success();
7405 auto ToInit = importChecked(Err, S->getInit());
7406 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7407 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7408 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7409 auto ToCond = importChecked(Err, S->getCond());
7410 auto ToInc = importChecked(Err, S->getInc());
7411 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7412 auto ToBody = importChecked(Err, S->getBody());
7413 auto ToForLoc = importChecked(Err, S->getForLoc());
7414 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7415 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7416 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7417 if (Err)
7418 return std::move(Err);
7419
7420 return new (Importer.getToContext()) CXXForRangeStmt(
7421 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7422 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7423}
7424
7427 Error Err = Error::success();
7428 auto ToElement = importChecked(Err, S->getElement());
7429 auto ToCollection = importChecked(Err, S->getCollection());
7430 auto ToBody = importChecked(Err, S->getBody());
7431 auto ToForLoc = importChecked(Err, S->getForLoc());
7432 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7433 if (Err)
7434 return std::move(Err);
7435
7436 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7437 ToCollection,
7438 ToBody,
7439 ToForLoc,
7440 ToRParenLoc);
7441}
7442
7444
7445 Error Err = Error::success();
7446 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7447 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7448 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7449 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7450 if (Err)
7451 return std::move(Err);
7452
7453 return new (Importer.getToContext()) ObjCAtCatchStmt (
7454 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7455}
7456
7458 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7459 if (!ToAtFinallyLocOrErr)
7460 return ToAtFinallyLocOrErr.takeError();
7461 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7462 if (!ToAtFinallyStmtOrErr)
7463 return ToAtFinallyStmtOrErr.takeError();
7464 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7465 *ToAtFinallyStmtOrErr);
7466}
7467
7469
7470 Error Err = Error::success();
7471 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7472 auto ToTryBody = importChecked(Err, S->getTryBody());
7473 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7474 if (Err)
7475 return std::move(Err);
7476
7477 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7478 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7479 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7480 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7481 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7482 else
7483 return ToCatchStmtOrErr.takeError();
7484 }
7485
7486 return ObjCAtTryStmt::Create(Importer.getToContext(),
7487 ToAtTryLoc, ToTryBody,
7488 ToCatchStmts.begin(), ToCatchStmts.size(),
7489 ToFinallyStmt);
7490}
7491
7494
7495 Error Err = Error::success();
7496 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7497 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7498 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7499 if (Err)
7500 return std::move(Err);
7501
7502 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7503 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7504}
7505
7507 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7508 if (!ToThrowLocOrErr)
7509 return ToThrowLocOrErr.takeError();
7510 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7511 if (!ToThrowExprOrErr)
7512 return ToThrowExprOrErr.takeError();
7513 return new (Importer.getToContext()) ObjCAtThrowStmt(
7514 *ToThrowLocOrErr, *ToThrowExprOrErr);
7515}
7516
7519 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7520 if (!ToAtLocOrErr)
7521 return ToAtLocOrErr.takeError();
7522 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7523 if (!ToSubStmtOrErr)
7524 return ToSubStmtOrErr.takeError();
7525 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7526 *ToSubStmtOrErr);
7527}
7528
7529//----------------------------------------------------------------------------
7530// Import Expressions
7531//----------------------------------------------------------------------------
7533 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7534 << E->getStmtClassName();
7535 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7536}
7537
7539 Error Err = Error::success();
7540 auto ToType = importChecked(Err, E->getType());
7541 auto BLoc = importChecked(Err, E->getBeginLoc());
7542 auto RParenLoc = importChecked(Err, E->getEndLoc());
7543 if (Err)
7544 return std::move(Err);
7545 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7546 if (!ParentContextOrErr)
7547 return ParentContextOrErr.takeError();
7548
7549 return new (Importer.getToContext())
7550 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7551 RParenLoc, *ParentContextOrErr);
7552}
7553
7555
7556 Error Err = Error::success();
7557 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7558 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7559 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7560 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7561 auto ToType = importChecked(Err, E->getType());
7562 if (Err)
7563 return std::move(Err);
7564
7565 return new (Importer.getToContext()) VAArgExpr(
7566 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7567 E->isMicrosoftABI());
7568}
7569
7571
7572 Error Err = Error::success();
7573 auto ToCond = importChecked(Err, E->getCond());
7574 auto ToLHS = importChecked(Err, E->getLHS());
7575 auto ToRHS = importChecked(Err, E->getRHS());
7576 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7577 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7578 auto ToType = importChecked(Err, E->getType());
7579 if (Err)
7580 return std::move(Err);
7581
7583 ExprObjectKind OK = E->getObjectKind();
7584
7585 // The value of CondIsTrue only matters if the value is not
7586 // condition-dependent.
7587 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7588
7589 return new (Importer.getToContext())
7590 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7591 ToRParenLoc, CondIsTrue);
7592}
7593
7595 Error Err = Error::success();
7596 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7597 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7598 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7599 auto ToType = importChecked(Err, E->getType());
7600 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7601 if (Err)
7602 return std::move(Err);
7603
7605 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7606 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7608}
7609
7611 Error Err = Error::success();
7612 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7613 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7614 auto ToType = importChecked(Err, E->getType());
7615 const unsigned NumSubExprs = E->getNumSubExprs();
7616
7618 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7619 ToSubExprs.resize(NumSubExprs);
7620
7621 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7622 return std::move(Err);
7623
7624 return new (Importer.getToContext()) ShuffleVectorExpr(
7625 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7626}
7627
7629 ExpectedType TypeOrErr = import(E->getType());
7630 if (!TypeOrErr)
7631 return TypeOrErr.takeError();
7632
7633 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7634 if (!BeginLocOrErr)
7635 return BeginLocOrErr.takeError();
7636
7637 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7638}
7639
7642 Error Err = Error::success();
7643 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7644 Expr *ToControllingExpr = nullptr;
7645 TypeSourceInfo *ToControllingType = nullptr;
7646 if (E->isExprPredicate())
7647 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7648 else
7649 ToControllingType = importChecked(Err, E->getControllingType());
7650 assert((ToControllingExpr || ToControllingType) &&
7651 "Either the controlling expr or type must be nonnull");
7652 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7653 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7654 if (Err)
7655 return std::move(Err);
7656
7658 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7659 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7660 return std::move(Err);
7661
7662 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7663 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7664 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7665 return std::move(Err);
7666
7667 const ASTContext &ToCtx = Importer.getToContext();
7668 if (E->isResultDependent()) {
7669 if (ToControllingExpr) {
7671 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7672 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7674 }
7676 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7677 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7679 }
7680
7681 if (ToControllingExpr) {
7683 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7684 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7686 }
7688 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7689 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7691}
7692
7694
7695 Error Err = Error::success();
7696 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7697 auto ToType = importChecked(Err, E->getType());
7698 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7699 if (Err)
7700 return std::move(Err);
7701
7702 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7703 E->getIdentKind(), E->isTransparent(),
7704 ToFunctionName);
7705}
7706
7708
7709 Error Err = Error::success();
7710 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7711 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7712 auto ToDecl = importChecked(Err, E->getDecl());
7713 auto ToLocation = importChecked(Err, E->getLocation());
7714 auto ToType = importChecked(Err, E->getType());
7715 if (Err)
7716 return std::move(Err);
7717
7718 NamedDecl *ToFoundD = nullptr;
7719 if (E->getDecl() != E->getFoundDecl()) {
7720 auto FoundDOrErr = import(E->getFoundDecl());
7721 if (!FoundDOrErr)
7722 return FoundDOrErr.takeError();
7723 ToFoundD = *FoundDOrErr;
7724 }
7725
7726 TemplateArgumentListInfo ToTAInfo;
7727 TemplateArgumentListInfo *ToResInfo = nullptr;
7728 if (E->hasExplicitTemplateArgs()) {
7729 if (Error Err =
7731 E->template_arguments(), ToTAInfo))
7732 return std::move(Err);
7733 ToResInfo = &ToTAInfo;
7734 }
7735
7736 auto *ToE = DeclRefExpr::Create(
7737 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7738 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7739 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7740 if (E->hadMultipleCandidates())
7741 ToE->setHadMultipleCandidates(true);
7742 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7743 return ToE;
7744}
7745
7747 ExpectedType TypeOrErr = import(E->getType());
7748 if (!TypeOrErr)
7749 return TypeOrErr.takeError();
7750
7751 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7752}
7753
7755 ExpectedExpr ToInitOrErr = import(E->getInit());
7756 if (!ToInitOrErr)
7757 return ToInitOrErr.takeError();
7758
7759 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7760 if (!ToEqualOrColonLocOrErr)
7761 return ToEqualOrColonLocOrErr.takeError();
7762
7763 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7764 // List elements from the second, the first is Init itself
7765 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7766 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7767 ToIndexExprs[I - 1] = *ToArgOrErr;
7768 else
7769 return ToArgOrErr.takeError();
7770 }
7771
7772 SmallVector<Designator, 4> ToDesignators(E->size());
7773 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7774 return std::move(Err);
7775
7777 Importer.getToContext(), ToDesignators,
7778 ToIndexExprs, *ToEqualOrColonLocOrErr,
7779 E->usesGNUSyntax(), *ToInitOrErr);
7780}
7781
7784 ExpectedType ToTypeOrErr = import(E->getType());
7785 if (!ToTypeOrErr)
7786 return ToTypeOrErr.takeError();
7787
7788 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7789 if (!ToLocationOrErr)
7790 return ToLocationOrErr.takeError();
7791
7792 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7793 *ToTypeOrErr, *ToLocationOrErr);
7794}
7795
7797 ExpectedType ToTypeOrErr = import(E->getType());
7798 if (!ToTypeOrErr)
7799 return ToTypeOrErr.takeError();
7800
7801 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7802 if (!ToLocationOrErr)
7803 return ToLocationOrErr.takeError();
7804
7806 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7807}
7808
7809
7811 ExpectedType ToTypeOrErr = import(E->getType());
7812 if (!ToTypeOrErr)
7813 return ToTypeOrErr.takeError();
7814
7815 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7816 if (!ToLocationOrErr)
7817 return ToLocationOrErr.takeError();
7818
7820 Importer.getToContext(), E->getValue(), E->isExact(),
7821 *ToTypeOrErr, *ToLocationOrErr);
7822}
7823
7825 auto ToTypeOrErr = import(E->getType());
7826 if (!ToTypeOrErr)
7827 return ToTypeOrErr.takeError();
7828
7829 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7830 if (!ToSubExprOrErr)
7831 return ToSubExprOrErr.takeError();
7832
7833 return new (Importer.getToContext()) ImaginaryLiteral(
7834 *ToSubExprOrErr, *ToTypeOrErr);
7835}
7836
7838 auto ToTypeOrErr = import(E->getType());
7839 if (!ToTypeOrErr)
7840 return ToTypeOrErr.takeError();
7841
7842 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7843 if (!ToLocationOrErr)
7844 return ToLocationOrErr.takeError();
7845
7846 return new (Importer.getToContext()) FixedPointLiteral(
7847 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7848 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7849}
7850
7852 ExpectedType ToTypeOrErr = import(E->getType());
7853 if (!ToTypeOrErr)
7854 return ToTypeOrErr.takeError();
7855
7856 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7857 if (!ToLocationOrErr)
7858 return ToLocationOrErr.takeError();
7859
7860 return new (Importer.getToContext()) CharacterLiteral(
7861 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7862}
7863
7865 ExpectedType ToTypeOrErr = import(E->getType());
7866 if (!ToTypeOrErr)
7867 return ToTypeOrErr.takeError();
7868
7870 if (Error Err = ImportArrayChecked(
7871 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7872 return std::move(Err);
7873
7874 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7875 E->getKind(), E->isPascal(), *ToTypeOrErr,
7876 ToLocations);
7877}
7878
7880
7881 Error Err = Error::success();
7882 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7883 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7884 auto ToType = importChecked(Err, E->getType());
7885 auto ToInitializer = importChecked(Err, E->getInitializer());
7886 if (Err)
7887 return std::move(Err);
7888
7889 return new (Importer.getToContext()) CompoundLiteralExpr(
7890 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7891 ToInitializer, E->isFileScope());
7892}
7893
7895
7896 Error Err = Error::success();
7897 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7898 auto ToType = importChecked(Err, E->getType());
7899 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7900 if (Err)
7901 return std::move(Err);
7902
7904 if (Error Err = ImportArrayChecked(
7905 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7906 ToExprs.begin()))
7907 return std::move(Err);
7908
7909 return new (Importer.getToContext()) AtomicExpr(
7910
7911 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7912}
7913
7915 Error Err = Error::success();
7916 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7917 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7918 auto ToLabel = importChecked(Err, E->getLabel());
7919 auto ToType = importChecked(Err, E->getType());
7920 if (Err)
7921 return std::move(Err);
7922
7923 return new (Importer.getToContext()) AddrLabelExpr(
7924 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7925}
7927 Error Err = Error::success();
7928 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7929 auto ToResult = importChecked(Err, E->getAPValueResult());
7930 if (Err)
7931 return std::move(Err);
7932
7933 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7934}
7936 Error Err = Error::success();
7937 auto ToLParen = importChecked(Err, E->getLParen());
7938 auto ToRParen = importChecked(Err, E->getRParen());
7939 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7940 if (Err)
7941 return std::move(Err);
7942
7943 return new (Importer.getToContext())
7944 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7945}
7946
7948 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7949 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7950 return std::move(Err);
7951
7952 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7953 if (!ToLParenLocOrErr)
7954 return ToLParenLocOrErr.takeError();
7955
7956 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7957 if (!ToRParenLocOrErr)
7958 return ToRParenLocOrErr.takeError();
7959
7960 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7961 ToExprs, *ToRParenLocOrErr);
7962}
7963
7965 Error Err = Error::success();
7966 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7967 auto ToType = importChecked(Err, E->getType());
7968 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7969 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7970 if (Err)
7971 return std::move(Err);
7972
7973 return new (Importer.getToContext())
7974 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7975 E->getTemplateDepth());
7976}
7977
7979 Error Err = Error::success();
7980 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7981 auto ToType = importChecked(Err, E->getType());
7982 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7983 if (Err)
7984 return std::move(Err);
7985
7986 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7987 E->hasStoredFPFeatures());
7988 UO->setType(ToType);
7989 UO->setSubExpr(ToSubExpr);
7990 UO->setOpcode(E->getOpcode());
7991 UO->setOperatorLoc(ToOperatorLoc);
7992 UO->setCanOverflow(E->canOverflow());
7993 if (E->hasStoredFPFeatures())
7994 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7995
7996 return UO;
7997}
7998
8000
8002 Error Err = Error::success();
8003 auto ToType = importChecked(Err, E->getType());
8004 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8005 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8006 if (Err)
8007 return std::move(Err);
8008
8009 if (E->isArgumentType()) {
8010 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8011 import(E->getArgumentTypeInfo());
8012 if (!ToArgumentTypeInfoOrErr)
8013 return ToArgumentTypeInfoOrErr.takeError();
8014
8015 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8016 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8017 ToRParenLoc);
8018 }
8019
8020 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8021 if (!ToArgumentExprOrErr)
8022 return ToArgumentExprOrErr.takeError();
8023
8024 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8025 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8026}
8027
8029 Error Err = Error::success();
8030 auto ToLHS = importChecked(Err, E->getLHS());
8031 auto ToRHS = importChecked(Err, E->getRHS());
8032 auto ToType = importChecked(Err, E->getType());
8033 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8034 if (Err)
8035 return std::move(Err);
8036
8038 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8039 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8040 E->getFPFeatures());
8041}
8042
8044 Error Err = Error::success();
8045 auto ToCond = importChecked(Err, E->getCond());
8046 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8047 auto ToLHS = importChecked(Err, E->getLHS());
8048 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8049 auto ToRHS = importChecked(Err, E->getRHS());
8050 auto ToType = importChecked(Err, E->getType());
8051 if (Err)
8052 return std::move(Err);
8053
8054 return new (Importer.getToContext()) ConditionalOperator(
8055 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8056 E->getValueKind(), E->getObjectKind());
8057}
8058
8061 Error Err = Error::success();
8062 auto ToCommon = importChecked(Err, E->getCommon());
8063 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8064 auto ToCond = importChecked(Err, E->getCond());
8065 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8066 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8067 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8068 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8069 auto ToType = importChecked(Err, E->getType());
8070 if (Err)
8071 return std::move(Err);
8072
8073 return new (Importer.getToContext()) BinaryConditionalOperator(
8074 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8075 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8076 E->getObjectKind());
8077}
8078
8081 Error Err = Error::success();
8082 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8083 if (Err)
8084 return std::move(Err);
8085
8086 return new (Importer.getToContext())
8087 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8088}
8089
8091 Error Err = Error::success();
8092 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8093 auto ToQueriedTypeSourceInfo =
8095 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8096 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8097 auto ToType = importChecked(Err, E->getType());
8098 if (Err)
8099 return std::move(Err);
8100
8101 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8102 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8103 ToDimensionExpression, ToEndLoc, ToType);
8104}
8105
8107 Error Err = Error::success();
8108 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8109 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8110 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8111 auto ToType = importChecked(Err, E->getType());
8112 if (Err)
8113 return std::move(Err);
8114
8115 return new (Importer.getToContext()) ExpressionTraitExpr(
8116 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8117 ToEndLoc, ToType);
8118}
8119
8121 Error Err = Error::success();
8122 auto ToLocation = importChecked(Err, E->getLocation());
8123 auto ToType = importChecked(Err, E->getType());
8124 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8125 if (Err)
8126 return std::move(Err);
8127
8128 return new (Importer.getToContext()) OpaqueValueExpr(
8129 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8130}
8131
8133 Error Err = Error::success();
8134 auto ToLHS = importChecked(Err, E->getLHS());
8135 auto ToRHS = importChecked(Err, E->getRHS());
8136 auto ToType = importChecked(Err, E->getType());
8137 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8138 if (Err)
8139 return std::move(Err);
8140
8141 return new (Importer.getToContext()) ArraySubscriptExpr(
8142 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8143 ToRBracketLoc);
8144}
8145
8148 Error Err = Error::success();
8149 auto ToLHS = importChecked(Err, E->getLHS());
8150 auto ToRHS = importChecked(Err, E->getRHS());
8151 auto ToType = importChecked(Err, E->getType());
8152 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8153 auto ToComputationResultType =
8155 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8156 if (Err)
8157 return std::move(Err);
8158
8160 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8161 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8162 E->getFPFeatures(),
8163 ToComputationLHSType, ToComputationResultType);
8164}
8165
8168 CXXCastPath Path;
8169 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8170 if (auto SpecOrErr = import(*I))
8171 Path.push_back(*SpecOrErr);
8172 else
8173 return SpecOrErr.takeError();
8174 }
8175 return Path;
8176}
8177
8179 ExpectedType ToTypeOrErr = import(E->getType());
8180 if (!ToTypeOrErr)
8181 return ToTypeOrErr.takeError();
8182
8183 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8184 if (!ToSubExprOrErr)
8185 return ToSubExprOrErr.takeError();
8186
8187 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8188 if (!ToBasePathOrErr)
8189 return ToBasePathOrErr.takeError();
8190
8192 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8193 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8194}
8195
8197 Error Err = Error::success();
8198 auto ToType = importChecked(Err, E->getType());
8199 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8200 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8201 if (Err)
8202 return std::move(Err);
8203
8204 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8205 if (!ToBasePathOrErr)
8206 return ToBasePathOrErr.takeError();
8207 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8208
8209 switch (E->getStmtClass()) {
8210 case Stmt::CStyleCastExprClass: {
8211 auto *CCE = cast<CStyleCastExpr>(E);
8212 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8213 if (!ToLParenLocOrErr)
8214 return ToLParenLocOrErr.takeError();
8215 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8216 if (!ToRParenLocOrErr)
8217 return ToRParenLocOrErr.takeError();
8219 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8220 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8221 *ToLParenLocOrErr, *ToRParenLocOrErr);
8222 }
8223
8224 case Stmt::CXXFunctionalCastExprClass: {
8225 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8226 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8227 if (!ToLParenLocOrErr)
8228 return ToLParenLocOrErr.takeError();
8229 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8230 if (!ToRParenLocOrErr)
8231 return ToRParenLocOrErr.takeError();
8233 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8234 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8235 *ToLParenLocOrErr, *ToRParenLocOrErr);
8236 }
8237
8238 case Stmt::ObjCBridgedCastExprClass: {
8239 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8240 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8241 if (!ToLParenLocOrErr)
8242 return ToLParenLocOrErr.takeError();
8243 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8244 if (!ToBridgeKeywordLocOrErr)
8245 return ToBridgeKeywordLocOrErr.takeError();
8246 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8247 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8248 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8249 }
8250 case Stmt::BuiltinBitCastExprClass: {
8251 auto *BBC = cast<BuiltinBitCastExpr>(E);
8252 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8253 if (!ToKWLocOrErr)
8254 return ToKWLocOrErr.takeError();
8255 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8256 if (!ToRParenLocOrErr)
8257 return ToRParenLocOrErr.takeError();
8258 return new (Importer.getToContext()) BuiltinBitCastExpr(
8259 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8260 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8261 }
8262 default:
8263 llvm_unreachable("Cast expression of unsupported type!");
8264 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8265 }
8266}
8267
8270 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8271 const OffsetOfNode &FromNode = E->getComponent(I);
8272
8273 SourceLocation ToBeginLoc, ToEndLoc;
8274
8275 if (FromNode.getKind() != OffsetOfNode::Base) {
8276 Error Err = Error::success();
8277 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8278 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8279 if (Err)
8280 return std::move(Err);
8281 }
8282
8283 switch (FromNode.getKind()) {
8285 ToNodes.push_back(
8286 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8287 break;
8288 case OffsetOfNode::Base: {
8289 auto ToBSOrErr = import(FromNode.getBase());
8290 if (!ToBSOrErr)
8291 return ToBSOrErr.takeError();
8292 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8293 break;
8294 }
8295 case OffsetOfNode::Field: {
8296 auto ToFieldOrErr = import(FromNode.getField());
8297 if (!ToFieldOrErr)
8298 return ToFieldOrErr.takeError();
8299 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8300 break;
8301 }
8303 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8304 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8305 break;
8306 }
8307 }
8308 }
8309
8311 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8312 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8313 if (!ToIndexExprOrErr)
8314 return ToIndexExprOrErr.takeError();
8315 ToExprs[I] = *ToIndexExprOrErr;
8316 }
8317
8318 Error Err = Error::success();
8319 auto ToType = importChecked(Err, E->getType());
8320 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8321 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8322 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8323 if (Err)
8324 return std::move(Err);
8325
8326 return OffsetOfExpr::Create(
8327 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8328 ToExprs, ToRParenLoc);
8329}
8330
8332 Error Err = Error::success();
8333 auto ToType = importChecked(Err, E->getType());
8334 auto ToOperand = importChecked(Err, E->getOperand());
8335 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8336 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8337 if (Err)
8338 return std::move(Err);
8339
8340 CanThrowResult ToCanThrow;
8341 if (E->isValueDependent())
8342 ToCanThrow = CT_Dependent;
8343 else
8344 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8345
8346 return new (Importer.getToContext()) CXXNoexceptExpr(
8347 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8348}
8349
8351 Error Err = Error::success();
8352 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8353 auto ToType = importChecked(Err, E->getType());
8354 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8355 if (Err)
8356 return std::move(Err);
8357
8358 return new (Importer.getToContext()) CXXThrowExpr(
8359 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8360}
8361
8363 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8364 if (!ToUsedLocOrErr)
8365 return ToUsedLocOrErr.takeError();
8366
8367 auto ToParamOrErr = import(E->getParam());
8368 if (!ToParamOrErr)
8369 return ToParamOrErr.takeError();
8370
8371 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8372 if (!UsedContextOrErr)
8373 return UsedContextOrErr.takeError();
8374
8375 // Import the default arg if it was not imported yet.
8376 // This is needed because it can happen that during the import of the
8377 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8378 // encountered here. The default argument for a ParmVarDecl is set in the
8379 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8380 // see VisitParmVarDecl).
8381 ParmVarDecl *ToParam = *ToParamOrErr;
8382 if (!ToParam->getDefaultArg()) {
8383 std::optional<ParmVarDecl *> FromParam =
8384 Importer.getImportedFromDecl(ToParam);
8385 assert(FromParam && "ParmVarDecl was not imported?");
8386
8387 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8388 return std::move(Err);
8389 }
8390 Expr *RewrittenInit = nullptr;
8391 if (E->hasRewrittenInit()) {
8392 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8393 if (!ExprOrErr)
8394 return ExprOrErr.takeError();
8395 RewrittenInit = ExprOrErr.get();
8396 }
8397 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8398 *ToParamOrErr, RewrittenInit,
8399 *UsedContextOrErr);
8400}
8401
8404 Error Err = Error::success();
8405 auto ToType = importChecked(Err, E->getType());
8406 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8407 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8408 if (Err)
8409 return std::move(Err);
8410
8411 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8412 ToType, ToTypeSourceInfo, ToRParenLoc);
8413}
8414
8417 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8418 if (!ToSubExprOrErr)
8419 return ToSubExprOrErr.takeError();
8420
8421 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8422 if (!ToDtorOrErr)
8423 return ToDtorOrErr.takeError();
8424
8425 ASTContext &ToCtx = Importer.getToContext();
8426 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8427 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8428}
8429
8431
8433 Error Err = Error::success();
8434 auto ToConstructor = importChecked(Err, E->getConstructor());
8435 auto ToType = importChecked(Err, E->getType());
8436 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8437 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8438 if (Err)
8439 return std::move(Err);
8440
8442 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8443 return std::move(Err);
8444
8446 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8447 ToParenOrBraceRange, E->hadMultipleCandidates(),
8450}
8451
8454 DeclContext *DC, *LexicalDC;
8455 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8456 return std::move(Err);
8457
8458 Error Err = Error::success();
8459 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8460 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8461 if (Err)
8462 return std::move(Err);
8463 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8464
8466 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8467 D->getManglingNumber()))
8468 return To;
8469
8470 To->setLexicalDeclContext(LexicalDC);
8471 LexicalDC->addDeclInternal(To);
8472 return To;
8473}
8474
8477 Error Err = Error::success();
8478 auto ToType = importChecked(Err, E->getType());
8479 Expr *ToTemporaryExpr = importChecked(
8480 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8481 auto ToMaterializedDecl =
8483 if (Err)
8484 return std::move(Err);
8485
8486 if (!ToTemporaryExpr)
8487 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8488
8489 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8490 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8491 ToMaterializedDecl);
8492
8493 return ToMTE;
8494}
8495
8497 Error Err = Error::success();
8498 auto *ToPattern = importChecked(Err, E->getPattern());
8499 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8500 if (Err)
8501 return std::move(Err);
8502
8503 return new (Importer.getToContext())
8504 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8505}
8506
8508 Error Err = Error::success();
8509 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8510 auto ToPack = importChecked(Err, E->getPack());
8511 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8512 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8513 if (Err)
8514 return std::move(Err);
8515
8516 UnsignedOrNone Length = std::nullopt;
8517 if (!E->isValueDependent())
8518 Length = E->getPackLength();
8519
8520 SmallVector<TemplateArgument, 8> ToPartialArguments;
8521 if (E->isPartiallySubstituted()) {
8523 ToPartialArguments))
8524 return std::move(Err);
8525 }
8526
8528 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8529 Length, ToPartialArguments);
8530}
8531
8532
8534 Error Err = Error::success();
8535 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8536 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8537 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8538 auto ToArraySize = importChecked(Err, E->getArraySize());
8539 auto ToInitializer = importChecked(Err, E->getInitializer());
8540 auto ToType = importChecked(Err, E->getType());
8541 auto ToAllocatedTypeSourceInfo =
8543 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8544 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8545 if (Err)
8546 return std::move(Err);
8547
8548 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8549 if (Error Err =
8550 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8551 return std::move(Err);
8552
8553 return CXXNewExpr::Create(
8554 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8555 ToOperatorDelete, E->implicitAllocationParameters(),
8556 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8557 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8558 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8559}
8560
8562 Error Err = Error::success();
8563 auto ToType = importChecked(Err, E->getType());
8564 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8565 auto ToArgument = importChecked(Err, E->getArgument());
8566 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8567 if (Err)
8568 return std::move(Err);
8569
8570 return new (Importer.getToContext()) CXXDeleteExpr(
8571 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8572 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8573 ToBeginLoc);
8574}
8575
8577 Error Err = Error::success();
8578 auto ToType = importChecked(Err, E->getType());
8579 auto ToLocation = importChecked(Err, E->getLocation());
8580 auto ToConstructor = importChecked(Err, E->getConstructor());
8581 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8582 if (Err)
8583 return std::move(Err);
8584
8586 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8587 return std::move(Err);
8588
8590 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8591 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8594 ToParenOrBraceRange);
8596 return ToE;
8597}
8598
8600 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8601 if (!ToSubExprOrErr)
8602 return ToSubExprOrErr.takeError();
8603
8605 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8606 return std::move(Err);
8607
8609 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8610 ToObjects);
8611}
8612
8614 Error Err = Error::success();
8615 auto ToCallee = importChecked(Err, E->getCallee());
8616 auto ToType = importChecked(Err, E->getType());
8617 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8618 if (Err)
8619 return std::move(Err);
8620
8622 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8623 return std::move(Err);
8624
8625 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8626 ToType, E->getValueKind(), ToRParenLoc,
8627 E->getFPFeatures());
8628}
8629
8631 ExpectedType ToTypeOrErr = import(E->getType());
8632 if (!ToTypeOrErr)
8633 return ToTypeOrErr.takeError();
8634
8635 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8636 if (!ToLocationOrErr)
8637 return ToLocationOrErr.takeError();
8638
8639 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8640 *ToTypeOrErr, E->isImplicit());
8641}
8642
8644 ExpectedType ToTypeOrErr = import(E->getType());
8645 if (!ToTypeOrErr)
8646 return ToTypeOrErr.takeError();
8647
8648 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8649 if (!ToLocationOrErr)
8650 return ToLocationOrErr.takeError();
8651
8652 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8653 *ToTypeOrErr, *ToLocationOrErr);
8654}
8655
8657 Error Err = Error::success();
8658 auto ToBase = importChecked(Err, E->getBase());
8659 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8660 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8661 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8662 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8663 auto ToType = importChecked(Err, E->getType());
8664 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8665 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8666 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8667 if (Err)
8668 return std::move(Err);
8669
8670 DeclAccessPair ToFoundDecl =
8672
8673 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8674
8675 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8676 if (E->hasExplicitTemplateArgs()) {
8677 if (Error Err =
8679 E->template_arguments(), ToTAInfo))
8680 return std::move(Err);
8681 ResInfo = &ToTAInfo;
8682 }
8683
8684 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8685 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8686 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8687 ResInfo, ToType, E->getValueKind(),
8688 E->getObjectKind(), E->isNonOdrUse());
8689}
8690
8693 Error Err = Error::success();
8694 auto ToBase = importChecked(Err, E->getBase());
8695 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8696 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8697 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8698 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8699 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8700 if (Err)
8701 return std::move(Err);
8702
8704 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8705 const IdentifierInfo *ToII = Importer.Import(FromII);
8706 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8707 if (!ToDestroyedTypeLocOrErr)
8708 return ToDestroyedTypeLocOrErr.takeError();
8709 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8710 } else {
8711 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8712 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8713 else
8714 return ToTIOrErr.takeError();
8715 }
8716
8717 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8718 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8719 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8720}
8721
8724 Error Err = Error::success();
8725 auto ToType = importChecked(Err, E->getType());
8726 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8727 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8728 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8729 auto ToFirstQualifierFoundInScope =
8731 if (Err)
8732 return std::move(Err);
8733
8734 Expr *ToBase = nullptr;
8735 if (!E->isImplicitAccess()) {
8736 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8737 ToBase = *ToBaseOrErr;
8738 else
8739 return ToBaseOrErr.takeError();
8740 }
8741
8742 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8743
8744 if (E->hasExplicitTemplateArgs()) {
8745 if (Error Err =
8747 E->template_arguments(), ToTAInfo))
8748 return std::move(Err);
8749 ResInfo = &ToTAInfo;
8750 }
8751 auto ToMember = importChecked(Err, E->getMember());
8752 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8753 if (Err)
8754 return std::move(Err);
8755 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8756
8757 // Import additional name location/type info.
8758 if (Error Err =
8759 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8760 return std::move(Err);
8761
8763 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8764 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8765 ToMemberNameInfo, ResInfo);
8766}
8767
8770 Error Err = Error::success();
8771 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8772 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8773 auto ToDeclName = importChecked(Err, E->getDeclName());
8774 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8775 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8776 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8777 if (Err)
8778 return std::move(Err);
8779
8780 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8781 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8782 return std::move(Err);
8783
8784 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8785 TemplateArgumentListInfo *ResInfo = nullptr;
8786 if (E->hasExplicitTemplateArgs()) {
8787 if (Error Err =
8789 return std::move(Err);
8790 ResInfo = &ToTAInfo;
8791 }
8792
8794 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8795 ToNameInfo, ResInfo);
8796}
8797
8800 Error Err = Error::success();
8801 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8802 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8803 auto ToType = importChecked(Err, E->getType());
8804 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8805 if (Err)
8806 return std::move(Err);
8807
8809 if (Error Err =
8810 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8811 return std::move(Err);
8812
8814 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8815 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8816}
8817
8820 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8821 if (!ToNamingClassOrErr)
8822 return ToNamingClassOrErr.takeError();
8823
8824 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8825 if (!ToQualifierLocOrErr)
8826 return ToQualifierLocOrErr.takeError();
8827
8828 Error Err = Error::success();
8829 auto ToName = importChecked(Err, E->getName());
8830 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8831 if (Err)
8832 return std::move(Err);
8833 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8834
8835 // Import additional name location/type info.
8836 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8837 return std::move(Err);
8838
8839 UnresolvedSet<8> ToDecls;
8840 for (auto *D : E->decls())
8841 if (auto ToDOrErr = import(D))
8842 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8843 else
8844 return ToDOrErr.takeError();
8845
8846 if (E->hasExplicitTemplateArgs()) {
8847 TemplateArgumentListInfo ToTAInfo;
8850 ToTAInfo))
8851 return std::move(Err);
8852
8853 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8854 if (!ToTemplateKeywordLocOrErr)
8855 return ToTemplateKeywordLocOrErr.takeError();
8856
8857 const bool KnownDependent =
8858 (E->getDependence() & ExprDependence::TypeValue) ==
8859 ExprDependence::TypeValue;
8861 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8862 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8863 ToDecls.begin(), ToDecls.end(), KnownDependent,
8864 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8865 }
8866
8868 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8869 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8870 /*KnownDependent=*/E->isTypeDependent(),
8871 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8872}
8873
8876 Error Err = Error::success();
8877 auto ToType = importChecked(Err, E->getType());
8878 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8879 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8880 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8881 auto ToName = importChecked(Err, E->getName());
8882 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8883 if (Err)
8884 return std::move(Err);
8885
8886 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8887 // Import additional name location/type info.
8888 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8889 return std::move(Err);
8890
8891 UnresolvedSet<8> ToDecls;
8892 for (Decl *D : E->decls())
8893 if (auto ToDOrErr = import(D))
8894 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8895 else
8896 return ToDOrErr.takeError();
8897
8898 TemplateArgumentListInfo ToTAInfo;
8899 TemplateArgumentListInfo *ResInfo = nullptr;
8900 if (E->hasExplicitTemplateArgs()) {
8901 TemplateArgumentListInfo FromTAInfo;
8902 E->copyTemplateArgumentsInto(FromTAInfo);
8903 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8904 return std::move(Err);
8905 ResInfo = &ToTAInfo;
8906 }
8907
8908 Expr *ToBase = nullptr;
8909 if (!E->isImplicitAccess()) {
8910 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8911 ToBase = *ToBaseOrErr;
8912 else
8913 return ToBaseOrErr.takeError();
8914 }
8915
8917 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8918 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8919 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8920}
8921
8923 Error Err = Error::success();
8924 auto ToCallee = importChecked(Err, E->getCallee());
8925 auto ToType = importChecked(Err, E->getType());
8926 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8927 if (Err)
8928 return std::move(Err);
8929
8930 unsigned NumArgs = E->getNumArgs();
8931 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8932 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8933 return std::move(Err);
8934
8935 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8937 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8938 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8939 OCE->getADLCallKind());
8940 }
8941
8942 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8943 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8944 /*MinNumArgs=*/0, E->getADLCallKind());
8945}
8946
8948 CXXRecordDecl *FromClass = E->getLambdaClass();
8949 auto ToClassOrErr = import(FromClass);
8950 if (!ToClassOrErr)
8951 return ToClassOrErr.takeError();
8952 CXXRecordDecl *ToClass = *ToClassOrErr;
8953
8954 auto ToCallOpOrErr = import(E->getCallOperator());
8955 if (!ToCallOpOrErr)
8956 return ToCallOpOrErr.takeError();
8957
8958 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8959 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8960 return std::move(Err);
8961
8962 Error Err = Error::success();
8963 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8964 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8965 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8966 if (Err)
8967 return std::move(Err);
8968
8969 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8970 E->getCaptureDefault(), ToCaptureDefaultLoc,
8972 E->hasExplicitResultType(), ToCaptureInits,
8973 ToEndLoc, E->containsUnexpandedParameterPack());
8974}
8975
8976
8978 Error Err = Error::success();
8979 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8980 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8981 auto ToType = importChecked(Err, E->getType());
8982 if (Err)
8983 return std::move(Err);
8984
8985 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8986 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8987 return std::move(Err);
8988
8989 ASTContext &ToCtx = Importer.getToContext();
8990 InitListExpr *To = new (ToCtx) InitListExpr(
8991 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8992 To->setType(ToType);
8993
8994 if (E->hasArrayFiller()) {
8995 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8996 To->setArrayFiller(*ToFillerOrErr);
8997 else
8998 return ToFillerOrErr.takeError();
8999 }
9000
9001 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9002 if (auto ToFDOrErr = import(FromFD))
9003 To->setInitializedFieldInUnion(*ToFDOrErr);
9004 else
9005 return ToFDOrErr.takeError();
9006 }
9007
9008 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9009 if (auto ToSyntFormOrErr = import(SyntForm))
9010 To->setSyntacticForm(*ToSyntFormOrErr);
9011 else
9012 return ToSyntFormOrErr.takeError();
9013 }
9014
9015 // Copy InitListExprBitfields, which are not handled in the ctor of
9016 // InitListExpr.
9018
9019 return To;
9020}
9021
9024 ExpectedType ToTypeOrErr = import(E->getType());
9025 if (!ToTypeOrErr)
9026 return ToTypeOrErr.takeError();
9027
9028 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9029 if (!ToSubExprOrErr)
9030 return ToSubExprOrErr.takeError();
9031
9032 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9033 *ToTypeOrErr, *ToSubExprOrErr);
9034}
9035
9038 Error Err = Error::success();
9039 auto ToLocation = importChecked(Err, E->getLocation());
9040 auto ToType = importChecked(Err, E->getType());
9041 auto ToConstructor = importChecked(Err, E->getConstructor());
9042 if (Err)
9043 return std::move(Err);
9044
9045 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9046 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9047 E->inheritedFromVBase());
9048}
9049
9051 Error Err = Error::success();
9052 auto ToType = importChecked(Err, E->getType());
9053 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9054 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9055 if (Err)
9056 return std::move(Err);
9057
9058 return new (Importer.getToContext()) ArrayInitLoopExpr(
9059 ToType, ToCommonExpr, ToSubExpr);
9060}
9061
9063 ExpectedType ToTypeOrErr = import(E->getType());
9064 if (!ToTypeOrErr)
9065 return ToTypeOrErr.takeError();
9066 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9067}
9068
9070 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9071 if (!ToBeginLocOrErr)
9072 return ToBeginLocOrErr.takeError();
9073
9074 auto ToFieldOrErr = import(E->getField());
9075 if (!ToFieldOrErr)
9076 return ToFieldOrErr.takeError();
9077
9078 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9079 if (!UsedContextOrErr)
9080 return UsedContextOrErr.takeError();
9081
9082 FieldDecl *ToField = *ToFieldOrErr;
9083 assert(ToField->hasInClassInitializer() &&
9084 "Field should have in-class initializer if there is a default init "
9085 "expression that uses it.");
9086 if (!ToField->getInClassInitializer()) {
9087 // The in-class initializer may be not yet set in "To" AST even if the
9088 // field is already there. This must be set here to make construction of
9089 // CXXDefaultInitExpr work.
9090 auto ToInClassInitializerOrErr =
9091 import(E->getField()->getInClassInitializer());
9092 if (!ToInClassInitializerOrErr)
9093 return ToInClassInitializerOrErr.takeError();
9094 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9095 }
9096
9097 Expr *RewrittenInit = nullptr;
9098 if (E->hasRewrittenInit()) {
9099 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9100 if (!ExprOrErr)
9101 return ExprOrErr.takeError();
9102 RewrittenInit = ExprOrErr.get();
9103 }
9104
9105 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9106 ToField, *UsedContextOrErr, RewrittenInit);
9107}
9108
9110 Error Err = Error::success();
9111 auto ToType = importChecked(Err, E->getType());
9112 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9113 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9114 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9115 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9116 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9117 if (Err)
9118 return std::move(Err);
9119
9121 CastKind CK = E->getCastKind();
9122 auto ToBasePathOrErr = ImportCastPath(E);
9123 if (!ToBasePathOrErr)
9124 return ToBasePathOrErr.takeError();
9125
9126 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9128 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9129 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9130 ToAngleBrackets);
9131 } else if (isa<CXXDynamicCastExpr>(E)) {
9133 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9134 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9135 } else if (isa<CXXReinterpretCastExpr>(E)) {
9137 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9138 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9139 } else if (isa<CXXConstCastExpr>(E)) {
9141 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9142 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9143 } else {
9144 llvm_unreachable("Unknown cast type");
9145 return make_error<ASTImportError>();
9146 }
9147}
9148
9151 Error Err = Error::success();
9152 auto ToType = importChecked(Err, E->getType());
9153 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9154 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9155 auto ToReplacement = importChecked(Err, E->getReplacement());
9156 if (Err)
9157 return std::move(Err);
9158
9159 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9160 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9162 E->getFinal());
9163}
9164
9166 Error Err = Error::success();
9167 auto ToType = importChecked(Err, E->getType());
9168 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9169 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9170 if (Err)
9171 return std::move(Err);
9172
9174 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9175 return std::move(Err);
9176
9177 if (E->isStoredAsBoolean()) {
9178 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9179 // Value is always false.
9180 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9181 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9182 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9183 }
9184 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9185 E->getTrait(), ToArgs, ToEndLoc,
9186 E->getAPValue());
9187}
9188
9190 ExpectedType ToTypeOrErr = import(E->getType());
9191 if (!ToTypeOrErr)
9192 return ToTypeOrErr.takeError();
9193
9194 auto ToSourceRangeOrErr = import(E->getSourceRange());
9195 if (!ToSourceRangeOrErr)
9196 return ToSourceRangeOrErr.takeError();
9197
9198 if (E->isTypeOperand()) {
9199 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9200 return new (Importer.getToContext()) CXXTypeidExpr(
9201 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9202 else
9203 return ToTSIOrErr.takeError();
9204 }
9205
9206 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9207 if (!ToExprOperandOrErr)
9208 return ToExprOperandOrErr.takeError();
9209
9210 return new (Importer.getToContext()) CXXTypeidExpr(
9211 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9212}
9213
9215 Error Err = Error::success();
9216
9217 QualType ToType = importChecked(Err, E->getType());
9218 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9219 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9220 Expr *ToLHS = importChecked(Err, E->getLHS());
9221 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9222 Expr *ToRHS = importChecked(Err, E->getRHS());
9223 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9224
9225 if (Err)
9226 return std::move(Err);
9227
9228 return new (Importer.getToContext())
9229 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9230 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9231}
9232
9234 Error Err = Error::success();
9235 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9236 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9237 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9238
9239 auto Body = importChecked(Err, E->getBody());
9240 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9241 if (Err)
9242 return std::move(Err);
9243 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9244 if (Error Err =
9245 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9246 return std::move(Err);
9248 E->getRequirements().size());
9249 if (Error Err =
9250 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9251 return std::move(Err);
9252 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9253 LParenLoc, LocalParameters, RParenLoc,
9254 Requirements, RBraceLoc);
9255}
9256
9259 Error Err = Error::success();
9260 auto CL = importChecked(Err, E->getConceptReference());
9261 auto CSD = importChecked(Err, E->getSpecializationDecl());
9262 if (Err)
9263 return std::move(Err);
9264 if (E->isValueDependent())
9266 Importer.getToContext(), CL,
9267 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9268 ConstraintSatisfaction Satisfaction;
9269 if (Error Err =
9271 return std::move(Err);
9273 Importer.getToContext(), CL,
9274 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9275}
9276
9278 CXXMethodDecl *FromMethod) {
9279 Error ImportErrors = Error::success();
9280 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9281 if (auto ImportedOrErr = import(FromOverriddenMethod))
9283 (*ImportedOrErr)->getCanonicalDecl()));
9284 else
9285 ImportErrors =
9286 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9287 }
9288 return ImportErrors;
9289}
9290
9292 ASTContext &FromContext, FileManager &FromFileManager,
9293 bool MinimalImport,
9294 std::shared_ptr<ASTImporterSharedState> SharedState)
9295 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9296 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9297 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9298
9299 // Create a default state without the lookup table: LLDB case.
9300 if (!SharedState) {
9301 this->SharedState = std::make_shared<ASTImporterSharedState>();
9302 }
9303
9304 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9305 ToContext.getTranslationUnitDecl();
9306}
9307
9308ASTImporter::~ASTImporter() = default;
9309
9311 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9312 "Try to get field index for non-field.");
9313
9314 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9315 if (!Owner)
9316 return std::nullopt;
9317
9318 unsigned Index = 0;
9319 for (const auto *D : Owner->decls()) {
9320 if (D == F)
9321 return Index;
9322
9324 ++Index;
9325 }
9326
9327 llvm_unreachable("Field was not found in its parent context.");
9328
9329 return std::nullopt;
9330}
9331
9332ASTImporter::FoundDeclsTy
9333ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9334 // We search in the redecl context because of transparent contexts.
9335 // E.g. a simple C language enum is a transparent context:
9336 // enum E { A, B };
9337 // Now if we had a global variable in the TU
9338 // int A;
9339 // then the enum constant 'A' and the variable 'A' violates ODR.
9340 // We can diagnose this only if we search in the redecl context.
9341 DeclContext *ReDC = DC->getRedeclContext();
9342 if (SharedState->getLookupTable()) {
9343 if (ReDC->isNamespace()) {
9344 // Namespaces can be reopened.
9345 // Lookup table does not handle this, we must search here in all linked
9346 // namespaces.
9347 FoundDeclsTy Result;
9348 SmallVector<Decl *, 2> NSChain =
9350 dyn_cast<NamespaceDecl>(ReDC));
9351 for (auto *D : NSChain) {
9353 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9354 Name);
9356 }
9357 return Result;
9358 } else {
9360 SharedState->getLookupTable()->lookup(ReDC, Name);
9361 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9362 }
9363 } else {
9364 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9365 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9366 // We must search by the slow case of localUncachedLookup because that is
9367 // working even if there is no LookupPtr for the DC. We could use
9368 // DC::buildLookup() to create the LookupPtr, but that would load external
9369 // decls again, we must avoid that case.
9370 // Also, even if we had the LookupPtr, we must find Decls which are not
9371 // in the LookupPtr, so we need the slow case.
9372 // These cases are handled in ASTImporterLookupTable, but we cannot use
9373 // that with LLDB since that traverses through the AST which initiates the
9374 // load of external decls again via DC::decls(). And again, we must avoid
9375 // loading external decls during the import.
9376 if (Result.empty())
9377 ReDC->localUncachedLookup(Name, Result);
9378 return Result;
9379 }
9380}
9381
9382void ASTImporter::AddToLookupTable(Decl *ToD) {
9383 SharedState->addDeclToLookup(ToD);
9384}
9385
9387 // Import the decl using ASTNodeImporter.
9388 ASTNodeImporter Importer(*this);
9389 return Importer.Visit(FromD);
9390}
9391
9393 MapImported(FromD, ToD);
9394}
9395
9398 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9399 if (Expected<Expr *> R = Import(CLE))
9401 }
9402
9403 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9404 // ASTNodeImporter.
9405 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9406}
9407
9409 if (!FromT)
9410 return FromT;
9411
9412 // Check whether we've already imported this type.
9413 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9414 ImportedTypes.find(FromT);
9415 if (Pos != ImportedTypes.end())
9416 return Pos->second;
9417
9418 // Import the type.
9419 ASTNodeImporter Importer(*this);
9420 ExpectedType ToTOrErr = Importer.Visit(FromT);
9421 if (!ToTOrErr)
9422 return ToTOrErr.takeError();
9423
9424 // Record the imported type.
9425 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9426
9427 return ToTOrErr->getTypePtr();
9428}
9429
9431 if (FromT.isNull())
9432 return QualType{};
9433
9434 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9435 if (!ToTyOrErr)
9436 return ToTyOrErr.takeError();
9437
9438 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9439}
9440
9442 if (!FromTSI)
9443 return FromTSI;
9444
9445 // FIXME: For now we just create a "trivial" type source info based
9446 // on the type and a single location. Implement a real version of this.
9447 ExpectedType TOrErr = Import(FromTSI->getType());
9448 if (!TOrErr)
9449 return TOrErr.takeError();
9450 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9451 if (!BeginLocOrErr)
9452 return BeginLocOrErr.takeError();
9453
9454 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9455}
9456
9457namespace {
9458// To use this object, it should be created before the new attribute is created,
9459// and destructed after it is created. The construction already performs the
9460// import of the data.
9461template <typename T> struct AttrArgImporter {
9462 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9463 AttrArgImporter(AttrArgImporter<T> &&) = default;
9464 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9465 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9466
9467 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9468 : To(I.importChecked(Err, From)) {}
9469
9470 const T &value() { return To; }
9471
9472private:
9473 T To;
9474};
9475
9476// To use this object, it should be created before the new attribute is created,
9477// and destructed after it is created. The construction already performs the
9478// import of the data. The array data is accessible in a pointer form, this form
9479// is used by the attribute classes. This object should be created once for the
9480// array data to be imported (the array size is not imported, just copied).
9481template <typename T> struct AttrArgArrayImporter {
9482 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9483 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9484 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9485 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9486
9487 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9488 const llvm::iterator_range<T *> &From,
9489 unsigned ArraySize) {
9490 if (Err)
9491 return;
9492 To.reserve(ArraySize);
9493 Err = I.ImportContainerChecked(From, To);
9494 }
9495
9496 T *value() { return To.data(); }
9497
9498private:
9499 llvm::SmallVector<T, 2> To;
9500};
9501
9502class AttrImporter {
9503 Error Err{Error::success()};
9504 Attr *ToAttr = nullptr;
9505 ASTImporter &Importer;
9506 ASTNodeImporter NImporter;
9507
9508public:
9509 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9510
9511 // Useful for accessing the imported attribute.
9512 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9513 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9514
9515 // Create an "importer" for an attribute parameter.
9516 // Result of the 'value()' of that object is to be passed to the function
9517 // 'importAttr', in the order that is expected by the attribute class.
9518 template <class T> AttrArgImporter<T> importArg(const T &From) {
9519 return AttrArgImporter<T>(NImporter, Err, From);
9520 }
9521
9522 // Create an "importer" for an attribute parameter that has array type.
9523 // Result of the 'value()' of that object is to be passed to the function
9524 // 'importAttr', then the size of the array as next argument.
9525 template <typename T>
9526 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9527 unsigned ArraySize) {
9528 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9529 }
9530
9531 // Create an attribute object with the specified arguments.
9532 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9533 // should be values that are passed to the 'Create' function of the attribute.
9534 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9535 // used here.) As much data is copied or imported from the old attribute
9536 // as possible. The passed arguments should be already imported.
9537 // If an import error happens, the internal error is set to it, and any
9538 // further import attempt is ignored.
9539 template <typename T, typename... Arg>
9540 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9541 static_assert(std::is_base_of<Attr, T>::value,
9542 "T should be subclass of Attr.");
9543 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9544
9545 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9546 const IdentifierInfo *ToScopeName =
9547 Importer.Import(FromAttr->getScopeName());
9548 SourceRange ToAttrRange =
9549 NImporter.importChecked(Err, FromAttr->getRange());
9550 SourceLocation ToScopeLoc =
9551 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9552
9553 if (Err)
9554 return;
9555
9556 AttributeCommonInfo ToI(
9557 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9558 FromAttr->getParsedKind(), FromAttr->getForm());
9559 // The "SemanticSpelling" is not needed to be passed to the constructor.
9560 // That value is recalculated from the SpellingListIndex if needed.
9561 ToAttr = T::Create(Importer.getToContext(),
9562 std::forward<Arg>(ImportedArg)..., ToI);
9563
9564 ToAttr->setImplicit(FromAttr->isImplicit());
9565 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9566 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9567 ToInheritableAttr->setInherited(FromAttr->isInherited());
9568 }
9569
9570 // Create a clone of the 'FromAttr' and import its source range only.
9571 // This causes objects with invalid references to be created if the 'FromAttr'
9572 // contains other data that should be imported.
9573 void cloneAttr(const Attr *FromAttr) {
9574 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9575
9576 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9577 if (Err)
9578 return;
9579
9580 ToAttr = FromAttr->clone(Importer.getToContext());
9581 ToAttr->setRange(ToRange);
9582 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9583 }
9584
9585 // Get the result of the previous import attempt (can be used only once).
9586 llvm::Expected<Attr *> getResult() && {
9587 if (Err)
9588 return std::move(Err);
9589 assert(ToAttr && "Attribute should be created.");
9590 return ToAttr;
9591 }
9592};
9593} // namespace
9594
9596 AttrImporter AI(*this);
9597
9598 // FIXME: Is there some kind of AttrVisitor to use here?
9599 switch (FromAttr->getKind()) {
9600 case attr::Aligned: {
9601 auto *From = cast<AlignedAttr>(FromAttr);
9602 if (From->isAlignmentExpr())
9603 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9604 else
9605 AI.importAttr(From, false,
9606 AI.importArg(From->getAlignmentType()).value());
9607 break;
9608 }
9609
9610 case attr::AlignValue: {
9611 auto *From = cast<AlignValueAttr>(FromAttr);
9612 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9613 break;
9614 }
9615
9616 case attr::Format: {
9617 const auto *From = cast<FormatAttr>(FromAttr);
9618 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9619 From->getFirstArg());
9620 break;
9621 }
9622
9623 case attr::EnableIf: {
9624 const auto *From = cast<EnableIfAttr>(FromAttr);
9625 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9626 From->getMessage());
9627 break;
9628 }
9629
9630 case attr::AssertCapability: {
9631 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9632 AI.importAttr(From,
9633 AI.importArrayArg(From->args(), From->args_size()).value(),
9634 From->args_size());
9635 break;
9636 }
9637 case attr::AcquireCapability: {
9638 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9639 AI.importAttr(From,
9640 AI.importArrayArg(From->args(), From->args_size()).value(),
9641 From->args_size());
9642 break;
9643 }
9644 case attr::TryAcquireCapability: {
9645 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9646 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9647 AI.importArrayArg(From->args(), From->args_size()).value(),
9648 From->args_size());
9649 break;
9650 }
9651 case attr::ReleaseCapability: {
9652 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9653 AI.importAttr(From,
9654 AI.importArrayArg(From->args(), From->args_size()).value(),
9655 From->args_size());
9656 break;
9657 }
9658 case attr::RequiresCapability: {
9659 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9660 AI.importAttr(From,
9661 AI.importArrayArg(From->args(), From->args_size()).value(),
9662 From->args_size());
9663 break;
9664 }
9665 case attr::GuardedBy: {
9666 const auto *From = cast<GuardedByAttr>(FromAttr);
9667 AI.importAttr(From, AI.importArg(From->getArg()).value());
9668 break;
9669 }
9670 case attr::PtGuardedBy: {
9671 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9672 AI.importAttr(From, AI.importArg(From->getArg()).value());
9673 break;
9674 }
9675 case attr::AcquiredAfter: {
9676 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9677 AI.importAttr(From,
9678 AI.importArrayArg(From->args(), From->args_size()).value(),
9679 From->args_size());
9680 break;
9681 }
9682 case attr::AcquiredBefore: {
9683 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9684 AI.importAttr(From,
9685 AI.importArrayArg(From->args(), From->args_size()).value(),
9686 From->args_size());
9687 break;
9688 }
9689 case attr::LockReturned: {
9690 const auto *From = cast<LockReturnedAttr>(FromAttr);
9691 AI.importAttr(From, AI.importArg(From->getArg()).value());
9692 break;
9693 }
9694 case attr::LocksExcluded: {
9695 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9696 AI.importAttr(From,
9697 AI.importArrayArg(From->args(), From->args_size()).value(),
9698 From->args_size());
9699 break;
9700 }
9701 default: {
9702 // The default branch works for attributes that have no arguments to import.
9703 // FIXME: Handle every attribute type that has arguments of type to import
9704 // (most often Expr* or Decl* or type) in the switch above.
9705 AI.cloneAttr(FromAttr);
9706 break;
9707 }
9708 }
9709
9710 return std::move(AI).getResult();
9711}
9712
9714 return ImportedDecls.lookup(FromD);
9715}
9716
9718 auto FromDPos = ImportedFromDecls.find(ToD);
9719 if (FromDPos == ImportedFromDecls.end())
9720 return nullptr;
9721 return FromDPos->second->getTranslationUnitDecl();
9722}
9723
9725 if (!FromD)
9726 return nullptr;
9727
9728 // Push FromD to the stack, and remove that when we return.
9729 ImportPath.push(FromD);
9730 auto ImportPathBuilder =
9731 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9732
9733 // Check whether there was a previous failed import.
9734 // If yes return the existing error.
9735 if (auto Error = getImportDeclErrorIfAny(FromD))
9736 return make_error<ASTImportError>(*Error);
9737
9738 // Check whether we've already imported this declaration.
9739 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9740 if (ToD) {
9741 // Already imported (possibly from another TU) and with an error.
9742 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9743 setImportDeclError(FromD, *Error);
9744 return make_error<ASTImportError>(*Error);
9745 }
9746
9747 // If FromD has some updated flags after last import, apply it.
9748 updateFlags(FromD, ToD);
9749 // If we encounter a cycle during an import then we save the relevant part
9750 // of the import path associated to the Decl.
9751 if (ImportPath.hasCycleAtBack())
9752 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9753 return ToD;
9754 }
9755
9756 // Import the declaration.
9757 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9758 if (!ToDOrErr) {
9759 // Failed to import.
9760
9761 auto Pos = ImportedDecls.find(FromD);
9762 if (Pos != ImportedDecls.end()) {
9763 // Import failed after the object was created.
9764 // Remove all references to it.
9765 auto *ToD = Pos->second;
9766 ImportedDecls.erase(Pos);
9767
9768 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9769 // (e.g. with namespaces) that several decls from the 'from' context are
9770 // mapped to the same decl in the 'to' context. If we removed entries
9771 // from the LookupTable here then we may end up removing them multiple
9772 // times.
9773
9774 // The Lookuptable contains decls only which are in the 'to' context.
9775 // Remove from the Lookuptable only if it is *imported* into the 'to'
9776 // context (and do not remove it if it was added during the initial
9777 // traverse of the 'to' context).
9778 auto PosF = ImportedFromDecls.find(ToD);
9779 if (PosF != ImportedFromDecls.end()) {
9780 // In the case of TypedefNameDecl we create the Decl first and only
9781 // then we import and set its DeclContext. So, the DC might not be set
9782 // when we reach here.
9783 if (ToD->getDeclContext())
9784 SharedState->removeDeclFromLookup(ToD);
9785 ImportedFromDecls.erase(PosF);
9786 }
9787
9788 // FIXME: AST may contain remaining references to the failed object.
9789 // However, the ImportDeclErrors in the shared state contains all the
9790 // failed objects together with their error.
9791 }
9792
9793 // Error encountered for the first time.
9794 // After takeError the error is not usable any more in ToDOrErr.
9795 // Get a copy of the error object (any more simple solution for this?).
9796 ASTImportError ErrOut;
9797 handleAllErrors(ToDOrErr.takeError(),
9798 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9799 setImportDeclError(FromD, ErrOut);
9800 // Set the error for the mapped to Decl, which is in the "to" context.
9801 if (Pos != ImportedDecls.end())
9802 SharedState->setImportDeclError(Pos->second, ErrOut);
9803
9804 // Set the error for all nodes which have been created before we
9805 // recognized the error.
9806 for (const auto &Path : SavedImportPaths[FromD]) {
9807 // The import path contains import-dependency nodes first.
9808 // Save the node that was imported as dependency of the current node.
9809 Decl *PrevFromDi = FromD;
9810 for (Decl *FromDi : Path) {
9811 // Begin and end of the path equals 'FromD', skip it.
9812 if (FromDi == FromD)
9813 continue;
9814 // We should not set import error on a node and all following nodes in
9815 // the path if child import errors are ignored.
9816 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9817 PrevFromDi))
9818 break;
9819 PrevFromDi = FromDi;
9820 setImportDeclError(FromDi, ErrOut);
9821 //FIXME Should we remove these Decls from ImportedDecls?
9822 // Set the error for the mapped to Decl, which is in the "to" context.
9823 auto Ii = ImportedDecls.find(FromDi);
9824 if (Ii != ImportedDecls.end())
9825 SharedState->setImportDeclError(Ii->second, ErrOut);
9826 // FIXME Should we remove these Decls from the LookupTable,
9827 // and from ImportedFromDecls?
9828 }
9829 }
9830 SavedImportPaths.erase(FromD);
9831
9832 // Do not return ToDOrErr, error was taken out of it.
9833 return make_error<ASTImportError>(ErrOut);
9834 }
9835
9836 ToD = *ToDOrErr;
9837
9838 // FIXME: Handle the "already imported with error" case. We can get here
9839 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9840 // previously failed create was requested).
9841 // Later GetImportedOrCreateDecl can be updated to return the error.
9842 if (!ToD) {
9843 auto Err = getImportDeclErrorIfAny(FromD);
9844 assert(Err);
9845 return make_error<ASTImportError>(*Err);
9846 }
9847
9848 // We could import from the current TU without error. But previously we
9849 // already had imported a Decl as `ToD` from another TU (with another
9850 // ASTImporter object) and with an error.
9851 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9852 setImportDeclError(FromD, *Error);
9853 return make_error<ASTImportError>(*Error);
9854 }
9855 // Make sure that ImportImpl registered the imported decl.
9856 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9857
9858 if (FromD->hasAttrs())
9859 for (const Attr *FromAttr : FromD->getAttrs()) {
9860 auto ToAttrOrErr = Import(FromAttr);
9861 if (ToAttrOrErr)
9862 ToD->addAttr(*ToAttrOrErr);
9863 else
9864 return ToAttrOrErr.takeError();
9865 }
9866
9867 // Notify subclasses.
9868 Imported(FromD, ToD);
9869
9870 updateFlags(FromD, ToD);
9871 SavedImportPaths.erase(FromD);
9872 return ToDOrErr;
9873}
9874
9877 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9878}
9879
9881 if (!FromDC)
9882 return FromDC;
9883
9884 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9885 if (!ToDCOrErr)
9886 return ToDCOrErr.takeError();
9887 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9888
9889 // When we're using a record/enum/Objective-C class/protocol as a context, we
9890 // need it to have a definition.
9891 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9892 auto *FromRecord = cast<RecordDecl>(FromDC);
9893 if (ToRecord->isCompleteDefinition())
9894 return ToDC;
9895
9896 // If FromRecord is not defined we need to force it to be.
9897 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9898 // it will start the definition but we never finish it.
9899 // If there are base classes they won't be imported and we will
9900 // be missing anything that we inherit from those bases.
9901 if (FromRecord->getASTContext().getExternalSource() &&
9902 !FromRecord->isCompleteDefinition())
9903 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9904
9905 if (FromRecord->isCompleteDefinition())
9906 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9907 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9908 return std::move(Err);
9909 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9910 auto *FromEnum = cast<EnumDecl>(FromDC);
9911 if (ToEnum->isCompleteDefinition()) {
9912 // Do nothing.
9913 } else if (FromEnum->isCompleteDefinition()) {
9914 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9915 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9916 return std::move(Err);
9917 } else {
9918 CompleteDecl(ToEnum);
9919 }
9920 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9921 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9922 if (ToClass->getDefinition()) {
9923 // Do nothing.
9924 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9925 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9926 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9927 return std::move(Err);
9928 } else {
9929 CompleteDecl(ToClass);
9930 }
9931 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9932 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9933 if (ToProto->getDefinition()) {
9934 // Do nothing.
9935 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9936 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9937 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9938 return std::move(Err);
9939 } else {
9940 CompleteDecl(ToProto);
9941 }
9942 }
9943
9944 return ToDC;
9945}
9946
9948 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9949 return cast_or_null<Expr>(*ToSOrErr);
9950 else
9951 return ToSOrErr.takeError();
9952}
9953
9955 if (!FromS)
9956 return nullptr;
9957
9958 // Check whether we've already imported this statement.
9959 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9960 if (Pos != ImportedStmts.end())
9961 return Pos->second;
9962
9963 // Import the statement.
9964 ASTNodeImporter Importer(*this);
9965 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9966 if (!ToSOrErr)
9967 return ToSOrErr;
9968
9969 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9970 auto *FromE = cast<Expr>(FromS);
9971 // Copy ExprBitfields, which may not be handled in Expr subclasses
9972 // constructors.
9973 ToE->setValueKind(FromE->getValueKind());
9974 ToE->setObjectKind(FromE->getObjectKind());
9975 ToE->setDependence(FromE->getDependence());
9976 }
9977
9978 // Record the imported statement object.
9979 ImportedStmts[FromS] = *ToSOrErr;
9980 return ToSOrErr;
9981}
9982
9984 switch (FromNNS.getKind()) {
9987 return FromNNS;
9989 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
9990 auto NSOrErr = Import(Namespace);
9991 if (!NSOrErr)
9992 return NSOrErr.takeError();
9993 auto PrefixOrErr = Import(Prefix);
9994 if (!PrefixOrErr)
9995 return PrefixOrErr.takeError();
9996 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
9997 *PrefixOrErr);
9998 }
10000 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10001 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10002 else
10003 return RDOrErr.takeError();
10005 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10006 return NestedNameSpecifier(*TyOrErr);
10007 } else {
10008 return TyOrErr.takeError();
10009 }
10010 }
10011 llvm_unreachable("Invalid nested name specifier kind");
10012}
10013
10016 // Copied from NestedNameSpecifier mostly.
10018 NestedNameSpecifierLoc NNS = FromNNS;
10019
10020 // Push each of the nested-name-specifiers's onto a stack for
10021 // serialization in reverse order.
10022 while (NNS) {
10023 NestedNames.push_back(NNS);
10024 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10025 }
10026
10028
10029 while (!NestedNames.empty()) {
10030 NNS = NestedNames.pop_back_val();
10031 NestedNameSpecifier Spec = std::nullopt;
10032 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10033 return std::move(Err);
10034
10035 NestedNameSpecifier::Kind Kind = Spec.getKind();
10036
10037 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10039 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10040 return std::move(Err);
10041
10043 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10044 return std::move(Err);
10045 }
10046
10047 switch (Kind) {
10049 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10050 ToLocalBeginLoc, ToLocalEndLoc);
10051 break;
10052
10054 SourceLocation ToTLoc;
10055 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10056 return std::move(Err);
10058 QualType(Spec.getAsType(), 0), ToTLoc);
10059 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10060 break;
10061 }
10062
10064 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10065 break;
10066
10068 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10069 if (!ToSourceRangeOrErr)
10070 return ToSourceRangeOrErr.takeError();
10071
10072 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10073 ToSourceRangeOrErr->getBegin(),
10074 ToSourceRangeOrErr->getEnd());
10075 break;
10076 }
10078 llvm_unreachable("unexpected null nested name specifier");
10079 }
10080 }
10081
10082 return Builder.getWithLocInContext(getToContext());
10083}
10084
10086 switch (From.getKind()) {
10088 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10089 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10090 else
10091 return ToTemplateOrErr.takeError();
10092
10095 UnresolvedSet<2> ToTemplates;
10096 for (auto *I : *FromStorage) {
10097 if (auto ToOrErr = Import(I))
10098 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10099 else
10100 return ToOrErr.takeError();
10101 }
10102 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10103 ToTemplates.end());
10104 }
10105
10108 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10109 if (!DeclNameOrErr)
10110 return DeclNameOrErr.takeError();
10111 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10112 }
10113
10116 auto QualifierOrErr = Import(QTN->getQualifier());
10117 if (!QualifierOrErr)
10118 return QualifierOrErr.takeError();
10119 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10120 if (!TNOrErr)
10121 return TNOrErr.takeError();
10122 return ToContext.getQualifiedTemplateName(
10123 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10124 }
10125
10128 auto QualifierOrErr = Import(DTN->getQualifier());
10129 if (!QualifierOrErr)
10130 return QualifierOrErr.takeError();
10131 return ToContext.getDependentTemplateName(
10132 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10133 }
10134
10138 auto ReplacementOrErr = Import(Subst->getReplacement());
10139 if (!ReplacementOrErr)
10140 return ReplacementOrErr.takeError();
10141
10142 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10143 if (!AssociatedDeclOrErr)
10144 return AssociatedDeclOrErr.takeError();
10145
10146 return ToContext.getSubstTemplateTemplateParm(
10147 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10148 Subst->getPackIndex(), Subst->getFinal());
10149 }
10150
10154 ASTNodeImporter Importer(*this);
10155 auto ArgPackOrErr =
10156 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10157 if (!ArgPackOrErr)
10158 return ArgPackOrErr.takeError();
10159
10160 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10161 if (!AssociatedDeclOrErr)
10162 return AssociatedDeclOrErr.takeError();
10163
10164 return ToContext.getSubstTemplateTemplateParmPack(
10165 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10166 SubstPack->getFinal());
10167 }
10169 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10170 if (!UsingOrError)
10171 return UsingOrError.takeError();
10172 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10173 }
10175 llvm_unreachable("Unexpected DeducedTemplate");
10176 }
10177
10178 llvm_unreachable("Invalid template name kind");
10179}
10180
10182 if (FromLoc.isInvalid())
10183 return SourceLocation{};
10184
10185 SourceManager &FromSM = FromContext.getSourceManager();
10186 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10187
10188 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10189 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10190 if (!ToFileIDOrErr)
10191 return ToFileIDOrErr.takeError();
10192 SourceManager &ToSM = ToContext.getSourceManager();
10193 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10194}
10195
10197 SourceLocation ToBegin, ToEnd;
10198 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10199 return std::move(Err);
10200 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10201 return std::move(Err);
10202
10203 return SourceRange(ToBegin, ToEnd);
10204}
10205
10207 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10208 if (Pos != ImportedFileIDs.end())
10209 return Pos->second;
10210
10211 SourceManager &FromSM = FromContext.getSourceManager();
10212 SourceManager &ToSM = ToContext.getSourceManager();
10213 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10214
10215 // Map the FromID to the "to" source manager.
10216 FileID ToID;
10217 if (FromSLoc.isExpansion()) {
10218 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10219 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10220 if (!ToSpLoc)
10221 return ToSpLoc.takeError();
10222 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10223 if (!ToExLocS)
10224 return ToExLocS.takeError();
10225 unsigned ExLength = FromSM.getFileIDSize(FromID);
10226 SourceLocation MLoc;
10227 if (FromEx.isMacroArgExpansion()) {
10228 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10229 } else {
10230 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10231 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10232 FromEx.isExpansionTokenRange());
10233 else
10234 return ToExLocE.takeError();
10235 }
10236 ToID = ToSM.getFileID(MLoc);
10237 } else {
10238 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10239
10240 if (!IsBuiltin && !Cache->BufferOverridden) {
10241 // Include location of this file.
10242 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10243 if (!ToIncludeLoc)
10244 return ToIncludeLoc.takeError();
10245
10246 // Every FileID that is not the main FileID needs to have a valid include
10247 // location so that the include chain points to the main FileID. When
10248 // importing the main FileID (which has no include location), we need to
10249 // create a fake include location in the main file to keep this property
10250 // intact.
10251 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10252 if (FromID == FromSM.getMainFileID())
10253 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10254
10255 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10256 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10257 // the disk again
10258 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10259 // than mmap the files several times.
10260 auto Entry =
10261 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10262 // FIXME: The filename may be a virtual name that does probably not
10263 // point to a valid file and we get no Entry here. In this case try with
10264 // the memory buffer below.
10265 if (Entry)
10266 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10267 FromSLoc.getFile().getFileCharacteristic());
10268 }
10269 }
10270
10271 if (ToID.isInvalid() || IsBuiltin) {
10272 // FIXME: We want to re-use the existing MemoryBuffer!
10273 std::optional<llvm::MemoryBufferRef> FromBuf =
10274 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10275 FromSM.getFileManager(), SourceLocation{});
10276 if (!FromBuf)
10277 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10278
10279 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10280 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10281 FromBuf->getBufferIdentifier());
10282 ToID = ToSM.createFileID(std::move(ToBuf),
10283 FromSLoc.getFile().getFileCharacteristic());
10284 }
10285 }
10286
10287 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10288
10289 ImportedFileIDs[FromID] = ToID;
10290 return ToID;
10291}
10292
10294 ExpectedExpr ToExprOrErr = Import(From->getInit());
10295 if (!ToExprOrErr)
10296 return ToExprOrErr.takeError();
10297
10298 auto LParenLocOrErr = Import(From->getLParenLoc());
10299 if (!LParenLocOrErr)
10300 return LParenLocOrErr.takeError();
10301
10302 auto RParenLocOrErr = Import(From->getRParenLoc());
10303 if (!RParenLocOrErr)
10304 return RParenLocOrErr.takeError();
10305
10306 if (From->isBaseInitializer()) {
10307 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10308 if (!ToTInfoOrErr)
10309 return ToTInfoOrErr.takeError();
10310
10311 SourceLocation EllipsisLoc;
10312 if (From->isPackExpansion())
10313 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10314 return std::move(Err);
10315
10316 return new (ToContext) CXXCtorInitializer(
10317 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10318 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10319 } else if (From->isMemberInitializer()) {
10320 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10321 if (!ToFieldOrErr)
10322 return ToFieldOrErr.takeError();
10323
10324 auto MemberLocOrErr = Import(From->getMemberLocation());
10325 if (!MemberLocOrErr)
10326 return MemberLocOrErr.takeError();
10327
10328 return new (ToContext) CXXCtorInitializer(
10329 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10330 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10331 } else if (From->isIndirectMemberInitializer()) {
10332 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10333 if (!ToIFieldOrErr)
10334 return ToIFieldOrErr.takeError();
10335
10336 auto MemberLocOrErr = Import(From->getMemberLocation());
10337 if (!MemberLocOrErr)
10338 return MemberLocOrErr.takeError();
10339
10340 return new (ToContext) CXXCtorInitializer(
10341 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10342 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10343 } else if (From->isDelegatingInitializer()) {
10344 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10345 if (!ToTInfoOrErr)
10346 return ToTInfoOrErr.takeError();
10347
10348 return new (ToContext)
10349 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10350 *ToExprOrErr, *RParenLocOrErr);
10351 } else {
10352 // FIXME: assert?
10353 return make_error<ASTImportError>();
10354 }
10355}
10356
10359 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10360 if (Pos != ImportedCXXBaseSpecifiers.end())
10361 return Pos->second;
10362
10363 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10364 if (!ToSourceRange)
10365 return ToSourceRange.takeError();
10367 if (!ToTSI)
10368 return ToTSI.takeError();
10369 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10370 if (!ToEllipsisLoc)
10371 return ToEllipsisLoc.takeError();
10372 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10373 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10374 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10375 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10376 return Imported;
10377}
10378
10380 ASTNodeImporter Importer(*this);
10381 return Importer.ImportAPValue(FromValue);
10382}
10383
10385 ExpectedDecl ToOrErr = Import(From);
10386 if (!ToOrErr)
10387 return ToOrErr.takeError();
10388 Decl *To = *ToOrErr;
10389
10390 auto *FromDC = cast<DeclContext>(From);
10391 ASTNodeImporter Importer(*this);
10392
10393 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10394 if (!ToRecord->getDefinition()) {
10395 return Importer.ImportDefinition(
10396 cast<RecordDecl>(FromDC), ToRecord,
10398 }
10399 }
10400
10401 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10402 if (!ToEnum->getDefinition()) {
10403 return Importer.ImportDefinition(
10405 }
10406 }
10407
10408 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10409 if (!ToIFace->getDefinition()) {
10410 return Importer.ImportDefinition(
10411 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10413 }
10414 }
10415
10416 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10417 if (!ToProto->getDefinition()) {
10418 return Importer.ImportDefinition(
10419 cast<ObjCProtocolDecl>(FromDC), ToProto,
10421 }
10422 }
10423
10424 return Importer.ImportDeclContext(FromDC, true);
10425}
10426
10428 if (!FromName)
10429 return DeclarationName{};
10430
10431 switch (FromName.getNameKind()) {
10433 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10434
10438 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10439 return DeclarationName(*ToSelOrErr);
10440 else
10441 return ToSelOrErr.takeError();
10442
10444 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10445 return ToContext.DeclarationNames.getCXXConstructorName(
10446 ToContext.getCanonicalType(*ToTyOrErr));
10447 else
10448 return ToTyOrErr.takeError();
10449 }
10450
10452 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10453 return ToContext.DeclarationNames.getCXXDestructorName(
10454 ToContext.getCanonicalType(*ToTyOrErr));
10455 else
10456 return ToTyOrErr.takeError();
10457 }
10458
10460 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10461 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10462 cast<TemplateDecl>(*ToTemplateOrErr));
10463 else
10464 return ToTemplateOrErr.takeError();
10465 }
10466
10468 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10469 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10470 ToContext.getCanonicalType(*ToTyOrErr));
10471 else
10472 return ToTyOrErr.takeError();
10473 }
10474
10476 return ToContext.DeclarationNames.getCXXOperatorName(
10477 FromName.getCXXOverloadedOperator());
10478
10480 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10481 Import(FromName.getCXXLiteralIdentifier()));
10482
10484 // FIXME: STATICS!
10486 }
10487
10488 llvm_unreachable("Invalid DeclarationName Kind!");
10489}
10490
10492 if (!FromId)
10493 return nullptr;
10494
10495 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10496
10497 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10498 ToId->setBuiltinID(FromId->getBuiltinID());
10499
10500 return ToId;
10501}
10502
10505 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10506 return Import(FromII);
10507 return FromIO.getOperator();
10508}
10509
10511 if (FromSel.isNull())
10512 return Selector{};
10513
10515 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10516 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10517 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10518 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10519}
10520
10524 llvm::Error Err = llvm::Error::success();
10525 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10526 for (unsigned Idx = 0; Idx < Size; Idx++) {
10527 APValue Tmp = importChecked(Err, From[Idx]);
10528 To[Idx] = Tmp;
10529 }
10530 };
10531 switch (FromValue.getKind()) {
10532 case APValue::None:
10534 case APValue::Int:
10535 case APValue::Float:
10539 Result = FromValue;
10540 break;
10541 case APValue::Vector: {
10542 Result.MakeVector();
10544 Result.setVectorUninit(FromValue.getVectorLength());
10545 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10546 Elts.data(), FromValue.getVectorLength());
10547 break;
10548 }
10549 case APValue::Array:
10550 Result.MakeArray(FromValue.getArrayInitializedElts(),
10551 FromValue.getArraySize());
10552 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10553 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10554 FromValue.getArrayInitializedElts());
10555 break;
10556 case APValue::Struct:
10557 Result.MakeStruct(FromValue.getStructNumBases(),
10558 FromValue.getStructNumFields());
10559 ImportLoop(
10560 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10561 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10562 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10563 break;
10564 case APValue::Union: {
10565 Result.MakeUnion();
10566 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10567 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10568 if (Err)
10569 return std::move(Err);
10570 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10571 break;
10572 }
10574 Result.MakeAddrLabelDiff();
10575 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10576 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10577 if (Err)
10578 return std::move(Err);
10579 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10580 cast<AddrLabelExpr>(ImpRHS));
10581 break;
10582 }
10584 const Decl *ImpMemPtrDecl =
10585 importChecked(Err, FromValue.getMemberPointerDecl());
10586 if (Err)
10587 return std::move(Err);
10589 Result.setMemberPointerUninit(
10590 cast<const ValueDecl>(ImpMemPtrDecl),
10592 FromValue.getMemberPointerPath().size());
10593 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10594 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10595 Idx++) {
10596 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10597 if (Err)
10598 return std::move(Err);
10599 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10600 }
10601 break;
10602 }
10603 case APValue::LValue:
10605 QualType FromElemTy;
10606 if (FromValue.getLValueBase()) {
10607 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10608 "in C++20 dynamic allocation are transient so they shouldn't "
10609 "appear in the AST");
10610 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10611 if (const auto *E =
10612 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10613 FromElemTy = E->getType();
10614 const Expr *ImpExpr = importChecked(Err, E);
10615 if (Err)
10616 return std::move(Err);
10617 Base = APValue::LValueBase(ImpExpr,
10618 FromValue.getLValueBase().getCallIndex(),
10619 FromValue.getLValueBase().getVersion());
10620 } else {
10621 FromElemTy =
10622 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10623 const Decl *ImpDecl = importChecked(
10624 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10625 if (Err)
10626 return std::move(Err);
10628 FromValue.getLValueBase().getCallIndex(),
10629 FromValue.getLValueBase().getVersion());
10630 }
10631 } else {
10632 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10633 const Type *ImpTypeInfo = importChecked(
10634 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10635 QualType ImpType =
10636 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10637 if (Err)
10638 return std::move(Err);
10640 ImpType);
10641 }
10642 }
10643 CharUnits Offset = FromValue.getLValueOffset();
10644 unsigned PathLength = FromValue.getLValuePath().size();
10645 Result.MakeLValue();
10646 if (FromValue.hasLValuePath()) {
10647 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10648 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10649 FromValue.isNullPointer());
10651 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10652 if (FromElemTy->isRecordType()) {
10653 const Decl *FromDecl =
10654 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10655 const Decl *ImpDecl = importChecked(Err, FromDecl);
10656 if (Err)
10657 return std::move(Err);
10658 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10659 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10660 else
10661 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10663 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10664 } else {
10665 FromElemTy =
10666 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10667 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10668 FromPath[LoopIdx].getAsArrayIndex());
10669 }
10670 }
10671 } else
10672 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10673 FromValue.isNullPointer());
10674 }
10675 if (Err)
10676 return std::move(Err);
10677 return Result;
10678}
10679
10681 DeclContext *DC,
10682 unsigned IDNS,
10683 NamedDecl **Decls,
10684 unsigned NumDecls) {
10685 if (ODRHandling == ODRHandlingType::Conservative)
10686 // Report error at any name conflict.
10687 return make_error<ASTImportError>(ASTImportError::NameConflict);
10688 else
10689 // Allow to create the new Decl with the same name.
10690 return Name;
10691}
10692
10694 if (LastDiagFromFrom)
10695 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10696 FromContext.getDiagnostics());
10697 LastDiagFromFrom = false;
10698 return ToContext.getDiagnostics().Report(Loc, DiagID);
10699}
10700
10702 if (!LastDiagFromFrom)
10703 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10704 ToContext.getDiagnostics());
10705 LastDiagFromFrom = true;
10706 return FromContext.getDiagnostics().Report(Loc, DiagID);
10707}
10708
10710 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10711 if (!ID->getDefinition())
10712 ID->startDefinition();
10713 }
10714 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10715 if (!PD->getDefinition())
10716 PD->startDefinition();
10717 }
10718 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10719 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10720 TD->startDefinition();
10721 TD->setCompleteDefinition(true);
10722 }
10723 }
10724 else {
10725 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10726 }
10727}
10728
10730 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10731 assert((Inserted || Pos->second == To) &&
10732 "Try to import an already imported Decl");
10733 if (!Inserted)
10734 return Pos->second;
10735 // This mapping should be maintained only in this function. Therefore do not
10736 // check for additional consistency.
10737 ImportedFromDecls[To] = From;
10738 // In the case of TypedefNameDecl we create the Decl first and only then we
10739 // import and set its DeclContext. So, the DC is still not set when we reach
10740 // here from GetImportedOrCreateDecl.
10741 if (To->getDeclContext())
10742 AddToLookupTable(To);
10743 return To;
10744}
10745
10746std::optional<ASTImportError>
10748 auto Pos = ImportDeclErrors.find(FromD);
10749 if (Pos != ImportDeclErrors.end())
10750 return Pos->second;
10751 else
10752 return std::nullopt;
10753}
10754
10756 auto InsertRes = ImportDeclErrors.insert({From, Error});
10757 (void)InsertRes;
10758 // Either we set the error for the first time, or we already had set one and
10759 // now we want to set the same error.
10760 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10761}
10762
10764 bool Complain) {
10765 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10766 ImportedTypes.find(From.getTypePtr());
10767 if (Pos != ImportedTypes.end()) {
10768 if (ExpectedType ToFromOrErr = Import(From)) {
10769 if (ToContext.hasSameType(*ToFromOrErr, To))
10770 return true;
10771 } else {
10772 llvm::consumeError(ToFromOrErr.takeError());
10773 }
10774 }
10775
10777 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10778 getStructuralEquivalenceKind(*this), false, Complain);
10779 return Ctx.IsEquivalent(From, To);
10780}
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:188
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:891
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:4317
SourceLocation getQuestionLoc() const
Definition Expr.h:4316
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:4486
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4501
SourceLocation getLabelLoc() const
Definition Expr.h:4503
LabelDecl * getLabel() const
Definition Expr.h:4509
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:5957
Represents a loop initializing the elements of an array.
Definition Expr.h:5904
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5919
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5924
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition TypeBase.h:3890
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2723
SourceLocation getRBracketLoc() const
Definition Expr.h:2771
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2752
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:2990
uint64_t getValue() const
Definition ExprCXX.h:3038
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3028
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3030
Expr * getDimensionExpression() const
Definition ExprCXX.h:3040
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3036
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3027
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3720
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:6816
Expr ** getSubExprs()
Definition Expr.h:6891
SourceLocation getRParenLoc() const
Definition Expr.h:6930
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5112
AtomicOp getOp() const
Definition Expr.h:6879
SourceLocation getBuiltinLoc() const
Definition Expr.h:6929
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:432
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:4389
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4443
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4427
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4431
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4436
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4424
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3974
Expr * getLHS() const
Definition Expr.h:4024
SourceLocation getOperatorLoc() const
Definition Expr.h:4016
Expr * getRHS() const
Definition Expr.h:4026
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:4938
Opcode getOpcode() const
Definition Expr.h:4019
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4194
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:8137
Pointer to a block type.
Definition TypeBase.h:3540
BreakStmt - This represents a break.
Definition Stmt.h:3135
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5470
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:2620
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2659
bool isArrayForm() const
Definition ExprCXX.h:2646
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2670
bool isGlobalDelete() const
Definition ExprCXX.h:2645
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2655
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2647
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3864
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:3963
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:3966
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:4018
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4010
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:3997
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4037
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4006
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4026
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4002
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:3990
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:3954
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:3977
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:3946
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4065
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:5026
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5048
Expr * getRHS() const
Definition ExprCXX.h:5052
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5068
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5070
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5073
Expr * getLHS() const
Definition ExprCXX.h:5051
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5069
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5071
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:2349
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:2603
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2566
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:2463
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2521
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2556
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2455
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2488
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2432
SourceRange getSourceRange() const
Definition ExprCXX.h:2604
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2510
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2550
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2453
bool isGlobalNew() const
Definition ExprCXX.h:2515
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2527
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4303
bool getValue() const
Definition ExprCXX.h:4326
SourceLocation getEndLoc() const
Definition ExprCXX.h:4323
Expr * getOperand() const
Definition ExprCXX.h:4320
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4322
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:2739
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2833
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2803
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2817
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2824
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2792
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2848
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2821
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2806
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:2840
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:3738
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3782
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3793
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:3776
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3787
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3796
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2879
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:3030
Expr * getCallee()
Definition Expr.h:3026
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3178
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3070
arg_range arguments()
Definition Expr.h:3131
SourceLocation getRParenLoc() const
Definition Expr.h:3210
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:1264
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:3612
path_iterator path_begin()
Definition Expr.h:3682
CastKind getCastKind() const
Definition Expr.h:3656
path_iterator path_end()
Definition Expr.h:3683
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3732
Expr * getSubExpr()
Definition Expr.h:3662
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1623
unsigned getValue() const
Definition Expr.h:1631
CharacterLiteralKind getKind() const
Definition Expr.h:1624
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:4784
SourceLocation getBuiltinLoc() const
Definition Expr.h:4831
Expr * getLHS() const
Definition Expr.h:4826
bool isConditionDependent() const
Definition Expr.h:4814
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4807
Expr * getRHS() const
Definition Expr.h:4828
SourceLocation getRParenLoc() const
Definition Expr.h:4834
Expr * getCond() const
Definition Expr.h:4824
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:4236
QualType getComputationLHSType() const
Definition Expr.h:4270
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:4960
QualType getComputationResultType() const
Definition Expr.h:4273
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3541
SourceLocation getLParenLoc() const
Definition Expr.h:3576
bool isFileScope() const
Definition Expr.h:3573
const Expr * getInitializer() const
Definition Expr.h:3569
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3579
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:390
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:126
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ASTConcept.h:166
NamedDecl * getFoundDecl() const
Definition ASTConcept.h:193
const DeclarationNameInfo & getConceptNameInfo() const
Definition ASTConcept.h:170
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:199
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:197
SourceLocation getTemplateKWLoc() const
Definition ASTConcept.h:176
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:4327
Expr * getLHS() const
Definition Expr.h:4361
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4350
Expr * getRHS() const
Definition Expr.h:4362
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3758
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1084
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:37
std::pair< SourceLocation, StringRef > SubstitutionDiagnostic
Definition ASTConcept.h:51
llvm::SmallVector< Detail, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition ASTConcept.h:60
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:4655
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4723
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4759
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:5486
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4756
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4748
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4745
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:3523
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:1272
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1383
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1427
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1476
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1399
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:1407
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1365
ValueDecl * getDecl()
Definition Expr.h:1340
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1453
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1470
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1459
SourceLocation getLocation() const
Definition Expr.h:1348
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1415
bool isImmediateEscalating() const
Definition Expr.h:1480
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:263
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:524
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:147
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:553
DeclContext * getDeclContext()
Definition DeclBase.h:448
AccessSpecifier getAccess() const
Definition DeclBase.h:507
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:417
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:431
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:509
AttrVec & getAttrs()
Definition DeclBase.h:524
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:360
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:918
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:364
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:821
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:830
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:854
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:813
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:844
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:808
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:3504
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:3578
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3552
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3570
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3612
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3588
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3562
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3543
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3540
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4009
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4099
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:5530
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5657
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5611
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5647
SourceLocation getFieldLoc() const
Definition Expr.h:5638
SourceLocation getRBracketLoc() const
Definition Expr.h:5686
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4630
SourceLocation getEllipsisLoc() const
Definition Expr.h:5680
SourceLocation getDotLoc() const
Definition Expr.h:5633
SourceLocation getLBracketLoc() const
Definition Expr.h:5674
Represents a C99 designated initializer expression.
Definition Expr.h:5487
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5769
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5751
MutableArrayRef< Designator > designators()
Definition Expr.h:5720
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5755
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5717
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5742
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5767
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4671
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:5141
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3420
llvm::APSInt getInitVal() const
Definition Decl.h:3440
const Expr * getInitExpr() const
Definition Decl.h:3438
Represents an enum.
Definition Decl.h:4004
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4267
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4213
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4205
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4216
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4177
EnumDecl * getMostRecentDecl()
Definition Decl.h:4100
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4222
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:4973
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4168
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5033
EnumDecl * getDefinition() const
Definition Decl.h:4107
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4194
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4160
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3864
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3886
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:3655
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3690
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3679
unsigned getNumObjects() const
Definition ExprCXX.h:3683
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3661
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:3063
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3095
Expr * getQueriedExpression() const
Definition ExprCXX.h:3102
ExpressionTrait getTrait() const
Definition ExprCXX.h:3098
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3096
ExtVectorType - Extended vector type.
Definition TypeBase.h:4265
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:3157
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3257
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4666
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3337
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3331
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4676
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3273
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3381
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4776
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:1583
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1577
SourceLocation getLocation() const
Definition Expr.h:1709
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:1668
bool isExact() const
Definition Expr.h:1701
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:1078
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:1064
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3132
Represents a function declaration or definition.
Definition Decl.h:1999
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3271
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2475
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4139
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4134
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3290
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3152
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2698
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3539
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2755
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:2906
SourceLocation getDefaultLoc() const
Definition Decl.h:2397
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2771
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2388
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2376
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2447
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4113
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4264
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2401
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2325
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4330
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2015
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2018
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2885
void setTrivial(bool IT)
Definition Decl.h:2377
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2704
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4085
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4152
bool isDeletedAsWritten() const
Definition Decl.h:2543
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:4319
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2352
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:2348
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3543
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2281
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3547
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3551
void setRangeEnd(SourceLocation E)
Definition Decl.h:2217
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2384
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4158
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4358
void setDefaulted(bool D=true)
Definition Decl.h:2385
void setBody(Stmt *B)
Definition Decl.cpp:3283
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2343
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3161
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2393
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4106
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2210
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3191
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:2896
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4842
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5264
QualType desugar() const
Definition TypeBase.h:5845
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5553
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5718
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5704
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:4816
QualType getReturnType() const
Definition TypeBase.h:4800
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:4859
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4876
Represents a C11 generic selection.
Definition Expr.h:6114
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6389
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6409
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6370
SourceLocation getGenericLoc() const
Definition Expr.h:6467
SourceLocation getRParenLoc() const
Definition Expr.h:6471
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6359
SourceLocation getDefaultLoc() const
Definition Expr.h:6470
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:4560
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6366
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6377
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6414
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:1002
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:1026
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1733
const Expr * getSubExpr() const
Definition Expr.h:1745
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3789
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:1779
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:5993
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5015
Represents a C array with an unspecified size.
Definition TypeBase.h:3907
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3464
unsigned getChainingSize() const
Definition Decl.h:3489
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3485
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:5235
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5347
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5412
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5361
unsigned getNumInits() const
Definition Expr.h:5265
SourceLocation getLBraceLoc() const
Definition Expr.h:5396
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2433
InitListExpr * getSyntacticForm() const
Definition Expr.h:5408
bool hadArrayRangeDesignator() const
Definition Expr.h:5419
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5337
SourceLocation getRBraceLoc() const
Definition Expr.h:5398
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5367
ArrayRef< Expr * > inits()
Definition Expr.h:5285
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5422
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:1538
An lvalue reference type, per C++11 [dcl.ref].
Definition TypeBase.h:3615
Represents the declaration of a label.
Definition Decl.h:523
bool isGnuLocal() const
Definition Decl.h:550
LabelStmt * getStmt() const
Definition Decl.h:547
void setStmt(LabelStmt *T)
Definition Decl.h:548
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:6143
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4914
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4931
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:4983
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:4954
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3300
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3472
SourceLocation getOperatorLoc() const
Definition Expr.h:3482
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3417
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3402
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3383
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3444
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3524
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:3377
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3433
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3425
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3477
bool isArrow() const
Definition Expr.h:3484
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3387
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3651
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:273
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:294
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:339
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:591
SourceLocation getRBraceLoc() const
Definition Decl.h:691
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:690
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:647
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:674
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:656
void setRBraceLoc(SourceLocation L)
Definition Decl.h:693
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:7847
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:7903
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:3535
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:2529
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2588
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2562
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2576
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:2569
unsigned getNumExpressions() const
Definition Expr.h:2600
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2566
unsigned getNumComponents() const
Definition Expr.h:2584
Helper class for OffsetOfExpr.
Definition Expr.h:2423
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2481
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2487
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:2428
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2432
@ Field
A field.
Definition Expr.h:2430
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2435
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2509
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2477
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2510
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2497
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1180
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1230
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1202
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3274
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3256
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3229
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3235
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3248
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3244
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3221
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition ExprCXX.h:3336
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3232
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3264
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3331
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:4357
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4386
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4397
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4393
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2184
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2209
const Expr * getSubExpr() const
Definition Expr.h:2201
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2213
ArrayRef< Expr * > exprs()
Definition Expr.h:6059
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4810
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6046
SourceLocation getLParenLoc() const
Definition Expr.h:6061
SourceLocation getRParenLoc() const
Definition Expr.h:6062
Sugar for parentheses used when specifying types.
Definition TypeBase.h:3302
Represents a parameter to a function.
Definition Decl.h:1789
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1870
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1849
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1857
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3014
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1885
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1930
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1918
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3039
bool isObjCMethodParameter() const
Definition Decl.h:1832
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1853
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1822
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1922
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1817
bool hasInheritedDefaultArg() const
Definition Decl.h:1934
void setKNRPromoted(bool promoted)
Definition Decl.h:1873
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1881
Expr * getDefaultArg()
Definition Decl.cpp:3002
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3044
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3050
unsigned getFunctionScopeDepth() const
Definition Decl.h:1839
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1938
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:2007
SourceLocation getBeginLoc() const
Definition Expr.h:2072
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:2046
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2042
StringLiteral * getFunctionName()
Definition Expr.h:2051
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2688
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:8285
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8317
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:3633
Represents a struct/union/class.
Definition Decl.h:4309
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5125
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4365
field_range fields() const
Definition Decl.h:4512
RecordDecl * getMostRecentDecl()
Definition Decl.h:4335
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5166
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4493
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4361
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:5292
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:1248
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:4579
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4615
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4612
SourceLocation getRParenLoc() const
Definition Expr.h:4599
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4602
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4435
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4497
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4520
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:4525
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4494
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4500
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4503
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4509
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:4953
SourceLocation getBeginLoc() const
Definition Expr.h:4998
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:4994
SourceLocation getEndLoc() const
Definition Expr.h:4999
SourceLocIdentKind getIdentKind() const
Definition Expr.h:4973
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:4531
CompoundStmt * getSubStmt()
Definition Expr.h:4548
unsigned getTemplateDepth() const
Definition Expr.h:4560
SourceLocation getRParenLoc() const
Definition Expr.h:4557
SourceLocation getLParenLoc() const
Definition Expr.h:4555
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:346
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1801
bool isPascal() const
Definition Expr.h:1924
tokloc_iterator tokloc_begin() const
Definition Expr.h:1967
tokloc_iterator tokloc_end() const
Definition Expr.h:1971
StringLiteralKind getKind() const
Definition Expr.h:1914
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:1877
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1942
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4658
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4703
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4709
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4707
SourceLocation getNameLoc() const
Definition ExprCXX.h:4693
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:1125
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:1144
Stmt * getInit()
Definition Stmt.h:2589
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2640
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3714
SourceRange getBraceRange() const
Definition Decl.h:3785
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3829
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4870
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3804
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3809
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:3962
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:3945
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4847
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4842
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:4884
TagKind getTagKind() const
Definition Decl.h:3908
void setBraceRange(SourceRange R)
Definition Decl.h:3786
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3812
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:104
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3685
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3703
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:223
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3544
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:6175
A container of type source information.
Definition TypeBase.h:8256
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:272
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8267
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2890
bool getBoolValue() const
Definition ExprCXX.h:2941
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2961
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:2966
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2952
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2933
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2965
const APValue & getAPValue() const
Definition ExprCXX.h:2946
bool isStoredAsBoolean() const
Definition ExprCXX.h:2937
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:8621
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:9051
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2436
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition TypeBase.h:2411
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9098
bool isRecordType() const
Definition TypeBase.h:8649
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3664
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3559
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3609
QualType getUnderlyingType() const
Definition Decl.h:3614
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2627
SourceLocation getRParenLoc() const
Definition Expr.h:2703
SourceLocation getOperatorLoc() const
Definition Expr.h:2700
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2673
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2659
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2246
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2291
Expr * getSubExpr() const
Definition Expr.h:2287
Opcode getOpcode() const
Definition Expr.h:2282
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2383
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2386
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:4974
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2300
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3384
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3458
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3453
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:4120
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4212
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4215
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4206
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4193
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:5980
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:4893
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:4917
SourceLocation getBuiltinLoc() const
Definition Expr.h:4920
SourceLocation getRParenLoc() const
Definition Expr.h:4923
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition Expr.h:4914
const Expr * getSubExpr() const
Definition Expr.h:4909
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:711
void setType(QualType newType)
Definition Decl.h:723
QualType getType() const
Definition Decl.h:722
Represents a variable declaration or definition.
Definition Decl.h:925
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:1568
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:1553
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:1557
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:1341
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1172
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1550
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1176
const Expr * getInit() const
Definition Decl.h:1367
void setConstexpr(bool IC)
Definition Decl.h:1571
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:1167
void setImplicitlyInline()
Definition Decl.h:1562
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:1357
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:3964
Represents a GCC generic vector type.
Definition TypeBase.h:4173
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:1205
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:1187
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
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:117
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:87
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:886
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:904
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:897
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5333
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5337
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5323
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5326
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5329
Extra information about a function prototype.
Definition TypeBase.h:5349
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