clang 24.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 if (auto *VD = dyn_cast<VarDecl>(D))
125 if (auto *TD = dyn_cast<TagDecl>(D))
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 // Use this to import pointers of specific type.
189 template <typename ImportT>
190 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
191 auto ToOrErr = Importer.Import(From);
192 if (ToOrErr)
193 To = cast_or_null<ImportT>(*ToOrErr);
194 return ToOrErr.takeError();
195 }
196
197 // Call the import function of ASTImporter for a baseclass of type `T` and
198 // cast the return value to `T`.
199 template <typename T>
200 auto import(T *From)
201 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203 auto ToOrErr = Importer.Import(From);
204 if (!ToOrErr)
205 return ToOrErr.takeError();
206 return cast_or_null<T>(*ToOrErr);
207 }
208
209 template <typename T>
210 auto import(const T *From) {
211 return import(const_cast<T *>(From));
212 }
213
214 // Call the import function of ASTImporter for type `T`.
215 template <typename T>
216 Expected<T> import(const T &From) {
217 return Importer.Import(From);
218 }
219
220 // Import an std::optional<T> by importing the contained T, if any.
221 template <typename T>
222 Expected<std::optional<T>> import(std::optional<T> From) {
223 if (!From)
224 return std::nullopt;
225 return import(*From);
226 }
227
228 ExplicitSpecifier importExplicitSpecifier(Error &Err,
229 ExplicitSpecifier ESpec);
230
231 // Wrapper for an overload set.
232 template <typename ToDeclT> struct CallOverloadedCreateFun {
233 template <typename... Args> decltype(auto) operator()(Args &&... args) {
234 return ToDeclT::Create(std::forward<Args>(args)...);
235 }
236 };
237
238 // Always use these functions to create a Decl during import. There are
239 // certain tasks which must be done after the Decl was created, e.g. we
240 // must immediately register that as an imported Decl. The parameter `ToD`
241 // will be set to the newly created Decl or if had been imported before
242 // then to the already imported Decl. Returns a bool value set to true if
243 // the `FromD` had been imported before.
244 template <typename ToDeclT, typename FromDeclT, typename... Args>
245 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
246 Args &&...args) {
247 // There may be several overloads of ToDeclT::Create. We must make sure
248 // to call the one which would be chosen by the arguments, thus we use a
249 // wrapper for the overload set.
250 CallOverloadedCreateFun<ToDeclT> OC;
251 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
252 std::forward<Args>(args)...);
253 }
254 // Use this overload if a special Type is needed to be created. E.g if we
255 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
256 // then:
257 // TypedefNameDecl *ToTypedef;
258 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
259 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
260 typename... Args>
261 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
262 Args &&...args) {
263 CallOverloadedCreateFun<NewDeclT> OC;
264 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
265 std::forward<Args>(args)...);
266 }
267 // Use this version if a special create function must be
268 // used, e.g. CXXRecordDecl::CreateLambda .
269 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
270 typename... Args>
271 [[nodiscard]] bool
272 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
273 FromDeclT *FromD, Args &&...args) {
274 if (Importer.getImportDeclErrorIfAny(FromD)) {
275 ToD = nullptr;
276 return true; // Already imported but with error.
277 }
278 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
279 if (ToD)
280 return true; // Already imported.
281 ToD = CreateFun(std::forward<Args>(args)...);
282 // Keep track of imported Decls.
283 Importer.RegisterImportedDecl(FromD, ToD);
284 Importer.SharedState->markAsNewDecl(ToD);
285 InitializeImportedDecl(FromD, ToD);
286 return false; // A new Decl is created.
287 }
288
289 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
290 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
291 if (FromD->isUsed())
292 ToD->setIsUsed();
293 if (FromD->isImplicit())
294 ToD->setImplicit();
295 }
296
297 // Check if we have found an existing definition. Returns with that
298 // definition if yes, otherwise returns null.
299 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
300 const FunctionDecl *Definition = nullptr;
302 FoundFunction->hasBody(Definition))
303 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
304 return nullptr;
305 }
306
307 void addDeclToContexts(Decl *FromD, Decl *ToD) {
308 if (Importer.isMinimalImport()) {
309 // In minimal import case the decl must be added even if it is not
310 // contained in original context, for LLDB compatibility.
311 // FIXME: Check if a better solution is possible.
312 if (!FromD->getDescribedTemplate() &&
313 FromD->getFriendObjectKind() == Decl::FOK_None)
315 return;
316 }
317
318 DeclContext *FromDC = FromD->getDeclContext();
319 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
320 DeclContext *ToDC = ToD->getDeclContext();
321 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
322
323 bool Visible = false;
324 if (FromDC->containsDeclAndLoad(FromD)) {
325 ToDC->addDeclInternal(ToD);
326 Visible = true;
327 }
328 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
329 ToLexicalDC->addDeclInternal(ToD);
330 Visible = true;
331 }
332
333 // If the Decl was added to any context, it was made already visible.
334 // Otherwise it is still possible that it should be visible.
335 if (!Visible) {
336 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
337 auto *ToNamed = cast<NamedDecl>(ToD);
338 DeclContextLookupResult FromLookup =
339 FromDC->lookup(FromNamed->getDeclName());
340 if (llvm::is_contained(FromLookup, FromNamed))
341 ToDC->makeDeclVisibleInContext(ToNamed);
342 }
343 }
344 }
345
346 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
347 DeclContext *OldDC) {
348 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
349 if (!LT)
350 return;
351
352 for (NamedDecl *TP : Params)
353 LT->update(TP, OldDC);
354 }
355
356 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
357 updateLookupTableForTemplateParameters(
358 Params, Importer.getToContext().getTranslationUnitDecl());
359 }
360
361 template <typename TemplateParmDeclT>
362 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
363 TemplateParmDeclT *ToD) {
364 if (D->hasDefaultArgument()) {
365 if (D->defaultArgumentWasInherited()) {
366 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
367 import(D->getDefaultArgStorage().getInheritedFrom());
368 if (!ToInheritedFromOrErr)
369 return ToInheritedFromOrErr.takeError();
370 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
371 if (!ToInheritedFrom->hasDefaultArgument()) {
372 // Resolve possible circular dependency between default value of the
373 // template argument and the template declaration.
374 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
375 import(D->getDefaultArgStorage()
376 .getInheritedFrom()
377 ->getDefaultArgument());
378 if (!ToInheritedDefaultArgOrErr)
379 return ToInheritedDefaultArgOrErr.takeError();
380 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
381 *ToInheritedDefaultArgOrErr);
382 }
383 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
384 ToInheritedFrom);
385 } else {
386 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
387 import(D->getDefaultArgument());
388 if (!ToDefaultArgOrErr)
389 return ToDefaultArgOrErr.takeError();
390 // Default argument could have been set in the
391 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
392 if (!ToD->hasDefaultArgument())
393 ToD->setDefaultArgument(Importer.getToContext(),
394 *ToDefaultArgOrErr);
395 }
396 }
397 return Error::success();
398 }
399
400 public:
401 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
402
406
407 // Importing types
409#define TYPE(Class, Base) \
410 ExpectedType Visit##Class##Type(const Class##Type *T);
411#include "clang/AST/TypeNodes.inc"
412
413 // Importing declarations
415 SourceLocation &Loc);
417 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
418 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
419 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
422 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
424 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
426
427 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
429 Expected<APValue> ImportAPValue(const APValue &FromValue);
430
432
433 /// What we should import from the definition.
435 /// Import the default subset of the definition, which might be
436 /// nothing (if minimal import is set) or might be everything (if minimal
437 /// import is not set).
439 /// Import everything.
441 /// Import only the bare bones needed to establish a valid
442 /// DeclContext.
444 };
445
447 return IDK == IDK_Everything ||
448 (IDK == IDK_Default && !Importer.isMinimalImport());
449 }
450
453 RecordDecl *From, RecordDecl *To,
456 EnumDecl *From, EnumDecl *To,
468
469 template <typename InContainerTy>
471 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
472
473 template<typename InContainerTy>
475 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
476 const InContainerTy &Container, TemplateArgumentListInfo &Result);
477
480 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
483 FunctionDecl *FromFD);
484
485 template <typename DeclTy>
486 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
487
489
491
493 ParmVarDecl *ToParam);
494
497
498 // Use for allocating string for newly imported object.
499 StringRef ImportASTStringRef(StringRef FromStr);
508
509 template <typename T>
511
512 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
513 bool IgnoreTemplateParmDepth = false);
562
565
584
585 // Importing statements
605 // FIXME: MSAsmStmt
606 // FIXME: SEHExceptStmt
607 // FIXME: SEHFinallyStmt
608 // FIXME: SEHTryStmt
609 // FIXME: SEHLeaveStmt
610 // FIXME: CapturedStmt
617 // FIXME: MSDependentExistsStmt
625
626 // Importing expressions
710
711 // Helper for chaining together multiple imports. If an error is detected,
712 // subsequent imports will return default constructed nodes, so that failure
713 // can be detected with a single conditional branch after a sequence of
714 // imports.
715 template <typename T> T importChecked(Error &Err, const T &From) {
716 // Don't attempt to import nodes if we hit an error earlier.
717 if (Err)
718 return T{};
719 Expected<T> MaybeVal = import(From);
720 if (!MaybeVal) {
721 Err = MaybeVal.takeError();
722 return T{};
723 }
724 return *MaybeVal;
725 }
726
727 template<typename IIter, typename OIter>
728 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
729 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
730 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
731 Expected<ItemT> ToOrErr = import(*Ibegin);
732 if (!ToOrErr)
733 return ToOrErr.takeError();
734 *Obegin = *ToOrErr;
735 }
736 return Error::success();
737 }
738
739 // Import every item from a container structure into an output container.
740 // If error occurs, stops at first error and returns the error.
741 // The output container should have space for all needed elements (it is not
742 // expanded, new items are put into from the beginning).
743 template<typename InContainerTy, typename OutContainerTy>
745 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
746 return ImportArrayChecked(
747 InContainer.begin(), InContainer.end(), OutContainer.begin());
748 }
749
750 template<typename InContainerTy, typename OIter>
751 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
752 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
753 }
754
756 CXXMethodDecl *FromMethod);
757
760 };
761
762template <typename InContainerTy>
764 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
765 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
766 auto ToLAngleLocOrErr = import(FromLAngleLoc);
767 if (!ToLAngleLocOrErr)
768 return ToLAngleLocOrErr.takeError();
769 auto ToRAngleLocOrErr = import(FromRAngleLoc);
770 if (!ToRAngleLocOrErr)
771 return ToRAngleLocOrErr.takeError();
772
773 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
774 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
775 return Err;
776 Result = std::move(ToTAInfo);
777 return Error::success();
778}
779
780template <>
786
787template <>
795
798 FunctionDecl *FromFD) {
799 assert(FromFD->getTemplatedKind() ==
801
803
804 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
805 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
806 return std::move(Err);
807
808 // Import template arguments.
809 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
810 std::get<1>(Result)))
811 return std::move(Err);
812
813 return Result;
814}
815
816template <>
818ASTNodeImporter::import(TemplateParameterList *From) {
820 if (Error Err = ImportContainerChecked(*From, To))
821 return std::move(Err);
822
823 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
824 if (!ToRequiresClause)
825 return ToRequiresClause.takeError();
826
827 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
828 if (!ToTemplateLocOrErr)
829 return ToTemplateLocOrErr.takeError();
830 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
831 if (!ToLAngleLocOrErr)
832 return ToLAngleLocOrErr.takeError();
833 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
834 if (!ToRAngleLocOrErr)
835 return ToRAngleLocOrErr.takeError();
836
838 Importer.getToContext(),
839 *ToTemplateLocOrErr,
840 *ToLAngleLocOrErr,
841 To,
842 *ToRAngleLocOrErr,
843 *ToRequiresClause);
844}
845
846template <>
848ASTNodeImporter::import(const TemplateArgument &From) {
849 switch (From.getKind()) {
851 return TemplateArgument();
852
854 ExpectedType ToTypeOrErr = import(From.getAsType());
855 if (!ToTypeOrErr)
856 return ToTypeOrErr.takeError();
857 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
858 From.getIsDefaulted());
859 }
860
862 ExpectedType ToTypeOrErr = import(From.getIntegralType());
863 if (!ToTypeOrErr)
864 return ToTypeOrErr.takeError();
865 return TemplateArgument(From, *ToTypeOrErr);
866 }
867
869 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
870 if (!ToOrErr)
871 return ToOrErr.takeError();
872 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
873 if (!ToTypeOrErr)
874 return ToTypeOrErr.takeError();
875 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
876 *ToTypeOrErr, From.getIsDefaulted());
877 }
878
880 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
881 if (!ToTypeOrErr)
882 return ToTypeOrErr.takeError();
883 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
884 From.getIsDefaulted());
885 }
886
888 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
889 if (!ToTypeOrErr)
890 return ToTypeOrErr.takeError();
891 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
892 if (!ToValueOrErr)
893 return ToValueOrErr.takeError();
894 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
895 *ToValueOrErr);
896 }
897
899 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
900 if (!ToTemplateOrErr)
901 return ToTemplateOrErr.takeError();
902
903 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
904 }
905
907 Expected<TemplateName> ToTemplateOrErr =
908 import(From.getAsTemplateOrTemplatePattern());
909 if (!ToTemplateOrErr)
910 return ToTemplateOrErr.takeError();
911
912 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
913 From.getIsDefaulted());
914 }
915
917 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
918 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
919 From.getIsDefaulted());
920 else
921 return ToExpr.takeError();
922
925 ToPack.reserve(From.pack_size());
926 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
927 return std::move(Err);
928
929 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
930 }
931 }
932
933 llvm_unreachable("Invalid template argument kind");
934}
935
936template <>
938ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
939 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
940 if (!ArgOrErr)
941 return ArgOrErr.takeError();
942 TemplateArgument Arg = *ArgOrErr;
943
944 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
945
948 ExpectedExpr E = import(FromInfo.getAsExpr());
949 if (!E)
950 return E.takeError();
951 ToInfo = TemplateArgumentLocInfo(*E);
952 } else if (Arg.getKind() == TemplateArgument::Type) {
953 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
954 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
955 else
956 return TSIOrErr.takeError();
957 } else {
958 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
959 if (!ToTemplateKWLocOrErr)
960 return ToTemplateKWLocOrErr.takeError();
961 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
962 if (!ToTemplateQualifierLocOrErr)
963 return ToTemplateQualifierLocOrErr.takeError();
964 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
965 if (!ToTemplateNameLocOrErr)
966 return ToTemplateNameLocOrErr.takeError();
967 auto ToTemplateEllipsisLocOrErr =
968 import(FromInfo.getTemplateEllipsisLoc());
969 if (!ToTemplateEllipsisLocOrErr)
970 return ToTemplateEllipsisLocOrErr.takeError();
972 Importer.getToContext(), *ToTemplateKWLocOrErr,
973 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
974 *ToTemplateEllipsisLocOrErr);
975 }
976
977 return TemplateArgumentLoc(Arg, ToInfo);
978}
979
980template <>
981Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
982 if (DG.isNull())
983 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
984 size_t NumDecls = DG.end() - DG.begin();
986 ToDecls.reserve(NumDecls);
987 for (Decl *FromD : DG) {
988 if (auto ToDOrErr = import(FromD))
989 ToDecls.push_back(*ToDOrErr);
990 else
991 return ToDOrErr.takeError();
992 }
993 return DeclGroupRef::Create(Importer.getToContext(),
994 ToDecls.begin(),
995 NumDecls);
996}
997
998template <>
1000ASTNodeImporter::import(const Designator &D) {
1001 if (D.isFieldDesignator()) {
1002 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
1003
1004 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
1005 if (!ToDotLocOrErr)
1006 return ToDotLocOrErr.takeError();
1007
1008 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1009 if (!ToFieldLocOrErr)
1010 return ToFieldLocOrErr.takeError();
1011
1013 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1014 }
1015
1016 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1017 if (!ToLBracketLocOrErr)
1018 return ToLBracketLocOrErr.takeError();
1019
1020 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1021 if (!ToRBracketLocOrErr)
1022 return ToRBracketLocOrErr.takeError();
1023
1024 if (D.isArrayDesignator())
1026 *ToLBracketLocOrErr,
1027 *ToRBracketLocOrErr);
1028
1029 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1030 if (!ToEllipsisLocOrErr)
1031 return ToEllipsisLocOrErr.takeError();
1032
1033 assert(D.isArrayRangeDesignator());
1035 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1036 *ToRBracketLocOrErr);
1037}
1038
1039template <>
1040Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1041 Error Err = Error::success();
1042 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1043 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1044 auto ToConceptNameLoc =
1045 importChecked(Err, From->getConceptNameInfo().getLoc());
1046 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1047 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1048 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1049 if (Err)
1050 return std::move(Err);
1051 TemplateArgumentListInfo ToTAInfo;
1052 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1053 if (ASTTemplateArgs)
1054 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1055 return std::move(Err);
1056 auto *ConceptRef = ConceptReference::Create(
1057 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1058 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1059 ToNamedConcept,
1060 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1061 Importer.getToContext(), ToTAInfo)
1062 : nullptr);
1063 return ConceptRef;
1064}
1065
1066StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1067 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1068 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1069 return StringRef(ToStore, FromStr.size());
1070}
1071
1073 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1074 ToSat.IsSatisfied = FromSat.IsSatisfied;
1075 ToSat.ContainsErrors = FromSat.ContainsErrors;
1076 if (!ToSat.IsSatisfied) {
1077 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1078 if (const Expr *E = Record->dyn_cast<const Expr *>()) {
1079 ExpectedExpr ToSecondExpr = import(E);
1080 if (!ToSecondExpr)
1081 return ToSecondExpr.takeError();
1082 ToSat.Details.emplace_back(ToSecondExpr.get());
1083 } else if (auto CR = Record->dyn_cast<const ConceptReference *>()) {
1084 Expected<ConceptReference *> ToCROrErr = import(CR);
1085 if (!ToCROrErr)
1086 return ToCROrErr.takeError();
1087 ToSat.Details.emplace_back(ToCROrErr.get());
1088 } else {
1089 auto Pair =
1090 Record->dyn_cast<const ConstraintSubstitutionDiagnostic *>();
1091
1092 ExpectedSLoc ToPairFirst = import(Pair->first);
1093 if (!ToPairFirst)
1094 return ToPairFirst.takeError();
1095 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1096 ToSat.Details.emplace_back(new (Importer.getToContext())
1098 ToPairFirst.get(), ToPairSecond});
1099 }
1100 }
1101 }
1102 return Error::success();
1103}
1104
1105template <>
1107ASTNodeImporter::import(
1109 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1110 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1111 if (!ToLoc)
1112 return ToLoc.takeError();
1113 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1114 return new (Importer.getToContext())
1116 ToDiagMessage};
1117}
1118
1121 using namespace concepts;
1122
1123 if (From->isSubstitutionFailure()) {
1124 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1125 if (!DiagOrErr)
1126 return DiagOrErr.takeError();
1127 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1128 } else {
1129 Expected<TypeSourceInfo *> ToType = import(From->getType());
1130 if (!ToType)
1131 return ToType.takeError();
1132 return new (Importer.getToContext()) TypeRequirement(*ToType);
1133 }
1134}
1135
1138 using namespace concepts;
1139
1140 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1141 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1142
1143 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1144 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1145
1146 if (IsRKSimple) {
1147 Req.emplace();
1148 } else {
1149 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1151
1152 if (FromTypeRequirement.isTypeConstraint()) {
1153 const bool IsDependent = FromTypeRequirement.isDependent();
1154 auto ParamsOrErr =
1155 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1156 if (!ParamsOrErr)
1157 return ParamsOrErr.takeError();
1158 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1159 auto SubstConstraintExprOrErr =
1161 if (!SubstConstraintExprOrErr)
1162 return SubstConstraintExprOrErr.takeError();
1163 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1164 }
1165 Req.emplace(ParamsOrErr.get(), IsDependent);
1166 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1167 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1168 if (!DiagOrErr)
1169 return DiagOrErr.takeError();
1170 Req.emplace(DiagOrErr.get());
1171 } else {
1172 Req.emplace();
1173 }
1174 }
1175
1176 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1177 if (!NoexceptLocOrErr)
1178 return NoexceptLocOrErr.takeError();
1179
1180 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1181 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1182 if (!DiagOrErr)
1183 return DiagOrErr.takeError();
1184 return new (Importer.getToContext()) ExprRequirement(
1185 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1186 } else {
1187 Expected<Expr *> ExprOrErr = import(From->getExpr());
1188 if (!ExprOrErr)
1189 return ExprOrErr.takeError();
1190 return new (Importer.getToContext()) concepts::ExprRequirement(
1191 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1192 SubstitutedConstraintExpr);
1193 }
1194}
1195
1198 using namespace concepts;
1199
1200 const ASTConstraintSatisfaction &FromSatisfaction =
1202 if (From->hasInvalidConstraint()) {
1203 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1204 ASTConstraintSatisfaction *ToSatisfaction =
1205 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1206 FromSatisfaction);
1207 return new (Importer.getToContext())
1208 NestedRequirement(ToEntity, ToSatisfaction);
1209 } else {
1210 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1211 if (!ToExpr)
1212 return ToExpr.takeError();
1213 if (ToExpr.get()->isInstantiationDependent()) {
1214 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1215 } else {
1216 ConstraintSatisfaction Satisfaction;
1217 if (Error Err =
1218 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1219 return std::move(Err);
1220 return new (Importer.getToContext()) NestedRequirement(
1221 Importer.getToContext(), ToExpr.get(), Satisfaction);
1222 }
1223 }
1224}
1225
1226template <>
1228ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1229 switch (FromRequire->getKind()) {
1238 }
1239 llvm_unreachable("Unhandled requirement kind");
1240}
1241
1242template <>
1243Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1244 ValueDecl *Var = nullptr;
1245 if (From.capturesVariable()) {
1246 if (auto VarOrErr = import(From.getCapturedVar()))
1247 Var = *VarOrErr;
1248 else
1249 return VarOrErr.takeError();
1250 }
1251
1252 auto LocationOrErr = import(From.getLocation());
1253 if (!LocationOrErr)
1254 return LocationOrErr.takeError();
1255
1256 SourceLocation EllipsisLoc;
1257 if (From.isPackExpansion())
1258 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1259 return std::move(Err);
1260
1261 return LambdaCapture(
1262 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1263 EllipsisLoc);
1264}
1265
1266template <typename T>
1268 if (Found->getLinkageInternal() != From->getLinkageInternal())
1269 return false;
1270
1271 if (From->hasExternalFormalLinkage())
1272 return Found->hasExternalFormalLinkage();
1273 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1274 return false;
1275 if (From->isInAnonymousNamespace())
1276 return Found->isInAnonymousNamespace();
1277 else
1278 return !Found->isInAnonymousNamespace() &&
1279 !Found->hasExternalFormalLinkage();
1280}
1281
1282template <>
1284 TypedefNameDecl *From) {
1285 if (Found->getLinkageInternal() != From->getLinkageInternal())
1286 return false;
1287
1288 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1289 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1290 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1291}
1292
1293} // namespace clang
1294
1295//----------------------------------------------------------------------------
1296// Import Types
1297//----------------------------------------------------------------------------
1298
1299using namespace clang;
1300
1302 const FunctionDecl *D) {
1303 const FunctionDecl *LambdaD = nullptr;
1304 if (!isCycle(D) && D) {
1305 FunctionDeclsWithImportInProgress.insert(D);
1306 LambdaD = D;
1307 }
1308 return llvm::scope_exit([this, LambdaD]() {
1309 if (LambdaD) {
1310 FunctionDeclsWithImportInProgress.erase(LambdaD);
1311 }
1312 });
1313}
1314
1316 const FunctionDecl *D) const {
1317 return FunctionDeclsWithImportInProgress.find(D) !=
1318 FunctionDeclsWithImportInProgress.end();
1319}
1320
1322 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1323 << T->getTypeClassName();
1324 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1325}
1326
1327ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1328 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1329 if (!UnderlyingTypeOrErr)
1330 return UnderlyingTypeOrErr.takeError();
1331
1332 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1333}
1334
1335ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1336 switch (T->getKind()) {
1337#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1338 case BuiltinType::Id: \
1339 return Importer.getToContext().SingletonId;
1340#include "clang/Basic/OpenCLImageTypes.def"
1341#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1342 case BuiltinType::Id: \
1343 return Importer.getToContext().Id##Ty;
1344#include "clang/Basic/OpenCLExtensionTypes.def"
1345#define SVE_TYPE(Name, Id, SingletonId) \
1346 case BuiltinType::Id: \
1347 return Importer.getToContext().SingletonId;
1348#include "clang/Basic/AArch64ACLETypes.def"
1349#define PPC_VECTOR_TYPE(Name, Id, Size) \
1350 case BuiltinType::Id: \
1351 return Importer.getToContext().Id##Ty;
1352#include "clang/Basic/PPCTypes.def"
1353#define RVV_TYPE(Name, Id, SingletonId) \
1354 case BuiltinType::Id: \
1355 return Importer.getToContext().SingletonId;
1356#include "clang/Basic/RISCVVTypes.def"
1357#define WASM_TYPE(Name, Id, SingletonId) \
1358 case BuiltinType::Id: \
1359 return Importer.getToContext().SingletonId;
1360#include "clang/Basic/WebAssemblyReferenceTypes.def"
1361#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1362 case BuiltinType::Id: \
1363 return Importer.getToContext().SingletonId;
1364#include "clang/Basic/AMDGPUTypes.def"
1365#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1366 case BuiltinType::Id: \
1367 return Importer.getToContext().SingletonId;
1368#include "clang/Basic/HLSLIntangibleTypes.def"
1369#define SPIRV_TYPE(Name, Id, SingletonId) \
1370 case BuiltinType::Id: \
1371 return Importer.getToContext().SingletonId;
1372#include "clang/Basic/SPIRVTypes.def"
1373#define SHARED_SINGLETON_TYPE(Expansion)
1374#define BUILTIN_TYPE(Id, SingletonId) \
1375 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1376#include "clang/AST/BuiltinTypes.def"
1377
1378 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1379 // context supports C++.
1380
1381 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1382 // context supports ObjC.
1383
1384 case BuiltinType::Char_U:
1385 // The context we're importing from has an unsigned 'char'. If we're
1386 // importing into a context with a signed 'char', translate to
1387 // 'unsigned char' instead.
1388 if (Importer.getToContext().getLangOpts().CharIsSigned)
1389 return Importer.getToContext().UnsignedCharTy;
1390
1391 return Importer.getToContext().CharTy;
1392
1393 case BuiltinType::Char_S:
1394 // The context we're importing from has an unsigned 'char'. If we're
1395 // importing into a context with a signed 'char', translate to
1396 // 'unsigned char' instead.
1397 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1398 return Importer.getToContext().SignedCharTy;
1399
1400 return Importer.getToContext().CharTy;
1401
1402 case BuiltinType::WChar_S:
1403 case BuiltinType::WChar_U:
1404 // FIXME: If not in C++, shall we translate to the C equivalent of
1405 // wchar_t?
1406 return Importer.getToContext().WCharTy;
1407 }
1408
1409 llvm_unreachable("Invalid BuiltinType Kind!");
1410}
1411
1412ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1413 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1414 if (!ToOriginalTypeOrErr)
1415 return ToOriginalTypeOrErr.takeError();
1416
1417 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1418}
1419
1420ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1421 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1422 if (!ToElementTypeOrErr)
1423 return ToElementTypeOrErr.takeError();
1424
1425 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1426}
1427
1428ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1429 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1430 if (!ToPointeeTypeOrErr)
1431 return ToPointeeTypeOrErr.takeError();
1432
1433 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1434}
1435
1436ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1437 // FIXME: Check for blocks support in "to" context.
1438 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1439 if (!ToPointeeTypeOrErr)
1440 return ToPointeeTypeOrErr.takeError();
1441
1442 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1443}
1444
1446ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1447 // FIXME: Check for C++ support in "to" context.
1448 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1449 if (!ToPointeeTypeOrErr)
1450 return ToPointeeTypeOrErr.takeError();
1451
1452 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1453}
1454
1456ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1457 // FIXME: Check for C++0x support in "to" context.
1458 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1459 if (!ToPointeeTypeOrErr)
1460 return ToPointeeTypeOrErr.takeError();
1461
1462 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1463}
1464
1466ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1467 // FIXME: Check for C++ support in "to" context.
1468 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1469 if (!ToPointeeTypeOrErr)
1470 return ToPointeeTypeOrErr.takeError();
1471
1472 auto QualifierOrErr = import(T->getQualifier());
1473 if (!QualifierOrErr)
1474 return QualifierOrErr.takeError();
1475
1476 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1477 if (!ClsOrErr)
1478 return ClsOrErr.takeError();
1479
1480 return Importer.getToContext().getMemberPointerType(
1481 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1482}
1483
1485ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1486 Error Err = Error::success();
1487 auto ToElementType = importChecked(Err, T->getElementType());
1488 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1489 if (Err)
1490 return std::move(Err);
1491
1492 return Importer.getToContext().getConstantArrayType(
1493 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1494 T->getIndexTypeCVRQualifiers());
1495}
1496
1498ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1499 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1500 if (!ToArrayTypeOrErr)
1501 return ToArrayTypeOrErr.takeError();
1502
1503 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1504}
1505
1507ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1508 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1509 if (!ToElementTypeOrErr)
1510 return ToElementTypeOrErr.takeError();
1511
1512 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1513 T->getSizeModifier(),
1514 T->getIndexTypeCVRQualifiers());
1515}
1516
1518ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1519 Error Err = Error::success();
1520 QualType ToElementType = importChecked(Err, T->getElementType());
1521 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1522 if (Err)
1523 return std::move(Err);
1524 return Importer.getToContext().getVariableArrayType(
1525 ToElementType, ToSizeExpr, T->getSizeModifier(),
1526 T->getIndexTypeCVRQualifiers());
1527}
1528
1529ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1530 const DependentSizedArrayType *T) {
1531 Error Err = Error::success();
1532 QualType ToElementType = importChecked(Err, T->getElementType());
1533 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1534 if (Err)
1535 return std::move(Err);
1536 // SizeExpr may be null if size is not specified directly.
1537 // For example, 'int a[]'.
1538
1539 return Importer.getToContext().getDependentSizedArrayType(
1540 ToElementType, ToSizeExpr, T->getSizeModifier(),
1541 T->getIndexTypeCVRQualifiers());
1542}
1543
1544ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1545 const DependentSizedExtVectorType *T) {
1546 Error Err = Error::success();
1547 QualType ToElementType = importChecked(Err, T->getElementType());
1548 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1549 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1550 if (Err)
1551 return std::move(Err);
1552 return Importer.getToContext().getDependentSizedExtVectorType(
1553 ToElementType, ToSizeExpr, ToAttrLoc);
1554}
1555
1556ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1557 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1558 if (!ToElementTypeOrErr)
1559 return ToElementTypeOrErr.takeError();
1560
1561 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1562 T->getNumElements(),
1563 T->getVectorKind());
1564}
1565
1566ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1567 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1568 if (!ToElementTypeOrErr)
1569 return ToElementTypeOrErr.takeError();
1570
1571 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1572 T->getNumElements());
1573}
1574
1576ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1577 // FIXME: What happens if we're importing a function without a prototype
1578 // into C++? Should we make it variadic?
1579 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1580 if (!ToReturnTypeOrErr)
1581 return ToReturnTypeOrErr.takeError();
1582
1583 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1584 T->getExtInfo());
1585}
1586
1588ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1589 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1590 if (!ToReturnTypeOrErr)
1591 return ToReturnTypeOrErr.takeError();
1592
1593 // Import argument types
1594 SmallVector<QualType, 4> ArgTypes;
1595 for (const auto &A : T->param_types()) {
1596 ExpectedType TyOrErr = import(A);
1597 if (!TyOrErr)
1598 return TyOrErr.takeError();
1599 ArgTypes.push_back(*TyOrErr);
1600 }
1601
1602 // Import exception types
1603 SmallVector<QualType, 4> ExceptionTypes;
1604 for (const auto &E : T->exceptions()) {
1605 ExpectedType TyOrErr = import(E);
1606 if (!TyOrErr)
1607 return TyOrErr.takeError();
1608 ExceptionTypes.push_back(*TyOrErr);
1609 }
1610
1611 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
1612 Error Err = Error::success();
1613 FunctionProtoType::ExtProtoInfo ToEPI;
1614 ToEPI.ExtInfo = FromEPI.ExtInfo;
1615 ToEPI.Variadic = FromEPI.Variadic;
1616 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1617 ToEPI.TypeQuals = FromEPI.TypeQuals;
1618 ToEPI.RefQualifier = FromEPI.RefQualifier;
1619 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1621 importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr);
1623 importChecked(Err, FromEPI.ExceptionSpec.SourceDecl);
1625 importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate);
1626 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1627
1628 if (Err)
1629 return std::move(Err);
1630
1631 return Importer.getToContext().getFunctionType(
1632 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1633}
1634
1635ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1636 const UnresolvedUsingType *T) {
1637 Error Err = Error::success();
1638 auto ToQualifier = importChecked(Err, T->getQualifier());
1639 auto *ToD = importChecked(Err, T->getDecl());
1640 if (Err)
1641 return std::move(Err);
1642
1644 return Importer.getToContext().getCanonicalUnresolvedUsingType(ToD);
1645 return Importer.getToContext().getUnresolvedUsingType(T->getKeyword(),
1646 ToQualifier, ToD);
1647}
1648
1649ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1650 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1651 if (!ToInnerTypeOrErr)
1652 return ToInnerTypeOrErr.takeError();
1653
1654 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1655}
1656
1658ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1659
1660 ExpectedType Pattern = import(T->getPattern());
1661 if (!Pattern)
1662 return Pattern.takeError();
1663 ExpectedExpr Index = import(T->getIndexExpr());
1664 if (!Index)
1665 return Index.takeError();
1666 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1667}
1668
1669ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1670 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1671 if (!ToDeclOrErr)
1672 return ToDeclOrErr.takeError();
1673
1674 auto ToQualifierOrErr = import(T->getQualifier());
1675 if (!ToQualifierOrErr)
1676 return ToQualifierOrErr.takeError();
1677
1678 ExpectedType ToUnderlyingTypeOrErr =
1679 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1680 if (!ToUnderlyingTypeOrErr)
1681 return ToUnderlyingTypeOrErr.takeError();
1682
1683 return Importer.getToContext().getTypedefType(
1684 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1685}
1686
1687ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1688 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1689 if (!ToExprOrErr)
1690 return ToExprOrErr.takeError();
1691 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1692}
1693
1694ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1695 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1696 if (!ToUnderlyingTypeOrErr)
1697 return ToUnderlyingTypeOrErr.takeError();
1698 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1699 T->getKind());
1700}
1701
1702ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1703 Error Err = Error::success();
1704 auto ToQualifier = importChecked(Err, T->getQualifier());
1705 auto *ToD = importChecked(Err, T->getDecl());
1706 QualType ToT = importChecked(Err, T->desugar());
1707 if (Err)
1708 return std::move(Err);
1709 return Importer.getToContext().getUsingType(T->getKeyword(), ToQualifier, ToD,
1710 ToT);
1711}
1712
1713ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1714 // FIXME: Make sure that the "to" context supports C++0x!
1715 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1716 if (!ToExprOrErr)
1717 return ToExprOrErr.takeError();
1718
1719 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1720 if (!ToUnderlyingTypeOrErr)
1721 return ToUnderlyingTypeOrErr.takeError();
1722
1723 return Importer.getToContext().getDecltypeType(
1724 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1725}
1726
1728ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1729 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1730 if (!ToBaseTypeOrErr)
1731 return ToBaseTypeOrErr.takeError();
1732
1733 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1734 if (!ToUnderlyingTypeOrErr)
1735 return ToUnderlyingTypeOrErr.takeError();
1736
1737 return Importer.getToContext().getUnaryTransformType(
1738 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1739}
1740
1741ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1742 // FIXME: Make sure that the "to" context supports C++11!
1743 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1744 if (!ToDeducedTypeOrErr)
1745 return ToDeducedTypeOrErr.takeError();
1746
1747 Expected<TemplateDecl *> ToTypeConstraint =
1748 import(T->getTypeConstraintConcept());
1749 if (!ToTypeConstraint)
1750 return ToTypeConstraint.takeError();
1751
1752 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1753 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1754 ToTemplateArgs))
1755 return std::move(Err);
1756
1757 return Importer.getToContext().getAutoType(
1758 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1759 *ToTypeConstraint, ToTemplateArgs);
1760}
1761
1762ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1763 const DeducedTemplateSpecializationType *T) {
1764 // FIXME: Make sure that the "to" context supports C++17!
1765 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1766 if (!ToTemplateNameOrErr)
1767 return ToTemplateNameOrErr.takeError();
1768 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1769 if (!ToDeducedTypeOrErr)
1770 return ToDeducedTypeOrErr.takeError();
1771
1772 return Importer.getToContext().getDeducedTemplateSpecializationType(
1773 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1774 *ToTemplateNameOrErr);
1775}
1776
1777ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1778 TagDecl *DeclForType = T->getDecl();
1779 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1780 if (!ToDeclOrErr)
1781 return ToDeclOrErr.takeError();
1782
1783 // If there is a definition of the 'OriginalDecl', it should be imported to
1784 // have all information for the type in the "To" AST. (In some cases no
1785 // other reference may exist to the definition decl and it would not be
1786 // imported otherwise.)
1787 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1788 if (!ToDefDeclOrErr)
1789 return ToDefDeclOrErr.takeError();
1790
1792 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1793
1794 auto ToQualifierOrErr = import(T->getQualifier());
1795 if (!ToQualifierOrErr)
1796 return ToQualifierOrErr.takeError();
1797
1798 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1799 *ToDeclOrErr, T->isTagOwned());
1800}
1801
1802ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1803 return VisitTagType(T);
1804}
1805
1806ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1807 return VisitTagType(T);
1808}
1809
1811ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1812 return VisitTagType(T);
1813}
1814
1815ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1816 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1817 if (!ToModifiedTypeOrErr)
1818 return ToModifiedTypeOrErr.takeError();
1819 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1820 if (!ToEquivalentTypeOrErr)
1821 return ToEquivalentTypeOrErr.takeError();
1822
1823 return Importer.getToContext().getAttributedType(
1824 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1825 T->getAttr());
1826}
1827
1829ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1830 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1831 if (!ToWrappedTypeOrErr)
1832 return ToWrappedTypeOrErr.takeError();
1833
1834 Error Err = Error::success();
1835 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1836
1837 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1838 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1839 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1840 if (!ToDeclOrErr)
1841 return ToDeclOrErr.takeError();
1842 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1843 }
1844
1845 return Importer.getToContext().getCountAttributedType(
1846 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1847 ArrayRef(CoupledDecls));
1848}
1849
1851ASTNodeImporter::VisitLateParsedAttrType(const LateParsedAttrType *T) {
1852 llvm_unreachable("should be replaced with a concrete type before AST import");
1853}
1854
1855ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1856 const TemplateTypeParmType *T) {
1857 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1858 if (!ToDeclOrErr)
1859 return ToDeclOrErr.takeError();
1860
1861 return Importer.getToContext().getTemplateTypeParmType(
1862 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1863}
1864
1865ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1866 const SubstTemplateTypeParmType *T) {
1867 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1868 if (!ReplacedOrErr)
1869 return ReplacedOrErr.takeError();
1870
1871 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1872 if (!ToReplacementTypeOrErr)
1873 return ToReplacementTypeOrErr.takeError();
1874
1875 return Importer.getToContext().getSubstTemplateTypeParmType(
1876 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1877 T->getFinal());
1878}
1879
1880ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1881 const SubstTemplateTypeParmPackType *T) {
1882 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1883 if (!ReplacedOrErr)
1884 return ReplacedOrErr.takeError();
1885
1886 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1887 if (!ToArgumentPack)
1888 return ToArgumentPack.takeError();
1889
1890 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1891 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1892}
1893
1894ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1895 const SubstBuiltinTemplatePackType *T) {
1896 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1897 if (!ToArgumentPack)
1898 return ToArgumentPack.takeError();
1899 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1900}
1901
1902ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1903 const TemplateSpecializationType *T) {
1904 auto ToTemplateOrErr = import(T->getTemplateName());
1905 if (!ToTemplateOrErr)
1906 return ToTemplateOrErr.takeError();
1907
1908 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1909 if (Error Err =
1910 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1911 return std::move(Err);
1912
1913 ExpectedType ToUnderlyingOrErr =
1914 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1915 if (!ToUnderlyingOrErr)
1916 return ToUnderlyingOrErr.takeError();
1917 return Importer.getToContext().getTemplateSpecializationType(
1918 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1919 *ToUnderlyingOrErr);
1920}
1921
1923ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1924 ExpectedType ToPatternOrErr = import(T->getPattern());
1925 if (!ToPatternOrErr)
1926 return ToPatternOrErr.takeError();
1927
1928 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1929 T->getNumExpansions(),
1930 /*ExpactPack=*/false);
1931}
1932
1934ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1935 auto ToQualifierOrErr = import(T->getQualifier());
1936 if (!ToQualifierOrErr)
1937 return ToQualifierOrErr.takeError();
1938
1939 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1940 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1941 *ToQualifierOrErr, Name);
1942}
1943
1945ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1946 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1947 if (!ToDeclOrErr)
1948 return ToDeclOrErr.takeError();
1949
1950 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1951}
1952
1953ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1954 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1955 if (!ToBaseTypeOrErr)
1956 return ToBaseTypeOrErr.takeError();
1957
1958 SmallVector<QualType, 4> TypeArgs;
1959 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1960 if (ExpectedType TyOrErr = import(TypeArg))
1961 TypeArgs.push_back(*TyOrErr);
1962 else
1963 return TyOrErr.takeError();
1964 }
1965
1966 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1967 for (auto *P : T->quals()) {
1968 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1969 Protocols.push_back(*ProtocolOrErr);
1970 else
1971 return ProtocolOrErr.takeError();
1972
1973 }
1974
1975 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1976 Protocols,
1977 T->isKindOfTypeAsWritten());
1978}
1979
1981ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1982 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1983 if (!ToPointeeTypeOrErr)
1984 return ToPointeeTypeOrErr.takeError();
1985
1986 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1987}
1988
1990ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1991 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1992 if (!ToUnderlyingTypeOrErr)
1993 return ToUnderlyingTypeOrErr.takeError();
1994
1995 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1996 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1997 ToIdentifier);
1998}
1999
2000ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
2001 Error Err = Error::success();
2002 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
2003 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
2004 if (Err)
2005 return std::move(Err);
2006
2007 return Importer.getToContext().getAdjustedType(ToOriginalType,
2008 ToAdjustedType);
2009}
2010
2011ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
2012 return Importer.getToContext().getBitIntType(T->isUnsigned(),
2013 T->getNumBits());
2014}
2015
2016ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
2017 const clang::BTFTagAttributedType *T) {
2018 Error Err = Error::success();
2019 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
2020 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2021 if (Err)
2022 return std::move(Err);
2023
2024 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
2025 ToWrappedType);
2026}
2027
2028ExpectedType clang::ASTNodeImporter::VisitOverflowBehaviorType(
2029 const clang::OverflowBehaviorType *T) {
2030 Error Err = Error::success();
2031 OverflowBehaviorType::OverflowBehaviorKind ToKind = T->getBehaviorKind();
2032 QualType ToUnderlyingType = importChecked(Err, T->getUnderlyingType());
2033 if (Err)
2034 return std::move(Err);
2035
2036 return Importer.getToContext().getOverflowBehaviorType(ToKind,
2038}
2039
2040ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2041 const clang::HLSLAttributedResourceType *T) {
2042 Error Err = Error::success();
2043 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
2044 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2045 QualType ToContainedType = importChecked(Err, T->getContainedType());
2046 if (Err)
2047 return std::move(Err);
2048
2049 return Importer.getToContext().getHLSLAttributedResourceType(
2050 ToWrappedType, ToContainedType, ToAttrs);
2051}
2052
2053ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2054 const clang::HLSLInlineSpirvType *T) {
2055 Error Err = Error::success();
2056
2057 uint32_t ToOpcode = T->getOpcode();
2058 uint32_t ToSize = T->getSize();
2059 uint32_t ToAlignment = T->getAlignment();
2060
2061 llvm::SmallVector<SpirvOperand> ToOperands;
2062
2063 for (auto &Operand : T->getOperands()) {
2064 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2065
2066 switch (Operand.getKind()) {
2067 case SpirvOperandKind::ConstantId:
2068 ToOperands.push_back(SpirvOperand::createConstant(
2069 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2070 break;
2071 case SpirvOperandKind::Literal:
2072 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2073 break;
2074 case SpirvOperandKind::TypeId:
2075 ToOperands.push_back(SpirvOperand::createType(
2076 importChecked(Err, Operand.getResultType())));
2077 break;
2078 default:
2079 llvm_unreachable("Invalid SpirvOperand kind");
2080 }
2081
2082 if (Err)
2083 return std::move(Err);
2084 }
2085
2086 return Importer.getToContext().getHLSLInlineSpirvType(
2087 ToOpcode, ToSize, ToAlignment, ToOperands);
2088}
2089
2090ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2091 const clang::ConstantMatrixType *T) {
2092 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2093 if (!ToElementTypeOrErr)
2094 return ToElementTypeOrErr.takeError();
2095
2096 return Importer.getToContext().getConstantMatrixType(
2097 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2098}
2099
2100ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2101 const clang::DependentAddressSpaceType *T) {
2102 Error Err = Error::success();
2103 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2104 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2105 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2106 if (Err)
2107 return std::move(Err);
2108
2109 return Importer.getToContext().getDependentAddressSpaceType(
2110 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2111}
2112
2113ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2114 const clang::DependentBitIntType *T) {
2115 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2116 if (!ToNumBitsExprOrErr)
2117 return ToNumBitsExprOrErr.takeError();
2118 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2119 *ToNumBitsExprOrErr);
2120}
2121
2122ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2123 const clang::PredefinedSugarType *T) {
2124 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2125}
2126
2127ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2128 const clang::DependentSizedMatrixType *T) {
2129 Error Err = Error::success();
2130 QualType ToElementType = importChecked(Err, T->getElementType());
2131 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2132 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2133 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2134 if (Err)
2135 return std::move(Err);
2136
2137 return Importer.getToContext().getDependentSizedMatrixType(
2138 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2139}
2140
2141ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2142 const clang::DependentVectorType *T) {
2143 Error Err = Error::success();
2144 QualType ToElementType = importChecked(Err, T->getElementType());
2145 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2146 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2147 if (Err)
2148 return std::move(Err);
2149
2150 return Importer.getToContext().getDependentVectorType(
2151 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2152}
2153
2154ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2155 const clang::ObjCTypeParamType *T) {
2156 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2157 if (!ToDeclOrErr)
2158 return ToDeclOrErr.takeError();
2159
2160 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2161 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2162 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2163 if (!ToProtocolOrErr)
2164 return ToProtocolOrErr.takeError();
2165 ToProtocols.push_back(*ToProtocolOrErr);
2166 }
2167
2168 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2169 ToProtocols);
2170}
2171
2172ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2173 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2174 if (!ToElementTypeOrErr)
2175 return ToElementTypeOrErr.takeError();
2176
2177 ASTContext &ToCtx = Importer.getToContext();
2178 if (T->isReadOnly())
2179 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2180 else
2181 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2182}
2183
2184//----------------------------------------------------------------------------
2185// Import Declarations
2186//----------------------------------------------------------------------------
2188 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2189 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2190 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2191 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2192 // FIXME: We could support these constructs by importing a different type of
2193 // this parameter and by importing the original type of the parameter only
2194 // after the FunctionDecl is created. See
2195 // VisitFunctionDecl::UsedDifferentProtoType.
2196 DeclContext *OrigDC = D->getDeclContext();
2197 FunctionDecl *FunDecl;
2198 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2199 FunDecl->hasBody()) {
2200 auto getLeafPointeeType = [](const Type *T) {
2201 while (T->isPointerType() || T->isArrayType()) {
2202 T = T->getPointeeOrArrayElementType();
2203 }
2204 return T;
2205 };
2206 for (const ParmVarDecl *P : FunDecl->parameters()) {
2207 const Type *LeafT =
2208 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2209 auto *RT = dyn_cast<RecordType>(LeafT);
2210 if (RT && RT->getDecl() == D) {
2211 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2212 << D->getDeclKindName();
2213 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2214 }
2215 }
2216 }
2217
2218 // Import the context of this declaration.
2219 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2220 return Err;
2221
2222 // Import the name of this declaration.
2223 if (Error Err = importInto(Name, D->getDeclName()))
2224 return Err;
2225
2226 // Import the location of this declaration.
2227 if (Error Err = importInto(Loc, D->getLocation()))
2228 return Err;
2229
2230 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2231 if (ToD)
2232 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2233 return Err;
2234
2235 return Error::success();
2236}
2237
2239 NamedDecl *&ToD, SourceLocation &Loc) {
2240
2241 // Import the name of this declaration.
2242 if (Error Err = importInto(Name, D->getDeclName()))
2243 return Err;
2244
2245 // Import the location of this declaration.
2246 if (Error Err = importInto(Loc, D->getLocation()))
2247 return Err;
2248
2249 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2250 if (ToD)
2251 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2252 return Err;
2253
2254 return Error::success();
2255}
2256
2258 if (!FromD)
2259 return Error::success();
2260
2261 if (!ToD)
2262 if (Error Err = importInto(ToD, FromD))
2263 return Err;
2264
2265 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2266 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2267 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2268 !ToRecord->getDefinition()) {
2269 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2270 return Err;
2271 }
2272 }
2273 return Error::success();
2274 }
2275
2276 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2277 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2278 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2279 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2280 return Err;
2281 }
2282 }
2283 return Error::success();
2284 }
2285
2286 return Error::success();
2287}
2288
2289Error
2291 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2292 // NOTE: To.Name and To.Loc are already imported.
2293 // We only have to import To.LocInfo.
2294 switch (To.getName().getNameKind()) {
2301 return Error::success();
2302
2304 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2305 To.setCXXOperatorNameRange(*ToRangeOrErr);
2306 else
2307 return ToRangeOrErr.takeError();
2308 return Error::success();
2309 }
2311 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2312 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2313 else
2314 return LocOrErr.takeError();
2315 return Error::success();
2316 }
2320 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2321 To.setNamedTypeInfo(*ToTInfoOrErr);
2322 else
2323 return ToTInfoOrErr.takeError();
2324 return Error::success();
2325 }
2326 }
2327 llvm_unreachable("Unknown name kind.");
2328}
2329
2330Error
2332 if (Importer.isMinimalImport() && !ForceImport) {
2333 auto ToDCOrErr = Importer.ImportContext(FromDC);
2334 return ToDCOrErr.takeError();
2335 }
2336
2337 // We use strict error handling in case of records and enums, but not
2338 // with e.g. namespaces.
2339 //
2340 // FIXME Clients of the ASTImporter should be able to choose an
2341 // appropriate error handling strategy for their needs. For instance,
2342 // they may not want to mark an entire namespace as erroneous merely
2343 // because there is an ODR error with two typedefs. As another example,
2344 // the client may allow EnumConstantDecls with same names but with
2345 // different values in two distinct translation units.
2346 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2347
2348 auto MightNeedReordering = [](const Decl *D) {
2350 };
2351
2352 // Import everything that might need reordering first.
2353 Error ChildErrors = Error::success();
2354 for (auto *From : FromDC->decls()) {
2355 if (!MightNeedReordering(From))
2356 continue;
2357
2358 ExpectedDecl ImportedOrErr = import(From);
2359
2360 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2361 // want to make sure that we are also completing each FieldDecl. There
2362 // are currently cases where this does not happen and this is correctness
2363 // fix since operations such as code generation will expect this to be so.
2364 if (!ImportedOrErr) {
2365 HandleChildErrors.handleChildImportResult(ChildErrors,
2366 ImportedOrErr.takeError());
2367 continue;
2368 }
2369 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2370 Decl *ImportedDecl = *ImportedOrErr;
2371 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2372 if (FieldFrom && FieldTo) {
2373 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2374 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2375 }
2376 }
2377
2378 // We reorder declarations in RecordDecls because they may have another order
2379 // in the "to" context than they have in the "from" context. This may happen
2380 // e.g when we import a class like this:
2381 // struct declToImport {
2382 // int a = c + b;
2383 // int b = 1;
2384 // int c = 2;
2385 // };
2386 // During the import of `a` we import first the dependencies in sequence,
2387 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2388 // first removing the already imported members and then adding them in the
2389 // order as they appear in the "from" context.
2390 //
2391 // Keeping field order is vital because it determines structure layout.
2392 //
2393 // Here and below, we cannot call field_begin() method and its callers on
2394 // ToDC if it has an external storage. Calling field_begin() will
2395 // automatically load all the fields by calling
2396 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2397 // call ASTImporter::Import(). This is because the ExternalASTSource
2398 // interface in LLDB is implemented by the means of the ASTImporter. However,
2399 // calling an import at this point would result in an uncontrolled import, we
2400 // must avoid that.
2401
2402 auto ToDCOrErr = Importer.ImportContext(FromDC);
2403 if (!ToDCOrErr) {
2404 consumeError(std::move(ChildErrors));
2405 return ToDCOrErr.takeError();
2406 }
2407
2408 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2409 DeclContext *ToDC = *ToDCOrErr;
2410 // Remove all declarations, which may be in wrong order in the
2411 // lexical DeclContext and then add them in the proper order.
2412 for (auto *D : FromRD->decls()) {
2413 if (!MightNeedReordering(D))
2414 continue;
2415
2416 assert(D && "DC contains a null decl");
2417 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2418 // Remove only the decls which we successfully imported.
2419 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2420 // Remove the decl from its wrong place in the linked list.
2421 ToDC->removeDecl(ToD);
2422 // Add the decl to the end of the linked list.
2423 // This time it will be at the proper place because the enclosing for
2424 // loop iterates in the original (good) order of the decls.
2425 ToDC->addDeclInternal(ToD);
2426 }
2427 }
2428 }
2429
2430 // Import everything else.
2431 for (auto *From : FromDC->decls()) {
2432 if (MightNeedReordering(From))
2433 continue;
2434
2435 ExpectedDecl ImportedOrErr = import(From);
2436 if (!ImportedOrErr)
2437 HandleChildErrors.handleChildImportResult(ChildErrors,
2438 ImportedOrErr.takeError());
2439 }
2440
2441 return ChildErrors;
2442}
2443
2445 const FieldDecl *To) {
2446 RecordDecl *FromRecordDecl = nullptr;
2447 RecordDecl *ToRecordDecl = nullptr;
2448 // If we have a field that is an ArrayType we need to check if the array
2449 // element is a RecordDecl and if so we need to import the definition.
2450 QualType FromType = From->getType();
2451 QualType ToType = To->getType();
2452 if (FromType->isArrayType()) {
2453 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2454 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2455 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2456 }
2457
2458 if (!FromRecordDecl || !ToRecordDecl) {
2459 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2460 const RecordType *RecordTo = ToType->getAs<RecordType>();
2461
2462 if (RecordFrom && RecordTo) {
2463 FromRecordDecl = RecordFrom->getDecl();
2464 ToRecordDecl = RecordTo->getDecl();
2465 }
2466 }
2467
2468 if (FromRecordDecl && ToRecordDecl) {
2469 if (FromRecordDecl->isCompleteDefinition() &&
2470 !ToRecordDecl->isCompleteDefinition())
2471 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2472 }
2473
2474 return Error::success();
2475}
2476
2478 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2479 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2480 if (!ToDCOrErr)
2481 return ToDCOrErr.takeError();
2482 ToDC = *ToDCOrErr;
2483
2484 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2485 auto ToLexicalDCOrErr = Importer.ImportContext(
2486 FromD->getLexicalDeclContext());
2487 if (!ToLexicalDCOrErr)
2488 return ToLexicalDCOrErr.takeError();
2489 ToLexicalDC = *ToLexicalDCOrErr;
2490 } else
2491 ToLexicalDC = ToDC;
2492
2493 return Error::success();
2494}
2495
2497 const CXXRecordDecl *From, CXXRecordDecl *To) {
2498 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2499 "Import implicit methods to or from non-definition");
2500
2501 for (CXXMethodDecl *FromM : From->methods())
2502 if (FromM->isImplicit()) {
2503 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2504 if (!ToMOrErr)
2505 return ToMOrErr.takeError();
2506 }
2507
2508 return Error::success();
2509}
2510
2512 ASTImporter &Importer) {
2513 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2514 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2516 else
2517 return ToTypedefOrErr.takeError();
2518 }
2519 return Error::success();
2520}
2521
2523 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2524 auto DefinitionCompleter = [To]() {
2525 // There are cases in LLDB when we first import a class without its
2526 // members. The class will have DefinitionData, but no members. Then,
2527 // importDefinition is called from LLDB, which tries to get the members, so
2528 // when we get here, the class already has the DefinitionData set, so we
2529 // must unset the CompleteDefinition here to be able to complete again the
2530 // definition.
2531 To->setCompleteDefinition(false);
2532 To->completeDefinition();
2533 };
2534
2535 if (To->getDefinition() || To->isBeingDefined()) {
2536 if (Kind == IDK_Everything ||
2537 // In case of lambdas, the class already has a definition ptr set, but
2538 // the contained decls are not imported yet. Also, isBeingDefined was
2539 // set in CXXRecordDecl::CreateLambda. We must import the contained
2540 // decls here and finish the definition.
2541 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2542 if (To->isLambda()) {
2543 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2545 ToCaptures.reserve(FromCXXRD->capture_size());
2546 for (const auto &FromCapture : FromCXXRD->captures()) {
2547 if (auto ToCaptureOrErr = import(FromCapture))
2548 ToCaptures.push_back(*ToCaptureOrErr);
2549 else
2550 return ToCaptureOrErr.takeError();
2551 }
2552 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2553 ToCaptures);
2554 }
2555
2556 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2557 // Finish the definition of the lambda, set isBeingDefined to false.
2558 if (To->isLambda())
2559 DefinitionCompleter();
2560 return Result;
2561 }
2562
2563 return Error::success();
2564 }
2565
2566 To->startDefinition();
2567 // Set the definition to complete even if it is really not complete during
2568 // import. Some AST constructs (expressions) require the record layout
2569 // to be calculated (see 'clang::computeDependence') at the time they are
2570 // constructed. Import of such AST node is possible during import of the
2571 // same record, there is no way to have a completely defined record (all
2572 // fields imported) at that time without multiple AST import passes.
2573 if (!Importer.isMinimalImport())
2574 To->setCompleteDefinition(true);
2575 // Complete the definition even if error is returned.
2576 // The RecordDecl may be already part of the AST so it is better to
2577 // have it in complete state even if something is wrong with it.
2578 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2579
2580 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2581 return Err;
2582
2583 // Add base classes.
2584 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2585 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2586 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2587
2588 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2589 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2590
2591 #define FIELD(Name, Width, Merge) \
2592 ToData.Name = FromData.Name;
2593 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2594
2595 // Copy over the data stored in RecordDeclBits
2596 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2597
2599 for (const auto &Base1 : FromCXX->bases()) {
2600 ExpectedType TyOrErr = import(Base1.getType());
2601 if (!TyOrErr)
2602 return TyOrErr.takeError();
2603
2604 SourceLocation EllipsisLoc;
2605 if (Base1.isPackExpansion()) {
2606 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2607 EllipsisLoc = *LocOrErr;
2608 else
2609 return LocOrErr.takeError();
2610 }
2611
2612 // Ensure that we have a definition for the base.
2613 if (Error Err =
2614 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2615 return Err;
2616
2617 auto RangeOrErr = import(Base1.getSourceRange());
2618 if (!RangeOrErr)
2619 return RangeOrErr.takeError();
2620
2621 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2622 if (!TSIOrErr)
2623 return TSIOrErr.takeError();
2624
2625 Bases.push_back(
2626 new (Importer.getToContext()) CXXBaseSpecifier(
2627 *RangeOrErr,
2628 Base1.isVirtual(),
2629 Base1.isBaseOfClass(),
2630 Base1.getAccessSpecifierAsWritten(),
2631 *TSIOrErr,
2632 EllipsisLoc));
2633 }
2634 if (!Bases.empty())
2635 ToCXX->setBases(Bases.data(), Bases.size());
2636 }
2637
2638 if (shouldForceImportDeclContext(Kind)) {
2639 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2640 return Err;
2641 }
2642
2643 return Error::success();
2644}
2645
2647 if (To->getAnyInitializer())
2648 return Error::success();
2649
2650 Expr *FromInit = From->getInit();
2651 if (!FromInit)
2652 return Error::success();
2653
2654 ExpectedExpr ToInitOrErr = import(FromInit);
2655 if (!ToInitOrErr)
2656 return ToInitOrErr.takeError();
2657
2658 To->setInit(*ToInitOrErr);
2659 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2660 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2661 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2662 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2663 // FIXME: Also import the initializer value.
2664 }
2665
2666 // FIXME: Other bits to merge?
2667 return Error::success();
2668}
2669
2671 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2672 if (To->getDefinition() || To->isBeingDefined()) {
2673 if (Kind == IDK_Everything)
2674 return ImportDeclContext(From, /*ForceImport=*/true);
2675 return Error::success();
2676 }
2677
2678 To->startDefinition();
2679
2680 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2681 return Err;
2682
2683 ExpectedType ToTypeOrErr =
2684 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2685 if (!ToTypeOrErr)
2686 return ToTypeOrErr.takeError();
2687
2688 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2689 if (!ToPromotionTypeOrErr)
2690 return ToPromotionTypeOrErr.takeError();
2691
2693 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2694 return Err;
2695
2696 // FIXME: we might need to merge the number of positive or negative bits
2697 // if the enumerator lists don't match.
2698 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2699 From->getNumPositiveBits(),
2700 From->getNumNegativeBits());
2701 return Error::success();
2702}
2703
2707 for (const auto &Arg : FromArgs) {
2708 if (auto ToOrErr = import(Arg))
2709 ToArgs.push_back(*ToOrErr);
2710 else
2711 return ToOrErr.takeError();
2712 }
2713
2714 return Error::success();
2715}
2716
2717// FIXME: Do not forget to remove this and use only 'import'.
2720 return import(From);
2721}
2722
2723template <typename InContainerTy>
2725 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2726 for (const auto &FromLoc : Container) {
2727 if (auto ToLocOrErr = import(FromLoc))
2728 ToTAInfo.addArgument(*ToLocOrErr);
2729 else
2730 return ToLocOrErr.takeError();
2731 }
2732 return Error::success();
2733}
2734
2740
2741bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2742 bool IgnoreTemplateParmDepth) {
2743 // Eliminate a potential failure point where we attempt to re-import
2744 // something we're trying to import while completing ToRecord.
2745 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2746 if (ToOrigin) {
2747 To = ToOrigin;
2748 }
2749
2751 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2752 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2754 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2755 IgnoreTemplateParmDepth);
2756 return Ctx.IsEquivalent(From, To);
2757}
2758
2760 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2761 << D->getDeclKindName();
2762 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2763}
2764
2766 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2767 << D->getDeclKindName();
2768 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2769}
2770
2772 // Import the context of this declaration.
2773 DeclContext *DC, *LexicalDC;
2774 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2775 return std::move(Err);
2776
2777 // Import the location of this declaration.
2778 ExpectedSLoc LocOrErr = import(D->getLocation());
2779 if (!LocOrErr)
2780 return LocOrErr.takeError();
2781
2782 EmptyDecl *ToD;
2783 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2784 return ToD;
2785
2786 ToD->setLexicalDeclContext(LexicalDC);
2787 LexicalDC->addDeclInternal(ToD);
2788 return ToD;
2789}
2790
2792 TranslationUnitDecl *ToD =
2793 Importer.getToContext().getTranslationUnitDecl();
2794
2795 Importer.MapImported(D, ToD);
2796
2797 return ToD;
2798}
2799
2801 Error Err = Error::success();
2802 Expr *ToAsmString = importChecked(Err, D->getAsmStringExpr());
2803 SourceLocation ToAsmLoc = importChecked(Err, D->getAsmLoc());
2804 SourceLocation ToRParenLoc = importChecked(Err, D->getRParenLoc());
2805 if (Err)
2806 return std::move(Err);
2807
2808 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2809 if (!DCOrErr)
2810 return DCOrErr.takeError();
2811 DeclContext *DC = *DCOrErr;
2812
2813 FileScopeAsmDecl *ToD;
2814 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToAsmString,
2815 ToAsmLoc, ToRParenLoc))
2816 return ToD;
2817
2818 ToD->setLexicalDeclContext(DC);
2819 DC->addDeclInternal(ToD);
2820
2821 return ToD;
2822}
2823
2825 DeclContext *DC, *LexicalDC;
2826 DeclarationName Name;
2827 SourceLocation Loc;
2828 NamedDecl *ToND;
2829 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2830 return std::move(Err);
2831 if (ToND)
2832 return ToND;
2833
2834 BindingDecl *ToD;
2835 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2836 Name.getAsIdentifierInfo(), D->getType()))
2837 return ToD;
2838
2839 Error Err = Error::success();
2840 QualType ToType = importChecked(Err, D->getType());
2841 Expr *ToBinding = importChecked(Err, D->getBinding());
2842 DecompositionDecl *ToDecomposedDecl =
2844 if (Err)
2845 return std::move(Err);
2846
2847 ToD->setBinding(ToType, ToBinding);
2848 ToD->setDecomposedDecl(ToDecomposedDecl);
2849 addDeclToContexts(D, ToD);
2850
2851 return ToD;
2852}
2853
2855 ExpectedSLoc LocOrErr = import(D->getLocation());
2856 if (!LocOrErr)
2857 return LocOrErr.takeError();
2858 auto ColonLocOrErr = import(D->getColonLoc());
2859 if (!ColonLocOrErr)
2860 return ColonLocOrErr.takeError();
2861
2862 // Import the context of this declaration.
2863 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2864 if (!DCOrErr)
2865 return DCOrErr.takeError();
2866 DeclContext *DC = *DCOrErr;
2867
2868 AccessSpecDecl *ToD;
2869 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2870 DC, *LocOrErr, *ColonLocOrErr))
2871 return ToD;
2872
2873 // Lexical DeclContext and Semantic DeclContext
2874 // is always the same for the accessSpec.
2875 ToD->setLexicalDeclContext(DC);
2876 DC->addDeclInternal(ToD);
2877
2878 return ToD;
2879}
2880
2882 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2883 if (!DCOrErr)
2884 return DCOrErr.takeError();
2885 DeclContext *DC = *DCOrErr;
2886 DeclContext *LexicalDC = DC;
2887
2888 Error Err = Error::success();
2889 auto ToLocation = importChecked(Err, D->getLocation());
2890 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2891 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2892 auto ToMessage = importChecked(Err, D->getMessage());
2893 if (Err)
2894 return std::move(Err);
2895
2896 StaticAssertDecl *ToD;
2897 if (GetImportedOrCreateDecl(
2898 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2899 ToRParenLoc, D->isFailed()))
2900 return ToD;
2901
2902 ToD->setLexicalDeclContext(LexicalDC);
2903 LexicalDC->addDeclInternal(ToD);
2904 return ToD;
2905}
2906
2909 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2910 if (!DCOrErr)
2911 return DCOrErr.takeError();
2912 DeclContext *DC = *DCOrErr;
2913 DeclContext *LexicalDC = DC;
2914
2915 Error Err = Error::success();
2916 auto ToLocation = importChecked(Err, D->getLocation());
2917 auto ToExpansion = importChecked(Err, D->getExpansionPattern());
2918 auto ToIndex = importChecked(Err, D->getIndexTemplateParm());
2919 auto ToInstantiations = importChecked(Err, D->getInstantiations());
2920 if (Err)
2921 return std::move(Err);
2922
2924 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToLocation,
2925 ToIndex))
2926 return ToD;
2927
2928 ToD->setExpansionPattern(ToExpansion);
2929 ToD->setInstantiations(ToInstantiations);
2930 ToD->setLexicalDeclContext(LexicalDC);
2931 LexicalDC->addDeclInternal(ToD);
2932 return ToD;
2933}
2934
2936 // Import the major distinguishing characteristics of this namespace.
2937 DeclContext *DC, *LexicalDC;
2938 DeclarationName Name;
2939 SourceLocation Loc;
2940 NamedDecl *ToD;
2941 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2942 return std::move(Err);
2943 if (ToD)
2944 return ToD;
2945
2946 NamespaceDecl *MergeWithNamespace = nullptr;
2947 if (!Name) {
2948 // This is an anonymous namespace. Adopt an existing anonymous
2949 // namespace if we can.
2950 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2951 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2952 MergeWithNamespace = TU->getAnonymousNamespace();
2953 else
2954 MergeWithNamespace =
2955 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2956 } else {
2957 SmallVector<NamedDecl *, 4> ConflictingDecls;
2958 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2959 for (auto *FoundDecl : FoundDecls) {
2960 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2961 continue;
2962
2963 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2964 MergeWithNamespace = FoundNS;
2965 ConflictingDecls.clear();
2966 break;
2967 }
2968
2969 ConflictingDecls.push_back(FoundDecl);
2970 }
2971
2972 if (!ConflictingDecls.empty()) {
2973 ExpectedName NameOrErr = Importer.HandleNameConflict(
2974 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2975 ConflictingDecls.size());
2976 if (NameOrErr)
2977 Name = NameOrErr.get();
2978 else
2979 return NameOrErr.takeError();
2980 }
2981 }
2982
2983 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2984 if (!BeginLocOrErr)
2985 return BeginLocOrErr.takeError();
2986 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2987 if (!RBraceLocOrErr)
2988 return RBraceLocOrErr.takeError();
2989
2990 // Create the "to" namespace, if needed.
2991 NamespaceDecl *ToNamespace = MergeWithNamespace;
2992 if (!ToNamespace) {
2993 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2994 D->isInline(), *BeginLocOrErr, Loc,
2995 Name.getAsIdentifierInfo(),
2996 /*PrevDecl=*/nullptr, D->isNested()))
2997 return ToNamespace;
2998 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2999 ToNamespace->setLexicalDeclContext(LexicalDC);
3000 LexicalDC->addDeclInternal(ToNamespace);
3001
3002 // If this is an anonymous namespace, register it as the anonymous
3003 // namespace within its context.
3004 if (!Name) {
3005 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3006 TU->setAnonymousNamespace(ToNamespace);
3007 else
3008 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
3009 }
3010 }
3011 Importer.MapImported(D, ToNamespace);
3012
3013 if (Error Err = ImportDeclContext(D))
3014 return std::move(Err);
3015
3016 return ToNamespace;
3017}
3018
3020 // Import the major distinguishing characteristics of this namespace.
3021 DeclContext *DC, *LexicalDC;
3022 DeclarationName Name;
3023 SourceLocation Loc;
3024 NamedDecl *LookupD;
3025 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
3026 return std::move(Err);
3027 if (LookupD)
3028 return LookupD;
3029
3030 // NOTE: No conflict resolution is done for namespace aliases now.
3031
3032 Error Err = Error::success();
3033 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
3034 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
3035 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3036 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
3037 auto ToNamespace = importChecked(Err, D->getNamespace());
3038 if (Err)
3039 return std::move(Err);
3040
3041 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
3042
3043 NamespaceAliasDecl *ToD;
3044 if (GetImportedOrCreateDecl(
3045 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
3046 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
3047 return ToD;
3048
3049 ToD->setLexicalDeclContext(LexicalDC);
3050 LexicalDC->addDeclInternal(ToD);
3051
3052 return ToD;
3053}
3054
3057 // Import the major distinguishing characteristics of this typedef.
3058 DeclarationName Name;
3059 SourceLocation Loc;
3060 NamedDecl *ToD;
3061 // Do not import the DeclContext, we will import it once the TypedefNameDecl
3062 // is created.
3063 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
3064 return std::move(Err);
3065 if (ToD)
3066 return ToD;
3067
3068 DeclContext *DC = cast_or_null<DeclContext>(
3069 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
3070 DeclContext *LexicalDC =
3071 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
3073
3074 // If this typedef is not in block scope, determine whether we've
3075 // seen a typedef with the same name (that we can merge with) or any
3076 // other entity by that name (which name lookup could conflict with).
3077 // Note: Repeated typedefs are not valid in C99:
3078 // 'typedef int T; typedef int T;' is invalid
3079 // We do not care about this now.
3080 if (DC && !DC->isFunctionOrMethod()) {
3081 SmallVector<NamedDecl *, 4> ConflictingDecls;
3082 unsigned IDNS = Decl::IDNS_Ordinary;
3083 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3084 for (auto *FoundDecl : FoundDecls) {
3085 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3086 continue;
3087 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3088 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3089 continue;
3090
3091 QualType FromUT = D->getUnderlyingType();
3092 QualType FoundUT = FoundTypedef->getUnderlyingType();
3093 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3094 // If the underlying declarations are unnamed records these can be
3095 // imported as different types. We should create a distinct typedef
3096 // node in this case.
3097 // If we found an existing underlying type with a record in a
3098 // different context (than the imported), this is already reason for
3099 // having distinct typedef nodes for these.
3100 // Again this can create situation like
3101 // 'typedef int T; typedef int T;' but this is hard to avoid without
3102 // a rename strategy at import.
3103 if (!FromUT.isNull() && !FoundUT.isNull()) {
3104 RecordDecl *FromR = FromUT->getAsRecordDecl();
3105 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3106 if (FromR && FoundR &&
3107 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3108 continue;
3109 }
3110 // If the "From" context has a complete underlying type but we
3111 // already have a complete underlying type then return with that.
3112 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3113 return Importer.MapImported(D, FoundTypedef);
3114 // FIXME Handle redecl chain. When you do that make consistent changes
3115 // in ASTImporterLookupTable too.
3116 } else {
3117 ConflictingDecls.push_back(FoundDecl);
3118 }
3119 }
3120 }
3121
3122 if (!ConflictingDecls.empty()) {
3123 ExpectedName NameOrErr = Importer.HandleNameConflict(
3124 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3125 if (NameOrErr)
3126 Name = NameOrErr.get();
3127 else
3128 return NameOrErr.takeError();
3129 }
3130 }
3131
3132 Error Err = Error::success();
3134 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3135 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3136 if (Err)
3137 return std::move(Err);
3138
3139 // Create the new typedef node.
3140 // FIXME: ToUnderlyingType is not used.
3141 (void)ToUnderlyingType;
3142 TypedefNameDecl *ToTypedef;
3143 if (IsAlias) {
3144 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3145 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3146 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3147 return ToTypedef;
3148 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3149 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3150 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3151 return ToTypedef;
3152
3153 // Import the DeclContext and set it to the Typedef.
3154 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3155 return std::move(Err);
3156 ToTypedef->setDeclContext(DC);
3157 ToTypedef->setLexicalDeclContext(LexicalDC);
3158 // Add to the lookupTable because we could not do that in MapImported.
3159 Importer.AddToLookupTable(ToTypedef);
3160
3161 ToTypedef->setAccess(D->getAccess());
3162
3163 // Templated declarations should not appear in DeclContext.
3164 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3165 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3166 LexicalDC->addDeclInternal(ToTypedef);
3167
3168 return ToTypedef;
3169}
3170
3174
3178
3181 // Import the major distinguishing characteristics of this typedef.
3182 DeclContext *DC, *LexicalDC;
3183 DeclarationName Name;
3184 SourceLocation Loc;
3185 NamedDecl *FoundD;
3186 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3187 return std::move(Err);
3188 if (FoundD)
3189 return FoundD;
3190
3191 // If this typedef is not in block scope, determine whether we've
3192 // seen a typedef with the same name (that we can merge with) or any
3193 // other entity by that name (which name lookup could conflict with).
3194 if (!DC->isFunctionOrMethod()) {
3195 SmallVector<NamedDecl *, 4> ConflictingDecls;
3196 unsigned IDNS = Decl::IDNS_Ordinary;
3197 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3198 for (auto *FoundDecl : FoundDecls) {
3199 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3200 continue;
3201 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3202 if (IsStructuralMatch(D, FoundAlias))
3203 return Importer.MapImported(D, FoundAlias);
3204 ConflictingDecls.push_back(FoundDecl);
3205 }
3206 }
3207
3208 if (!ConflictingDecls.empty()) {
3209 ExpectedName NameOrErr = Importer.HandleNameConflict(
3210 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3211 if (NameOrErr)
3212 Name = NameOrErr.get();
3213 else
3214 return NameOrErr.takeError();
3215 }
3216 }
3217
3218 Error Err = Error::success();
3219 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3220 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3221 if (Err)
3222 return std::move(Err);
3223
3224 TypeAliasTemplateDecl *ToAlias;
3225 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3226 Name, ToTemplateParameters, ToTemplatedDecl))
3227 return ToAlias;
3228
3229 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3230
3231 ToAlias->setAccess(D->getAccess());
3232 ToAlias->setLexicalDeclContext(LexicalDC);
3233 LexicalDC->addDeclInternal(ToAlias);
3234 if (DC != Importer.getToContext().getTranslationUnitDecl())
3235 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3236 return ToAlias;
3237}
3238
3240 // Import the major distinguishing characteristics of this label.
3241 DeclContext *DC, *LexicalDC;
3242 DeclarationName Name;
3243 SourceLocation Loc;
3244 NamedDecl *ToD;
3245 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3246 return std::move(Err);
3247 if (ToD)
3248 return ToD;
3249
3250 assert(LexicalDC->isFunctionOrMethod());
3251
3252 LabelDecl *ToLabel;
3253 if (D->isGnuLocal()) {
3254 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3255 if (!BeginLocOrErr)
3256 return BeginLocOrErr.takeError();
3257 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3258 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3259 return ToLabel;
3260
3261 } else {
3262 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3263 Name.getAsIdentifierInfo()))
3264 return ToLabel;
3265
3266 }
3267
3268 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3269 if (!ToStmtOrErr)
3270 return ToStmtOrErr.takeError();
3271
3272 ToLabel->setStmt(*ToStmtOrErr);
3273 ToLabel->setLexicalDeclContext(LexicalDC);
3274 LexicalDC->addDeclInternal(ToLabel);
3275 return ToLabel;
3276}
3277
3279 // Import the major distinguishing characteristics of this enum.
3280 DeclContext *DC, *LexicalDC;
3281 DeclarationName Name;
3282 SourceLocation Loc;
3283 NamedDecl *ToD;
3284 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3285 return std::move(Err);
3286 if (ToD)
3287 return ToD;
3288
3289 // Figure out what enum name we're looking for.
3290 unsigned IDNS = Decl::IDNS_Tag;
3291 DeclarationName SearchName = Name;
3292 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3293 if (Error Err = importInto(
3294 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3295 return std::move(Err);
3296 IDNS = Decl::IDNS_Ordinary;
3297 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3298 IDNS |= Decl::IDNS_Ordinary;
3299
3300 // We may already have an enum of the same name; try to find and match it.
3301 EnumDecl *PrevDecl = nullptr;
3302 if (!DC->isFunctionOrMethod()) {
3303 SmallVector<NamedDecl *, 4> ConflictingDecls;
3304 auto FoundDecls =
3305 Importer.findDeclsInToCtx(DC, SearchName);
3306 for (auto *FoundDecl : FoundDecls) {
3307 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3308 continue;
3309
3310 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3311 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3312 FoundDecl = Tag->getDecl();
3313 }
3314
3315 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3316 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3317 continue;
3318 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3319 EnumDecl *FoundDef = FoundEnum->getDefinition();
3320 if (D->isThisDeclarationADefinition() && FoundDef)
3321 return Importer.MapImported(D, FoundDef);
3322 PrevDecl = FoundEnum->getMostRecentDecl();
3323 break;
3324 }
3325 ConflictingDecls.push_back(FoundDecl);
3326 }
3327 }
3328
3329 // In case of unnamed enums, we try to find an existing similar one, if none
3330 // was found, perform the import always.
3331 // Structural in-equivalence is not detected in this way here, but it may
3332 // be found when the parent decl is imported (if the enum is part of a
3333 // class). To make this totally exact a more difficult solution is needed.
3334 if (SearchName && !ConflictingDecls.empty()) {
3335 ExpectedName NameOrErr = Importer.HandleNameConflict(
3336 SearchName, DC, IDNS, ConflictingDecls.data(),
3337 ConflictingDecls.size());
3338 if (NameOrErr)
3339 Name = NameOrErr.get();
3340 else
3341 return NameOrErr.takeError();
3342 }
3343 }
3344
3345 Error Err = Error::success();
3346 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3347 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3348 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3349 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3350 if (Err)
3351 return std::move(Err);
3352
3353 // Create the enum declaration.
3354 EnumDecl *D2;
3355 if (GetImportedOrCreateDecl(
3356 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3357 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3358 D->isScopedUsingClassTag(), D->isFixed()))
3359 return D2;
3360
3361 D2->setQualifierInfo(ToQualifierLoc);
3362 D2->setIntegerType(ToIntegerType);
3363 D2->setBraceRange(ToBraceRange);
3364 D2->setAccess(D->getAccess());
3365 D2->setLexicalDeclContext(LexicalDC);
3366 addDeclToContexts(D, D2);
3367
3369 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3370 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3371 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3372 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3373 else
3374 return ToInstOrErr.takeError();
3375 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3377 else
3378 return POIOrErr.takeError();
3379 }
3380
3381 // Import the definition
3382 if (D->isCompleteDefinition())
3383 if (Error Err = ImportDefinition(D, D2))
3384 return std::move(Err);
3385
3386 return D2;
3387}
3388
3390 bool IsFriendTemplate = false;
3391 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3392 IsFriendTemplate =
3393 DCXX->getDescribedClassTemplate() &&
3394 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3396 }
3397
3398 // Import the major distinguishing characteristics of this record.
3399 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3400 DeclarationName Name;
3401 SourceLocation Loc;
3402 NamedDecl *ToD = nullptr;
3403 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3404 return std::move(Err);
3405 if (ToD)
3406 return ToD;
3407
3408 // Figure out what structure name we're looking for.
3409 unsigned IDNS = Decl::IDNS_Tag;
3410 DeclarationName SearchName = Name;
3411 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3412 if (Error Err = importInto(
3413 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3414 return std::move(Err);
3415 IDNS = Decl::IDNS_Ordinary;
3416 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3418
3419 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3420 : DC->isDependentContext();
3421 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3422
3423 // We may already have a record of the same name; try to find and match it.
3424 RecordDecl *PrevDecl = nullptr;
3425 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3426 SmallVector<NamedDecl *, 4> ConflictingDecls;
3427 auto FoundDecls =
3428 Importer.findDeclsInToCtx(DC, SearchName);
3429 if (!FoundDecls.empty()) {
3430 // We're going to have to compare D against potentially conflicting Decls,
3431 // so complete it.
3434 }
3435
3436 for (auto *FoundDecl : FoundDecls) {
3437 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3438 continue;
3439
3440 Decl *Found = FoundDecl;
3441 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3442 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3443 Found = Tag->getDecl();
3444 }
3445
3446 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3447 // Do not emit false positive diagnostic in case of unnamed
3448 // struct/union and in case of anonymous structs. Would be false
3449 // because there may be several anonymous/unnamed structs in a class.
3450 // E.g. these are both valid:
3451 // struct A { // unnamed structs
3452 // struct { struct A *next; } entry0;
3453 // struct { struct A *next; } entry1;
3454 // };
3455 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3456 if (!SearchName)
3457 if (!IsStructuralMatch(D, FoundRecord, false))
3458 continue;
3459
3460 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3461 continue;
3462
3463 if (IsStructuralMatch(D, FoundRecord)) {
3464 RecordDecl *FoundDef = FoundRecord->getDefinition();
3465 if (D->isThisDeclarationADefinition() && FoundDef) {
3466 // FIXME: Structural equivalence check should check for same
3467 // user-defined methods.
3468 Importer.MapImported(D, FoundDef);
3469 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3470 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3471 assert(FoundCXX && "Record type mismatch");
3472
3473 if (!Importer.isMinimalImport())
3474 // FoundDef may not have every implicit method that D has
3475 // because implicit methods are created only if they are used.
3476 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3477 return std::move(Err);
3478 }
3479 // FIXME: We can return FoundDef here.
3480 }
3481 PrevDecl = FoundRecord->getMostRecentDecl();
3482 break;
3483 }
3484 ConflictingDecls.push_back(FoundDecl);
3485 } // kind is RecordDecl
3486 } // for
3487
3488 if (!ConflictingDecls.empty() && SearchName) {
3489 ExpectedName NameOrErr = Importer.HandleNameConflict(
3490 SearchName, DC, IDNS, ConflictingDecls.data(),
3491 ConflictingDecls.size());
3492 if (NameOrErr)
3493 Name = NameOrErr.get();
3494 else
3495 return NameOrErr.takeError();
3496 }
3497 }
3498
3499 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3500 if (!BeginLocOrErr)
3501 return BeginLocOrErr.takeError();
3502
3503 // Create the record declaration.
3504 RecordDecl *D2 = nullptr;
3505 CXXRecordDecl *D2CXX = nullptr;
3506 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3507 if (DCXX->isLambda()) {
3508 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3509 if (!TInfoOrErr)
3510 return TInfoOrErr.takeError();
3511 if (GetImportedOrCreateSpecialDecl(
3512 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3513 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3514 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3515 return D2CXX;
3516 Decl *ContextDecl = DCXX->getLambdaContextDecl();
3517 ExpectedDecl CDeclOrErr = import(ContextDecl);
3518 if (!CDeclOrErr)
3519 return CDeclOrErr.takeError();
3520 if (ContextDecl != nullptr) {
3521 D2CXX->setLambdaContextDecl(*CDeclOrErr);
3522 }
3523 D2CXX->setLambdaNumbering(DCXX->getLambdaNumbering());
3524 } else {
3525 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3526 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3527 Name.getAsIdentifierInfo(),
3528 cast_or_null<CXXRecordDecl>(PrevDecl)))
3529 return D2CXX;
3530 }
3531
3532 D2 = D2CXX;
3533 D2->setAccess(D->getAccess());
3534 D2->setLexicalDeclContext(LexicalDC);
3535 addDeclToContexts(D, D2);
3536
3537 if (ClassTemplateDecl *FromDescribed =
3538 DCXX->getDescribedClassTemplate()) {
3539 ClassTemplateDecl *ToDescribed;
3540 if (Error Err = importInto(ToDescribed, FromDescribed))
3541 return std::move(Err);
3542 D2CXX->setDescribedClassTemplate(ToDescribed);
3543 } else if (MemberSpecializationInfo *MemberInfo =
3544 DCXX->getMemberSpecializationInfo()) {
3546 MemberInfo->getTemplateSpecializationKind();
3548
3549 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3550 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3551 else
3552 return ToInstOrErr.takeError();
3553
3554 if (ExpectedSLoc POIOrErr =
3555 import(MemberInfo->getPointOfInstantiation()))
3557 *POIOrErr);
3558 else
3559 return POIOrErr.takeError();
3560 }
3561
3562 } else {
3563 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3564 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3565 Name.getAsIdentifierInfo(), PrevDecl))
3566 return D2;
3567 D2->setLexicalDeclContext(LexicalDC);
3568 addDeclToContexts(D, D2);
3569 }
3570
3571 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3572 D2->setBraceRange(*BraceRangeOrErr);
3573 else
3574 return BraceRangeOrErr.takeError();
3575 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3576 D2->setQualifierInfo(*QualifierLocOrErr);
3577 else
3578 return QualifierLocOrErr.takeError();
3579
3580 if (D->isAnonymousStructOrUnion())
3581 D2->setAnonymousStructOrUnion(true);
3582
3583 if (D->isCompleteDefinition())
3584 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3585 return std::move(Err);
3586
3587 return D2;
3588}
3589
3591 // Import the major distinguishing characteristics of this enumerator.
3592 DeclContext *DC, *LexicalDC;
3593 DeclarationName Name;
3594 SourceLocation Loc;
3595 NamedDecl *ToD;
3596 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3597 return std::move(Err);
3598 if (ToD)
3599 return ToD;
3600
3601 // Determine whether there are any other declarations with the same name and
3602 // in the same context.
3603 if (!LexicalDC->isFunctionOrMethod()) {
3604 SmallVector<NamedDecl *, 4> ConflictingDecls;
3605 unsigned IDNS = Decl::IDNS_Ordinary;
3606 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3607 for (auto *FoundDecl : FoundDecls) {
3608 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3609 continue;
3610
3611 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3612 if (IsStructuralMatch(D, FoundEnumConstant))
3613 return Importer.MapImported(D, FoundEnumConstant);
3614 ConflictingDecls.push_back(FoundDecl);
3615 }
3616 }
3617
3618 if (!ConflictingDecls.empty()) {
3619 ExpectedName NameOrErr = Importer.HandleNameConflict(
3620 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3621 if (NameOrErr)
3622 Name = NameOrErr.get();
3623 else
3624 return NameOrErr.takeError();
3625 }
3626 }
3627
3628 ExpectedType TypeOrErr = import(D->getType());
3629 if (!TypeOrErr)
3630 return TypeOrErr.takeError();
3631
3632 ExpectedExpr InitOrErr = import(D->getInitExpr());
3633 if (!InitOrErr)
3634 return InitOrErr.takeError();
3635
3636 EnumConstantDecl *ToEnumerator;
3637 if (GetImportedOrCreateDecl(
3638 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3639 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3640 return ToEnumerator;
3641
3642 ToEnumerator->setAccess(D->getAccess());
3643 ToEnumerator->setLexicalDeclContext(LexicalDC);
3644 LexicalDC->addDeclInternal(ToEnumerator);
3645 return ToEnumerator;
3646}
3647
3648template <typename DeclTy>
3650 DeclTy *ToD) {
3652 FromD->getTemplateParameterLists();
3653 if (FromTPLs.empty())
3654 return Error::success();
3655 SmallVector<TemplateParameterList *, 2> ToTPLists(FromTPLs.size());
3656 for (unsigned int I = 0; I < FromTPLs.size(); ++I)
3657 if (Expected<TemplateParameterList *> ToTPListOrErr = import(FromTPLs[I]))
3658 ToTPLists[I] = *ToTPListOrErr;
3659 else
3660 return ToTPListOrErr.takeError();
3661 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3662 return Error::success();
3663}
3664
3666 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3667 switch (FromFD->getTemplatedKind()) {
3670 return Error::success();
3671
3673 if (Expected<FunctionDecl *> InstFDOrErr =
3674 import(FromFD->getInstantiatedFromDecl()))
3675 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3676 return Error::success();
3679
3680 if (Expected<FunctionDecl *> InstFDOrErr =
3681 import(FromFD->getInstantiatedFromMemberFunction()))
3682 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3683 else
3684 return InstFDOrErr.takeError();
3685
3686 if (ExpectedSLoc POIOrErr = import(
3689 else
3690 return POIOrErr.takeError();
3691
3692 return Error::success();
3693 }
3694
3696 auto FunctionAndArgsOrErr =
3698 if (!FunctionAndArgsOrErr)
3699 return FunctionAndArgsOrErr.takeError();
3700
3702 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3703
3704 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3705 TemplateArgumentListInfo ToTAInfo;
3706 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3707 if (FromTAArgsAsWritten)
3709 *FromTAArgsAsWritten, ToTAInfo))
3710 return Err;
3711
3712 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3713 if (!POIOrErr)
3714 return POIOrErr.takeError();
3715
3716 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3717 return Err;
3718
3719 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3720 ToFD->setFunctionTemplateSpecialization(
3721 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3722 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3723 return Error::success();
3724 }
3725
3727 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3728 UnresolvedSet<8> Candidates;
3729 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3730 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3731 Candidates.addDecl(*ToFTDOrErr);
3732 else
3733 return ToFTDOrErr.takeError();
3734 }
3735
3736 // Import TemplateArgumentListInfo.
3737 TemplateArgumentListInfo ToTAInfo;
3738 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3739 if (FromTAArgsAsWritten)
3740 if (Error Err =
3741 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3742 return Err;
3743
3745 Importer.getToContext(), Candidates,
3746 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3747 return Error::success();
3748 }
3749 }
3750 llvm_unreachable("All cases should be covered!");
3751}
3752
3755 auto FunctionAndArgsOrErr =
3757 if (!FunctionAndArgsOrErr)
3758 return FunctionAndArgsOrErr.takeError();
3759
3761 TemplateArgsTy ToTemplArgs;
3762 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3763 void *InsertPos = nullptr;
3764 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3765 return FoundSpec;
3766}
3767
3769 FunctionDecl *ToFD) {
3770 if (Stmt *FromBody = FromFD->getBody()) {
3771 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3772 ToFD->setBody(*ToBodyOrErr);
3773 else
3774 return ToBodyOrErr.takeError();
3775 }
3776 return Error::success();
3777}
3778
3780ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3781 Expr *ExplicitExpr = ESpec.getExpr();
3782 if (ExplicitExpr)
3783 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3784 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3785}
3786
3788
3790 auto RedeclIt = Redecls.begin();
3791 // Import the first part of the decl chain. I.e. import all previous
3792 // declarations starting from the canonical decl.
3793 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3794 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3795 if (!ToRedeclOrErr)
3796 return ToRedeclOrErr.takeError();
3797 }
3798 assert(*RedeclIt == D);
3799
3800 // Import the major distinguishing characteristics of this function.
3801 DeclContext *DC, *LexicalDC;
3802 DeclarationName Name;
3803 SourceLocation Loc;
3804 NamedDecl *ToD;
3805 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3806 return std::move(Err);
3807 if (ToD)
3808 return ToD;
3809
3810 FunctionDecl *FoundByLookup = nullptr;
3812
3813 // If this is a function template specialization, then try to find the same
3814 // existing specialization in the "to" context. The lookup below will not
3815 // find any specialization, but would find the primary template; thus, we
3816 // have to skip normal lookup in case of specializations.
3817 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3818 if (D->getTemplatedKind() ==
3820 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3821 if (!FoundFunctionOrErr)
3822 return FoundFunctionOrErr.takeError();
3823 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3824 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3825 return Def;
3826 FoundByLookup = FoundFunction;
3827 }
3828 }
3829 // Try to find a function in our own ("to") context with the same name, same
3830 // type, and in the same context as the function we're importing.
3831 else if (!LexicalDC->isFunctionOrMethod()) {
3832 SmallVector<NamedDecl *, 4> ConflictingDecls;
3834 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3835 for (auto *FoundDecl : FoundDecls) {
3836 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3837 continue;
3838
3839 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3840 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3841 continue;
3842
3843 if (IsStructuralMatch(D, FoundFunction)) {
3844 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3845 return Def;
3846 FoundByLookup = FoundFunction;
3847 break;
3848 }
3849 // FIXME: Check for overloading more carefully, e.g., by boosting
3850 // Sema::IsOverload out to the AST library.
3851
3852 // Function overloading is okay in C++.
3853 if (Importer.getToContext().getLangOpts().CPlusPlus)
3854 continue;
3855
3856 // Complain about inconsistent function types.
3857 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3858 << Name << D->getType() << FoundFunction->getType();
3859 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3860 << FoundFunction->getType();
3861 ConflictingDecls.push_back(FoundDecl);
3862 }
3863 }
3864
3865 if (!ConflictingDecls.empty()) {
3866 ExpectedName NameOrErr = Importer.HandleNameConflict(
3867 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3868 if (NameOrErr)
3869 Name = NameOrErr.get();
3870 else
3871 return NameOrErr.takeError();
3872 }
3873 }
3874
3875 // We do not allow more than one in-class declaration of a function. This is
3876 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3877 // assumes there is only one in-class declaration. Building a redecl
3878 // chain would result in more than one in-class declaration for
3879 // overrides (even if they are part of the same redecl chain inside the
3880 // derived class.)
3881 if (FoundByLookup) {
3882 if (isa<CXXMethodDecl>(FoundByLookup)) {
3883 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3884 if (!D->doesThisDeclarationHaveABody()) {
3885 if (FunctionTemplateDecl *DescribedD =
3887 // Handle a "templated" function together with its described
3888 // template. This avoids need for a similar check at import of the
3889 // described template.
3890 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3891 "Templated function mapped to non-templated?");
3892 Importer.MapImported(DescribedD,
3893 FoundByLookup->getDescribedFunctionTemplate());
3894 }
3895 return Importer.MapImported(D, FoundByLookup);
3896 } else {
3897 // Let's continue and build up the redecl chain in this case.
3898 // FIXME Merge the functions into one decl.
3899 }
3900 }
3901 }
3902 }
3903
3904 DeclarationNameInfo NameInfo(Name, Loc);
3905 // Import additional name location/type info.
3906 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3907 return std::move(Err);
3908
3909 QualType FromTy = D->getType();
3910 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3911 // Set to true if we do not import the type of the function as is. There are
3912 // cases when the original type would result in an infinite recursion during
3913 // the import. To avoid an infinite recursion when importing, we create the
3914 // FunctionDecl with a simplified function type and update it only after the
3915 // relevant AST nodes are already imported.
3916 // The type is related to TypeSourceInfo (it references the type), so we must
3917 // do the same with TypeSourceInfo.
3918 bool UsedDifferentProtoType = false;
3919 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3920 QualType FromReturnTy = FromFPT->getReturnType();
3921 // Functions with auto return type may define a struct inside their body
3922 // and the return type could refer to that struct.
3923 // E.g.: auto foo() { struct X{}; return X(); }
3924 // There are many more cases when types inside the function declaration
3925 // can appear in the return type, like types declared as typenames from
3926 // template params.
3927 // All such cases are tracked in FindFunctionDeclImportCycle.
3928 if (Importer.FindFunctionDeclImportCycle.isCycle(D)) {
3929 FromReturnTy = Importer.getFromContext().VoidTy;
3930 UsedDifferentProtoType = true;
3931 }
3932 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3933 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3934 // FunctionDecl that we are importing the FunctionProtoType for.
3935 // To avoid an infinite recursion when importing, create the FunctionDecl
3936 // with a simplified function type.
3937 if (FromEPI.ExceptionSpec.SourceDecl ||
3938 FromEPI.ExceptionSpec.SourceTemplate ||
3939 FromEPI.ExceptionSpec.NoexceptExpr) {
3941 FromEPI = DefaultEPI;
3942 UsedDifferentProtoType = true;
3943 }
3944 FromTy = Importer.getFromContext().getFunctionType(
3945 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3946 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3947 FromTy, D->getBeginLoc());
3948 }
3949
3950 Error Err = Error::success();
3951 auto ScopedReturnTypeDeclCycleDetector =
3952 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
3953 auto T = importChecked(Err, FromTy);
3954 auto TInfo = importChecked(Err, FromTSI);
3955 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3956 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3957 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3958 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3959 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
3960 TrailingRequiresClause.ConstraintExpr =
3961 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
3962 if (Err)
3963 return std::move(Err);
3964
3965 // Import the function parameters.
3967 for (auto *P : D->parameters()) {
3968 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3969 Parameters.push_back(*ToPOrErr);
3970 else
3971 return ToPOrErr.takeError();
3972 }
3973
3974 // Create the imported function.
3975 FunctionDecl *ToFunction = nullptr;
3976 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3977 ExplicitSpecifier ESpec =
3978 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3979 if (Err)
3980 return std::move(Err);
3981 auto ToInheritedConstructor = InheritedConstructor();
3982 if (FromConstructor->isInheritingConstructor()) {
3983 Expected<InheritedConstructor> ImportedInheritedCtor =
3984 import(FromConstructor->getInheritedConstructor());
3985 if (!ImportedInheritedCtor)
3986 return ImportedInheritedCtor.takeError();
3987 ToInheritedConstructor = *ImportedInheritedCtor;
3988 }
3989 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3990 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3991 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3993 ToInheritedConstructor, TrailingRequiresClause))
3994 return ToFunction;
3995 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3996
3997 Error Err = Error::success();
3998 auto ToOperatorDelete = importChecked(
3999 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4000 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4001 if (Err)
4002 return std::move(Err);
4003
4004 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4005 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4006 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4008 TrailingRequiresClause))
4009 return ToFunction;
4010
4011 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4012
4013 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4014 } else if (CXXConversionDecl *FromConversion =
4015 dyn_cast<CXXConversionDecl>(D)) {
4016 ExplicitSpecifier ESpec =
4017 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4018 if (Err)
4019 return std::move(Err);
4020 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4021 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4022 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4023 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4024 SourceLocation(), TrailingRequiresClause))
4025 return ToFunction;
4026 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4027 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4028 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4029 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4030 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4031 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4032 return ToFunction;
4033 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4034 ExplicitSpecifier ESpec =
4035 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4036 CXXConstructorDecl *Ctor =
4037 importChecked(Err, Guide->getCorrespondingConstructor());
4038 const CXXDeductionGuideDecl *SourceDG =
4039 importChecked(Err, Guide->getSourceDeductionGuide());
4040 if (Err)
4041 return std::move(Err);
4042 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4043 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4044 NameInfo, T, TInfo, ToEndLoc, Ctor,
4045 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4046 SourceDG, Guide->getSourceDeductionGuideKind()))
4047 return ToFunction;
4048 } else {
4049 if (GetImportedOrCreateDecl(
4050 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4051 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4053 D->getConstexprKind(), TrailingRequiresClause))
4054 return ToFunction;
4055 }
4056
4057 // Connect the redecl chain.
4058 if (FoundByLookup) {
4059 auto *Recent = const_cast<FunctionDecl *>(
4060 FoundByLookup->getMostRecentDecl());
4061 ToFunction->setPreviousDecl(Recent);
4062 // FIXME Probably we should merge exception specifications. E.g. In the
4063 // "To" context the existing function may have exception specification with
4064 // noexcept-unevaluated, while the newly imported function may have an
4065 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4066 // decl and its redeclarations may be required.
4067 }
4068
4069 // We will import DefaultedOrDeletedInfo later.
4070
4071 ToFunction->setQualifierInfo(ToQualifierLoc);
4072 ToFunction->setAccess(D->getAccess());
4073 ToFunction->setLexicalDeclContext(LexicalDC);
4074 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4075 ToFunction->setTrivial(D->isTrivial());
4076 ToFunction->setIsPureVirtual(D->isPureVirtual());
4077 ToFunction->setDefaulted(D->isDefaulted());
4079 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4085 ToFunction->setRangeEnd(ToEndLoc);
4086 ToFunction->setDefaultLoc(ToDefaultLoc);
4087
4088 if (auto *Info = D->getDefaultedOrDeletedInfo()) {
4089 StringLiteral *Msg = nullptr;
4090 if (StringLiteral *M = Info->getDeletedMessage()) {
4091 auto Imported = import(M);
4092 if (!Imported)
4093 return Imported.takeError();
4094 Msg = *Imported;
4095 }
4096
4098 for (DeclAccessPair P : Info->getUnqualifiedLookups()) {
4099 auto Imported = import(P.getDecl());
4100 if (!Imported)
4101 return Imported.takeError();
4102 Lookups.push_back(
4104 }
4105
4106 ToFunction->setDefaultedOrDeletedInfo(
4108 Importer.getToContext(), Lookups, Info->getFPFeatures(), Msg));
4109 }
4110
4111 // Set the parameters.
4112 for (auto *Param : Parameters) {
4113 Param->setOwningFunction(ToFunction);
4114 ToFunction->addDeclInternal(Param);
4115 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4116 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4117 }
4118 ToFunction->setParams(Parameters);
4119
4120 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4121 // params it refers to.
4122 if (TInfo) {
4123 if (auto ProtoLoc =
4124 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4125 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4126 ProtoLoc.setParam(I, Parameters[I]);
4127 }
4128 }
4129
4130 // Import the describing template function, if any.
4131 if (FromFT) {
4132 auto ToFTOrErr = import(FromFT);
4133 if (!ToFTOrErr)
4134 return ToFTOrErr.takeError();
4135 }
4136
4137 // Import Ctor initializers.
4138 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4139 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4140 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4141 // Import first, then allocate memory and copy if there was no error.
4142 if (Error Err = ImportContainerChecked(
4143 FromConstructor->inits(), CtorInitializers))
4144 return std::move(Err);
4145 auto **Memory =
4146 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4147 llvm::copy(CtorInitializers, Memory);
4148 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4149 ToCtor->setCtorInitializers(Memory);
4150 ToCtor->setNumCtorInitializers(NumInitializers);
4151 }
4152 }
4153
4154 // If it is a template, import all related things.
4155 if (Error Err = ImportTemplateInformation(D, ToFunction))
4156 return std::move(Err);
4157
4158 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4160 FromCXXMethod))
4161 return std::move(Err);
4162
4164 Error Err = ImportFunctionDeclBody(D, ToFunction);
4165
4166 if (Err)
4167 return std::move(Err);
4168 }
4169
4170 // Import and set the original type in case we used another type.
4171 if (UsedDifferentProtoType) {
4172 if (ExpectedType TyOrErr = import(D->getType()))
4173 ToFunction->setType(*TyOrErr);
4174 else
4175 return TyOrErr.takeError();
4176 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4177 ToFunction->setTypeSourceInfo(*TSIOrErr);
4178 else
4179 return TSIOrErr.takeError();
4180 }
4181
4182 // FIXME: Other bits to merge?
4183
4184 addDeclToContexts(D, ToFunction);
4185
4186 // Import the rest of the chain. I.e. import all subsequent declarations.
4187 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4188 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4189 if (!ToRedeclOrErr)
4190 return ToRedeclOrErr.takeError();
4191 }
4192
4193 return ToFunction;
4194}
4195
4199
4203
4207
4211
4216
4218 // Import the major distinguishing characteristics of a variable.
4219 DeclContext *DC, *LexicalDC;
4220 DeclarationName Name;
4221 SourceLocation Loc;
4222 NamedDecl *ToD;
4223 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4224 return std::move(Err);
4225 if (ToD)
4226 return ToD;
4227
4228 // Determine whether we've already imported this field.
4229 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4230 for (auto *FoundDecl : FoundDecls) {
4231 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4232 // For anonymous fields, match up by index.
4233 if (!Name &&
4235 ASTImporter::getFieldIndex(FoundField))
4236 continue;
4237
4238 if (Importer.IsStructurallyEquivalent(D->getType(),
4239 FoundField->getType())) {
4240 Importer.MapImported(D, FoundField);
4241 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4242 // initializer of a FieldDecl might not had been instantiated in the
4243 // "To" context. However, the "From" context might instantiated that,
4244 // thus we have to merge that.
4245 // Note: `hasInClassInitializer()` is not the same as non-null
4246 // `getInClassInitializer()` value.
4247 if (Expr *FromInitializer = D->getInClassInitializer()) {
4248 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4249 // Import of the FromInitializer may result in the setting of
4250 // InClassInitializer. If not, set it here.
4251 assert(FoundField->hasInClassInitializer() &&
4252 "Field should have an in-class initializer if it has an "
4253 "expression for it.");
4254 if (!FoundField->getInClassInitializer())
4255 FoundField->setInClassInitializer(*ToInitializerOrErr);
4256 } else {
4257 return ToInitializerOrErr.takeError();
4258 }
4259 }
4260 return FoundField;
4261 }
4262
4263 // FIXME: Why is this case not handled with calling HandleNameConflict?
4264 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4265 << Name << D->getType() << FoundField->getType();
4266 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4267 << FoundField->getType();
4268
4269 return make_error<ASTImportError>(ASTImportError::NameConflict);
4270 }
4271 }
4272
4273 Error Err = Error::success();
4274 auto ToType = importChecked(Err, D->getType());
4275 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4276 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4277 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4278 if (Err)
4279 return std::move(Err);
4280 const Type *ToCapturedVLAType = nullptr;
4281 if (Error Err = Importer.importInto(
4282 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4283 return std::move(Err);
4284
4285 FieldDecl *ToField;
4286 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4287 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4288 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4289 D->getInClassInitStyle()))
4290 return ToField;
4291
4292 ToField->setAccess(D->getAccess());
4293 ToField->setLexicalDeclContext(LexicalDC);
4294 ToField->setImplicit(D->isImplicit());
4295 if (ToCapturedVLAType)
4296 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4297 LexicalDC->addDeclInternal(ToField);
4298 // Import initializer only after the field was created, it may have recursive
4299 // reference to the field.
4300 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4301 if (Err)
4302 return std::move(Err);
4303 if (ToInitializer) {
4304 auto *AlreadyImported = ToField->getInClassInitializer();
4305 if (AlreadyImported)
4306 assert(ToInitializer == AlreadyImported &&
4307 "Duplicate import of in-class initializer.");
4308 else
4309 ToField->setInClassInitializer(ToInitializer);
4310 }
4311
4312 return ToField;
4313}
4314
4316 // Import the major distinguishing characteristics of a variable.
4317 DeclContext *DC, *LexicalDC;
4318 DeclarationName Name;
4319 SourceLocation Loc;
4320 NamedDecl *ToD;
4321 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4322 return std::move(Err);
4323 if (ToD)
4324 return ToD;
4325
4326 // Determine whether we've already imported this field.
4327 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4328 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4329 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4330 // For anonymous indirect fields, match up by index.
4331 if (!Name &&
4333 ASTImporter::getFieldIndex(FoundField))
4334 continue;
4335
4336 if (Importer.IsStructurallyEquivalent(D->getType(),
4337 FoundField->getType(),
4338 !Name.isEmpty())) {
4339 Importer.MapImported(D, FoundField);
4340 return FoundField;
4341 }
4342
4343 // If there are more anonymous fields to check, continue.
4344 if (!Name && I < N-1)
4345 continue;
4346
4347 // FIXME: Why is this case not handled with calling HandleNameConflict?
4348 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4349 << Name << D->getType() << FoundField->getType();
4350 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4351 << FoundField->getType();
4352
4353 return make_error<ASTImportError>(ASTImportError::NameConflict);
4354 }
4355 }
4356
4357 // Import the type.
4358 auto TypeOrErr = import(D->getType());
4359 if (!TypeOrErr)
4360 return TypeOrErr.takeError();
4361
4362 auto **NamedChain =
4363 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4364
4365 unsigned i = 0;
4366 for (auto *PI : D->chain())
4367 if (Expected<NamedDecl *> ToD = import(PI))
4368 NamedChain[i++] = *ToD;
4369 else
4370 return ToD.takeError();
4371
4372 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4373 IndirectFieldDecl *ToIndirectField;
4374 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4375 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4376 // FIXME here we leak `NamedChain` which is allocated before
4377 return ToIndirectField;
4378
4379 ToIndirectField->setAccess(D->getAccess());
4380 ToIndirectField->setLexicalDeclContext(LexicalDC);
4381 LexicalDC->addDeclInternal(ToIndirectField);
4382 return ToIndirectField;
4383}
4384
4385/// Used as return type of getFriendCountAndPosition.
4387 /// Number of similar looking friends.
4388 unsigned int TotalCount;
4389 /// Index of the specific FriendDecl.
4390 unsigned int IndexOfDecl;
4391};
4392
4393static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4394 FriendDecl *FD2) {
4395 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4396 return false;
4397
4398 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4399 return Importer.IsStructurallyEquivalent(
4400 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4401
4402 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4404 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4405 FD2->getASTContext(), NonEquivalentDecls,
4407 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4408 return Ctx.IsEquivalent(FD1, FD2);
4409}
4410
4412 FriendDecl *FD) {
4413 unsigned int FriendCount = 0;
4414 UnsignedOrNone FriendPosition = std::nullopt;
4415 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4416
4417 for (FriendDecl *FoundFriend : RD->friends()) {
4418 if (FoundFriend == FD) {
4419 FriendPosition = FriendCount;
4420 ++FriendCount;
4421 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4422 ++FriendCount;
4423 }
4424 }
4425
4426 assert(FriendPosition && "Friend decl not found in own parent.");
4427
4428 return {FriendCount, *FriendPosition};
4429}
4430
4432 // Import the major distinguishing characteristics of a declaration.
4433 DeclContext *DC, *LexicalDC;
4434 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4435 return std::move(Err);
4436
4437 // Determine whether we've already imported this decl.
4438 // FriendDecl is not a NamedDecl so we cannot use lookup.
4439 // We try to maintain order and count of redundant friend declarations.
4440 const auto *RD = cast<CXXRecordDecl>(DC);
4441 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4442 for (FriendDecl *ImportedFriend : RD->friends())
4443 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4444 ImportedEquivalentFriends.push_back(ImportedFriend);
4445
4446 FriendCountAndPosition CountAndPosition =
4447 getFriendCountAndPosition(Importer, D);
4448
4449 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4450 "Class with non-matching friends is imported, ODR check wrong?");
4451 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4452 return Importer.MapImported(
4453 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4454
4455 // Not found. Create it.
4456 // The declarations will be put into order later by ImportDeclContext.
4458 if (NamedDecl *FriendD = D->getFriendDecl()) {
4459 NamedDecl *ToFriendD;
4460 if (Error Err = importInto(ToFriendD, FriendD))
4461 return std::move(Err);
4462
4463 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4464 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4465 ToFriendD->setObjectOfFriendDecl(false);
4466
4467 ToFU = ToFriendD;
4468 } else { // The friend is a type, not a decl.
4469 if (auto TSIOrErr = import(D->getFriendType()))
4470 ToFU = *TSIOrErr;
4471 else
4472 return TSIOrErr.takeError();
4473 }
4474
4475 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4476 auto **FromTPLists = D->getTrailingObjects();
4477 for (unsigned I = 0; I < D->NumTPLists; I++) {
4478 if (auto ListOrErr = import(FromTPLists[I]))
4479 ToTPLists[I] = *ListOrErr;
4480 else
4481 return ListOrErr.takeError();
4482 }
4483
4484 auto LocationOrErr = import(D->getLocation());
4485 if (!LocationOrErr)
4486 return LocationOrErr.takeError();
4487 auto FriendLocOrErr = import(D->getFriendLoc());
4488 if (!FriendLocOrErr)
4489 return FriendLocOrErr.takeError();
4490 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4491 if (!EllipsisLocOrErr)
4492 return EllipsisLocOrErr.takeError();
4493
4494 FriendDecl *FrD;
4495 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4496 *LocationOrErr, ToFU, *FriendLocOrErr,
4497 *EllipsisLocOrErr, ToTPLists))
4498 return FrD;
4499
4500 FrD->setAccess(D->getAccess());
4501 FrD->setLexicalDeclContext(LexicalDC);
4502 LexicalDC->addDeclInternal(FrD);
4503 return FrD;
4504}
4505
4507 // Import the major distinguishing characteristics of an ivar.
4508 DeclContext *DC, *LexicalDC;
4509 DeclarationName Name;
4510 SourceLocation Loc;
4511 NamedDecl *ToD;
4512 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4513 return std::move(Err);
4514 if (ToD)
4515 return ToD;
4516
4517 // Determine whether we've already imported this ivar
4518 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4519 for (auto *FoundDecl : FoundDecls) {
4520 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4521 if (Importer.IsStructurallyEquivalent(D->getType(),
4522 FoundIvar->getType())) {
4523 Importer.MapImported(D, FoundIvar);
4524 return FoundIvar;
4525 }
4526
4527 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4528 << Name << D->getType() << FoundIvar->getType();
4529 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4530 << FoundIvar->getType();
4531
4532 return make_error<ASTImportError>(ASTImportError::NameConflict);
4533 }
4534 }
4535
4536 Error Err = Error::success();
4537 auto ToType = importChecked(Err, D->getType());
4538 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4539 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4540 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4541 if (Err)
4542 return std::move(Err);
4543
4544 ObjCIvarDecl *ToIvar;
4545 if (GetImportedOrCreateDecl(
4546 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4547 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4548 ToType, ToTypeSourceInfo,
4549 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4550 return ToIvar;
4551
4552 ToIvar->setLexicalDeclContext(LexicalDC);
4553 LexicalDC->addDeclInternal(ToIvar);
4554 return ToIvar;
4555}
4556
4558
4560 auto RedeclIt = Redecls.begin();
4561 // Import the first part of the decl chain. I.e. import all previous
4562 // declarations starting from the canonical decl.
4563 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4564 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4565 if (!RedeclOrErr)
4566 return RedeclOrErr.takeError();
4567 }
4568 assert(*RedeclIt == D);
4569
4570 // Import the major distinguishing characteristics of a variable.
4571 DeclContext *DC, *LexicalDC;
4572 DeclarationName Name;
4573 SourceLocation Loc;
4574 NamedDecl *ToD;
4575 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4576 return std::move(Err);
4577 if (ToD)
4578 return ToD;
4579
4580 // Try to find a variable in our own ("to") context with the same name and
4581 // in the same context as the variable we're importing.
4582 VarDecl *FoundByLookup = nullptr;
4583 if (D->isFileVarDecl()) {
4584 SmallVector<NamedDecl *, 4> ConflictingDecls;
4585 unsigned IDNS = Decl::IDNS_Ordinary;
4586 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4587 for (auto *FoundDecl : FoundDecls) {
4588 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4589 continue;
4590
4591 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4592 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4593 continue;
4594 if (Importer.IsStructurallyEquivalent(D->getType(),
4595 FoundVar->getType())) {
4596
4597 // The VarDecl in the "From" context has a definition, but in the
4598 // "To" context we already have a definition.
4599 VarDecl *FoundDef = FoundVar->getDefinition();
4600 if (D->isThisDeclarationADefinition() && FoundDef)
4601 // FIXME Check for ODR error if the two definitions have
4602 // different initializers?
4603 return Importer.MapImported(D, FoundDef);
4604
4605 // The VarDecl in the "From" context has an initializer, but in the
4606 // "To" context we already have an initializer.
4607 const VarDecl *FoundDInit = nullptr;
4608 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4609 // FIXME Diagnose ODR error if the two initializers are different?
4610 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4611
4612 FoundByLookup = FoundVar;
4613 break;
4614 }
4615
4616 const ArrayType *FoundArray
4617 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4618 const ArrayType *TArray
4619 = Importer.getToContext().getAsArrayType(D->getType());
4620 if (FoundArray && TArray) {
4621 if (isa<IncompleteArrayType>(FoundArray) &&
4622 isa<ConstantArrayType>(TArray)) {
4623 // Import the type.
4624 if (auto TyOrErr = import(D->getType()))
4625 FoundVar->setType(*TyOrErr);
4626 else
4627 return TyOrErr.takeError();
4628
4629 FoundByLookup = FoundVar;
4630 break;
4631 } else if (isa<IncompleteArrayType>(TArray) &&
4632 isa<ConstantArrayType>(FoundArray)) {
4633 FoundByLookup = FoundVar;
4634 break;
4635 }
4636 }
4637
4638 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4639 << Name << D->getType() << FoundVar->getType();
4640 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4641 << FoundVar->getType();
4642 ConflictingDecls.push_back(FoundDecl);
4643 }
4644 }
4645
4646 if (!ConflictingDecls.empty()) {
4647 ExpectedName NameOrErr = Importer.HandleNameConflict(
4648 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4649 if (NameOrErr)
4650 Name = NameOrErr.get();
4651 else
4652 return NameOrErr.takeError();
4653 }
4654 }
4655
4656 Error Err = Error::success();
4657 auto ToType = importChecked(Err, D->getType());
4658 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4659 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4660 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4661 if (Err)
4662 return std::move(Err);
4663
4664 VarDecl *ToVar;
4665 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4666 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4667 if (Error Err =
4668 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4669 return std::move(Err);
4670 DecompositionDecl *ToDecomp;
4671 if (GetImportedOrCreateDecl(
4672 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4673 Loc, FromDecomp->getRSquareLoc(), ToType, ToTypeSourceInfo,
4675 return ToDecomp;
4676 ToVar = ToDecomp;
4677 } else {
4678 // Create the imported variable.
4679 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4680 ToInnerLocStart, Loc,
4681 Name.getAsIdentifierInfo(), ToType,
4682 ToTypeSourceInfo, D->getStorageClass()))
4683 return ToVar;
4684 }
4685
4686 ToVar->setTSCSpec(D->getTSCSpec());
4687 ToVar->setQualifierInfo(ToQualifierLoc);
4688 ToVar->setAccess(D->getAccess());
4689 ToVar->setLexicalDeclContext(LexicalDC);
4690 if (D->isInlineSpecified())
4691 ToVar->setInlineSpecified();
4692 if (D->isInline())
4693 ToVar->setImplicitlyInline();
4694
4695 if (FoundByLookup) {
4696 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4697 ToVar->setPreviousDecl(Recent);
4698 }
4699
4700 // Import the described template, if any.
4701 if (D->getDescribedVarTemplate()) {
4702 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4703 if (!ToVTOrErr)
4704 return ToVTOrErr.takeError();
4706 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4708 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4709 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4710 else
4711 return ToInstOrErr.takeError();
4712 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4714 else
4715 return POIOrErr.takeError();
4716 }
4717
4718 if (Error Err = ImportInitializer(D, ToVar))
4719 return std::move(Err);
4720
4721 if (D->isConstexpr())
4722 ToVar->setConstexpr(true);
4723
4724 addDeclToContexts(D, ToVar);
4725
4726 // Import the rest of the chain. I.e. import all subsequent declarations.
4727 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4728 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4729 if (!RedeclOrErr)
4730 return RedeclOrErr.takeError();
4731 }
4732
4733 return ToVar;
4734}
4735
4737 // Parameters are created in the translation unit's context, then moved
4738 // into the function declaration's context afterward.
4739 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4740
4741 Error Err = Error::success();
4742 auto ToDeclName = importChecked(Err, D->getDeclName());
4743 auto ToLocation = importChecked(Err, D->getLocation());
4744 auto ToType = importChecked(Err, D->getType());
4745 if (Err)
4746 return std::move(Err);
4747
4748 // Create the imported parameter.
4749 ImplicitParamDecl *ToParm = nullptr;
4750 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4751 ToLocation, ToDeclName.getAsIdentifierInfo(),
4752 ToType, D->getParameterKind()))
4753 return ToParm;
4754 return ToParm;
4755}
4756
4758 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4759
4760 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4761 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4762 else
4763 return LocOrErr.takeError();
4764
4766 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4767
4768 if (FromParam->hasUninstantiatedDefaultArg()) {
4769 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4770 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4771 else
4772 return ToDefArgOrErr.takeError();
4773 } else if (FromParam->hasUnparsedDefaultArg()) {
4774 ToParam->setUnparsedDefaultArg();
4775 } else if (FromParam->hasDefaultArg()) {
4776 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4777 ToParam->setDefaultArg(*ToDefArgOrErr);
4778 else
4779 return ToDefArgOrErr.takeError();
4780 }
4781
4782 return Error::success();
4783}
4784
4787 Error Err = Error::success();
4788 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4789 ConstructorUsingShadowDecl *ToShadow =
4790 importChecked(Err, From.getShadowDecl());
4791 if (Err)
4792 return std::move(Err);
4793 return InheritedConstructor(ToShadow, ToBaseCtor);
4794}
4795
4797 // Parameters are created in the translation unit's context, then moved
4798 // into the function declaration's context afterward.
4799 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4800
4801 Error Err = Error::success();
4802 auto ToDeclName = importChecked(Err, D->getDeclName());
4803 auto ToLocation = importChecked(Err, D->getLocation());
4804 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4805 auto ToType = importChecked(Err, D->getType());
4806 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4807 if (Err)
4808 return std::move(Err);
4809
4810 ParmVarDecl *ToParm;
4811 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4812 ToInnerLocStart, ToLocation,
4813 ToDeclName.getAsIdentifierInfo(), ToType,
4814 ToTypeSourceInfo, D->getStorageClass(),
4815 /*DefaultArg*/ nullptr))
4816 return ToParm;
4817
4818 // Set the default argument. It should be no problem if it was already done.
4819 // Do not import the default expression before GetImportedOrCreateDecl call
4820 // to avoid possible infinite import loop because circular dependency.
4821 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4822 return std::move(Err);
4823
4824 if (D->isObjCMethodParameter()) {
4827 } else {
4830 }
4831
4832 return ToParm;
4833}
4834
4836 // Import the major distinguishing characteristics of a method.
4837 DeclContext *DC, *LexicalDC;
4838 DeclarationName Name;
4839 SourceLocation Loc;
4840 NamedDecl *ToD;
4841 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4842 return std::move(Err);
4843 if (ToD)
4844 return ToD;
4845
4846 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4847 for (auto *FoundDecl : FoundDecls) {
4848 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4849 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4850 continue;
4851
4852 // Check return types.
4853 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4854 FoundMethod->getReturnType())) {
4855 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4856 << D->isInstanceMethod() << Name << D->getReturnType()
4857 << FoundMethod->getReturnType();
4858 Importer.ToDiag(FoundMethod->getLocation(),
4859 diag::note_odr_objc_method_here)
4860 << D->isInstanceMethod() << Name;
4861
4862 return make_error<ASTImportError>(ASTImportError::NameConflict);
4863 }
4864
4865 // Check the number of parameters.
4866 if (D->param_size() != FoundMethod->param_size()) {
4867 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4868 << D->isInstanceMethod() << Name
4869 << D->param_size() << FoundMethod->param_size();
4870 Importer.ToDiag(FoundMethod->getLocation(),
4871 diag::note_odr_objc_method_here)
4872 << D->isInstanceMethod() << Name;
4873
4874 return make_error<ASTImportError>(ASTImportError::NameConflict);
4875 }
4876
4877 // Check parameter types.
4879 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4880 P != PEnd; ++P, ++FoundP) {
4881 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4882 (*FoundP)->getType())) {
4883 Importer.FromDiag((*P)->getLocation(),
4884 diag::warn_odr_objc_method_param_type_inconsistent)
4885 << D->isInstanceMethod() << Name
4886 << (*P)->getType() << (*FoundP)->getType();
4887 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4888 << (*FoundP)->getType();
4889
4890 return make_error<ASTImportError>(ASTImportError::NameConflict);
4891 }
4892 }
4893
4894 // Check variadic/non-variadic.
4895 // Check the number of parameters.
4896 if (D->isVariadic() != FoundMethod->isVariadic()) {
4897 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4898 << D->isInstanceMethod() << Name;
4899 Importer.ToDiag(FoundMethod->getLocation(),
4900 diag::note_odr_objc_method_here)
4901 << D->isInstanceMethod() << Name;
4902
4903 return make_error<ASTImportError>(ASTImportError::NameConflict);
4904 }
4905
4906 // FIXME: Any other bits we need to merge?
4907 return Importer.MapImported(D, FoundMethod);
4908 }
4909 }
4910
4911 Error Err = Error::success();
4912 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4913 auto ToReturnType = importChecked(Err, D->getReturnType());
4914 auto ToReturnTypeSourceInfo =
4916 if (Err)
4917 return std::move(Err);
4918
4919 ObjCMethodDecl *ToMethod;
4920 if (GetImportedOrCreateDecl(
4921 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4922 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4926 return ToMethod;
4927
4928 // FIXME: When we decide to merge method definitions, we'll need to
4929 // deal with implicit parameters.
4930
4931 // Import the parameters
4933 for (auto *FromP : D->parameters()) {
4934 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4935 ToParams.push_back(*ToPOrErr);
4936 else
4937 return ToPOrErr.takeError();
4938 }
4939
4940 // Set the parameters.
4941 for (auto *ToParam : ToParams) {
4942 ToParam->setOwningFunction(ToMethod);
4943 ToMethod->addDeclInternal(ToParam);
4944 }
4945
4947 D->getSelectorLocs(FromSelLocs);
4948 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4949 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4950 return std::move(Err);
4951
4952 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4953
4954 ToMethod->setLexicalDeclContext(LexicalDC);
4955 LexicalDC->addDeclInternal(ToMethod);
4956
4957 // Implicit params are declared when Sema encounters the definition but this
4958 // never happens when the method is imported. Manually declare the implicit
4959 // params now that the MethodDecl knows its class interface.
4960 if (D->getSelfDecl())
4961 ToMethod->createImplicitParams(Importer.getToContext(),
4962 ToMethod->getClassInterface());
4963
4964 return ToMethod;
4965}
4966
4968 // Import the major distinguishing characteristics of a category.
4969 DeclContext *DC, *LexicalDC;
4970 DeclarationName Name;
4971 SourceLocation Loc;
4972 NamedDecl *ToD;
4973 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4974 return std::move(Err);
4975 if (ToD)
4976 return ToD;
4977
4978 Error Err = Error::success();
4979 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4980 auto ToLocation = importChecked(Err, D->getLocation());
4981 auto ToColonLoc = importChecked(Err, D->getColonLoc());
4982 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4983 if (Err)
4984 return std::move(Err);
4985
4987 if (GetImportedOrCreateDecl(
4988 Result, D, Importer.getToContext(), DC, D->getVariance(),
4989 ToVarianceLoc, D->getIndex(),
4990 ToLocation, Name.getAsIdentifierInfo(),
4991 ToColonLoc, ToTypeSourceInfo))
4992 return Result;
4993
4994 // Only import 'ObjCTypeParamType' after the decl is created.
4995 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4996 if (Err)
4997 return std::move(Err);
4998 Result->setTypeForDecl(ToTypeForDecl);
4999 Result->setLexicalDeclContext(LexicalDC);
5000 return Result;
5001}
5002
5004 // Import the major distinguishing characteristics of a category.
5005 DeclContext *DC, *LexicalDC;
5006 DeclarationName Name;
5007 SourceLocation Loc;
5008 NamedDecl *ToD;
5009 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5010 return std::move(Err);
5011 if (ToD)
5012 return ToD;
5013
5014 ObjCInterfaceDecl *ToInterface;
5015 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5016 return std::move(Err);
5017
5018 // Determine if we've already encountered this category.
5019 ObjCCategoryDecl *MergeWithCategory
5020 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5021 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5022 if (!ToCategory) {
5023
5024 Error Err = Error::success();
5025 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5026 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5027 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5028 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5029 if (Err)
5030 return std::move(Err);
5031
5032 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5033 ToAtStartLoc, Loc,
5034 ToCategoryNameLoc,
5035 Name.getAsIdentifierInfo(), ToInterface,
5036 /*TypeParamList=*/nullptr,
5037 ToIvarLBraceLoc,
5038 ToIvarRBraceLoc))
5039 return ToCategory;
5040
5041 ToCategory->setLexicalDeclContext(LexicalDC);
5042 LexicalDC->addDeclInternal(ToCategory);
5043 // Import the type parameter list after MapImported, to avoid
5044 // loops when bringing in their DeclContext.
5045 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5046 ToCategory->setTypeParamList(*PListOrErr);
5047 else
5048 return PListOrErr.takeError();
5049
5050 // Import protocols
5052 SmallVector<SourceLocation, 4> ProtocolLocs;
5054 = D->protocol_loc_begin();
5056 FromProtoEnd = D->protocol_end();
5057 FromProto != FromProtoEnd;
5058 ++FromProto, ++FromProtoLoc) {
5059 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5060 Protocols.push_back(*ToProtoOrErr);
5061 else
5062 return ToProtoOrErr.takeError();
5063
5064 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5065 ProtocolLocs.push_back(*ToProtoLocOrErr);
5066 else
5067 return ToProtoLocOrErr.takeError();
5068 }
5069
5070 // FIXME: If we're merging, make sure that the protocol list is the same.
5071 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5072 ProtocolLocs.data(), Importer.getToContext());
5073
5074 } else {
5075 Importer.MapImported(D, ToCategory);
5076 }
5077
5078 // Import all of the members of this category.
5079 if (Error Err = ImportDeclContext(D))
5080 return std::move(Err);
5081
5082 // If we have an implementation, import it as well.
5083 if (D->getImplementation()) {
5084 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5085 import(D->getImplementation()))
5086 ToCategory->setImplementation(*ToImplOrErr);
5087 else
5088 return ToImplOrErr.takeError();
5089 }
5090
5091 return ToCategory;
5092}
5093
5096 if (To->getDefinition()) {
5098 if (Error Err = ImportDeclContext(From))
5099 return Err;
5100 return Error::success();
5101 }
5102
5103 // Start the protocol definition
5104 To->startDefinition();
5105
5106 // Import protocols
5108 SmallVector<SourceLocation, 4> ProtocolLocs;
5110 From->protocol_loc_begin();
5111 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5112 FromProtoEnd = From->protocol_end();
5113 FromProto != FromProtoEnd;
5114 ++FromProto, ++FromProtoLoc) {
5115 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5116 Protocols.push_back(*ToProtoOrErr);
5117 else
5118 return ToProtoOrErr.takeError();
5119
5120 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5121 ProtocolLocs.push_back(*ToProtoLocOrErr);
5122 else
5123 return ToProtoLocOrErr.takeError();
5124
5125 }
5126
5127 // FIXME: If we're merging, make sure that the protocol list is the same.
5128 To->setProtocolList(Protocols.data(), Protocols.size(),
5129 ProtocolLocs.data(), Importer.getToContext());
5130
5131 if (shouldForceImportDeclContext(Kind)) {
5132 // Import all of the members of this protocol.
5133 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5134 return Err;
5135 }
5136 return Error::success();
5137}
5138
5140 // If this protocol has a definition in the translation unit we're coming
5141 // from, but this particular declaration is not that definition, import the
5142 // definition and map to that.
5144 if (Definition && Definition != D) {
5145 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5146 return Importer.MapImported(D, *ImportedDefOrErr);
5147 else
5148 return ImportedDefOrErr.takeError();
5149 }
5150
5151 // Import the major distinguishing characteristics of a protocol.
5152 DeclContext *DC, *LexicalDC;
5153 DeclarationName Name;
5154 SourceLocation Loc;
5155 NamedDecl *ToD;
5156 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5157 return std::move(Err);
5158 if (ToD)
5159 return ToD;
5160
5161 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5162 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5163 for (auto *FoundDecl : FoundDecls) {
5164 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5165 continue;
5166
5167 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5168 break;
5169 }
5170
5171 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5172 if (!ToProto) {
5173 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5174 if (!ToAtBeginLocOrErr)
5175 return ToAtBeginLocOrErr.takeError();
5176
5177 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5178 Name.getAsIdentifierInfo(), Loc,
5179 *ToAtBeginLocOrErr,
5180 /*PrevDecl=*/nullptr))
5181 return ToProto;
5182 ToProto->setLexicalDeclContext(LexicalDC);
5183 LexicalDC->addDeclInternal(ToProto);
5184 }
5185
5186 Importer.MapImported(D, ToProto);
5187
5189 if (Error Err = ImportDefinition(D, ToProto))
5190 return std::move(Err);
5191
5192 return ToProto;
5193}
5194
5196 DeclContext *DC, *LexicalDC;
5197 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5198 return std::move(Err);
5199
5200 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5201 if (!ExternLocOrErr)
5202 return ExternLocOrErr.takeError();
5203
5204 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5205 if (!LangLocOrErr)
5206 return LangLocOrErr.takeError();
5207
5208 bool HasBraces = D->hasBraces();
5209
5210 LinkageSpecDecl *ToLinkageSpec;
5211 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5212 *ExternLocOrErr, *LangLocOrErr,
5213 D->getLanguage(), HasBraces))
5214 return ToLinkageSpec;
5215
5216 if (HasBraces) {
5217 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5218 if (!RBraceLocOrErr)
5219 return RBraceLocOrErr.takeError();
5220 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5221 }
5222
5223 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5224 LexicalDC->addDeclInternal(ToLinkageSpec);
5225
5226 return ToLinkageSpec;
5227}
5228
5230 BaseUsingDecl *ToSI) {
5231 for (UsingShadowDecl *FromShadow : D->shadows()) {
5232 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5233 ToSI->addShadowDecl(*ToShadowOrErr);
5234 else
5235 // FIXME: We return error here but the definition is already created
5236 // and available with lookups. How to fix this?..
5237 return ToShadowOrErr.takeError();
5238 }
5239 return ToSI;
5240}
5241
5243 DeclContext *DC, *LexicalDC;
5244 DeclarationName Name;
5245 SourceLocation Loc;
5246 NamedDecl *ToD = nullptr;
5247 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5248 return std::move(Err);
5249 if (ToD)
5250 return ToD;
5251
5252 Error Err = Error::success();
5253 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5254 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5255 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5256 if (Err)
5257 return std::move(Err);
5258
5259 DeclarationNameInfo NameInfo(Name, ToLoc);
5260 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5261 return std::move(Err);
5262
5263 UsingDecl *ToUsing;
5264 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5265 ToUsingLoc, ToQualifierLoc, NameInfo,
5266 D->hasTypename()))
5267 return ToUsing;
5268
5269 ToUsing->setLexicalDeclContext(LexicalDC);
5270 LexicalDC->addDeclInternal(ToUsing);
5271
5272 if (NamedDecl *FromPattern =
5273 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5274 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5275 Importer.getToContext().setInstantiatedFromUsingDecl(
5276 ToUsing, *ToPatternOrErr);
5277 else
5278 return ToPatternOrErr.takeError();
5279 }
5280
5281 return ImportUsingShadowDecls(D, ToUsing);
5282}
5283
5285 DeclContext *DC, *LexicalDC;
5286 DeclarationName Name;
5287 SourceLocation Loc;
5288 NamedDecl *ToD = nullptr;
5289 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5290 return std::move(Err);
5291 if (ToD)
5292 return ToD;
5293
5294 Error Err = Error::success();
5295 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5296 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5297 auto ToNameLoc = importChecked(Err, D->getLocation());
5298 auto *ToEnumType = importChecked(Err, D->getEnumType());
5299 if (Err)
5300 return std::move(Err);
5301
5302 UsingEnumDecl *ToUsingEnum;
5303 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5304 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5305 return ToUsingEnum;
5306
5307 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5308 LexicalDC->addDeclInternal(ToUsingEnum);
5309
5310 if (UsingEnumDecl *FromPattern =
5311 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5312 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5313 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5314 *ToPatternOrErr);
5315 else
5316 return ToPatternOrErr.takeError();
5317 }
5318
5319 return ImportUsingShadowDecls(D, ToUsingEnum);
5320}
5321
5323 DeclContext *DC, *LexicalDC;
5324 DeclarationName Name;
5325 SourceLocation Loc;
5326 NamedDecl *ToD = nullptr;
5327 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5328 return std::move(Err);
5329 if (ToD)
5330 return ToD;
5331
5332 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5333 if (!ToIntroducerOrErr)
5334 return ToIntroducerOrErr.takeError();
5335
5336 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5337 if (!ToTargetOrErr)
5338 return ToTargetOrErr.takeError();
5339
5340 UsingShadowDecl *ToShadow;
5341 if (auto *FromConstructorUsingShadow =
5342 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5343 Error Err = Error::success();
5345 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5346 if (Err)
5347 return std::move(Err);
5348 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5349 // is really the "NominatedBaseClassShadowDecl" value if it exists
5350 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5351 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5352 // get the correct values.
5353 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5354 ToShadow, D, Importer.getToContext(), DC, Loc,
5355 cast<UsingDecl>(*ToIntroducerOrErr),
5356 Nominated ? Nominated : *ToTargetOrErr,
5357 FromConstructorUsingShadow->constructsVirtualBase()))
5358 return ToShadow;
5359 } else {
5360 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5361 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5362 return ToShadow;
5363 }
5364
5365 ToShadow->setLexicalDeclContext(LexicalDC);
5366 ToShadow->setAccess(D->getAccess());
5367
5368 if (UsingShadowDecl *FromPattern =
5369 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5370 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5371 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5372 ToShadow, *ToPatternOrErr);
5373 else
5374 // FIXME: We return error here but the definition is already created
5375 // and available with lookups. How to fix this?..
5376 return ToPatternOrErr.takeError();
5377 }
5378
5379 LexicalDC->addDeclInternal(ToShadow);
5380
5381 return ToShadow;
5382}
5383
5385 DeclContext *DC, *LexicalDC;
5386 DeclarationName Name;
5387 SourceLocation Loc;
5388 NamedDecl *ToD = nullptr;
5389 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5390 return std::move(Err);
5391 if (ToD)
5392 return ToD;
5393
5394 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5395 if (!ToComAncestorOrErr)
5396 return ToComAncestorOrErr.takeError();
5397
5398 Error Err = Error::success();
5399 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5400 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5401 auto ToNamespaceKeyLocation =
5403 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5404 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5405 if (Err)
5406 return std::move(Err);
5407
5408 UsingDirectiveDecl *ToUsingDir;
5409 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5410 ToUsingLoc,
5411 ToNamespaceKeyLocation,
5412 ToQualifierLoc,
5413 ToIdentLocation,
5414 ToNominatedNamespace, *ToComAncestorOrErr))
5415 return ToUsingDir;
5416
5417 ToUsingDir->setLexicalDeclContext(LexicalDC);
5418 LexicalDC->addDeclInternal(ToUsingDir);
5419
5420 return ToUsingDir;
5421}
5422
5424 DeclContext *DC, *LexicalDC;
5425 DeclarationName Name;
5426 SourceLocation Loc;
5427 NamedDecl *ToD = nullptr;
5428 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5429 return std::move(Err);
5430 if (ToD)
5431 return ToD;
5432
5433 auto ToInstantiatedFromUsingOrErr =
5434 Importer.Import(D->getInstantiatedFromUsingDecl());
5435 if (!ToInstantiatedFromUsingOrErr)
5436 return ToInstantiatedFromUsingOrErr.takeError();
5437 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5438 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5439 return std::move(Err);
5440
5441 UsingPackDecl *ToUsingPack;
5442 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5443 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5444 Expansions))
5445 return ToUsingPack;
5446
5447 addDeclToContexts(D, ToUsingPack);
5448
5449 return ToUsingPack;
5450}
5451
5454 DeclContext *DC, *LexicalDC;
5455 DeclarationName Name;
5456 SourceLocation Loc;
5457 NamedDecl *ToD = nullptr;
5458 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5459 return std::move(Err);
5460 if (ToD)
5461 return ToD;
5462
5463 Error Err = Error::success();
5464 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5465 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5466 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5467 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5468 if (Err)
5469 return std::move(Err);
5470
5471 DeclarationNameInfo NameInfo(Name, ToLoc);
5472 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5473 return std::move(Err);
5474
5475 UnresolvedUsingValueDecl *ToUsingValue;
5476 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5477 ToUsingLoc, ToQualifierLoc, NameInfo,
5478 ToEllipsisLoc))
5479 return ToUsingValue;
5480
5481 ToUsingValue->setAccess(D->getAccess());
5482 ToUsingValue->setLexicalDeclContext(LexicalDC);
5483 LexicalDC->addDeclInternal(ToUsingValue);
5484
5485 return ToUsingValue;
5486}
5487
5490 DeclContext *DC, *LexicalDC;
5491 DeclarationName Name;
5492 SourceLocation Loc;
5493 NamedDecl *ToD = nullptr;
5494 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5495 return std::move(Err);
5496 if (ToD)
5497 return ToD;
5498
5499 Error Err = Error::success();
5500 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5501 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5502 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5503 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5504 if (Err)
5505 return std::move(Err);
5506
5508 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5509 ToUsingLoc, ToTypenameLoc,
5510 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5511 return ToUsing;
5512
5513 ToUsing->setAccess(D->getAccess());
5514 ToUsing->setLexicalDeclContext(LexicalDC);
5515 LexicalDC->addDeclInternal(ToUsing);
5516
5517 return ToUsing;
5518}
5519
5521 Decl* ToD = nullptr;
5522 switch (D->getBuiltinTemplateKind()) {
5523#define BuiltinTemplate(BTName) \
5524 case BuiltinTemplateKind::BTK##BTName: \
5525 ToD = Importer.getToContext().get##BTName##Decl(); \
5526 break;
5527#include "clang/Basic/BuiltinTemplates.inc"
5528 }
5529 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5530 Importer.MapImported(D, ToD);
5531 return ToD;
5532}
5533
5536 if (To->getDefinition()) {
5537 // Check consistency of superclass.
5538 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5539 if (FromSuper) {
5540 if (auto FromSuperOrErr = import(FromSuper))
5541 FromSuper = *FromSuperOrErr;
5542 else
5543 return FromSuperOrErr.takeError();
5544 }
5545
5546 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5547 if ((bool)FromSuper != (bool)ToSuper ||
5548 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5549 Importer.ToDiag(To->getLocation(),
5550 diag::warn_odr_objc_superclass_inconsistent)
5551 << To->getDeclName();
5552 if (ToSuper)
5553 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5554 << To->getSuperClass()->getDeclName();
5555 else
5556 Importer.ToDiag(To->getLocation(),
5557 diag::note_odr_objc_missing_superclass);
5558 if (From->getSuperClass())
5559 Importer.FromDiag(From->getSuperClassLoc(),
5560 diag::note_odr_objc_superclass)
5561 << From->getSuperClass()->getDeclName();
5562 else
5563 Importer.FromDiag(From->getLocation(),
5564 diag::note_odr_objc_missing_superclass);
5565 }
5566
5568 if (Error Err = ImportDeclContext(From))
5569 return Err;
5570 return Error::success();
5571 }
5572
5573 // Start the definition.
5574 To->startDefinition();
5575
5576 // If this class has a superclass, import it.
5577 if (From->getSuperClass()) {
5578 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5579 To->setSuperClass(*SuperTInfoOrErr);
5580 else
5581 return SuperTInfoOrErr.takeError();
5582 }
5583
5584 // Import protocols
5586 SmallVector<SourceLocation, 4> ProtocolLocs;
5588 From->protocol_loc_begin();
5589
5591 FromProtoEnd = From->protocol_end();
5592 FromProto != FromProtoEnd;
5593 ++FromProto, ++FromProtoLoc) {
5594 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5595 Protocols.push_back(*ToProtoOrErr);
5596 else
5597 return ToProtoOrErr.takeError();
5598
5599 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5600 ProtocolLocs.push_back(*ToProtoLocOrErr);
5601 else
5602 return ToProtoLocOrErr.takeError();
5603
5604 }
5605
5606 // FIXME: If we're merging, make sure that the protocol list is the same.
5607 To->setProtocolList(Protocols.data(), Protocols.size(),
5608 ProtocolLocs.data(), Importer.getToContext());
5609
5610 // Import categories. When the categories themselves are imported, they'll
5611 // hook themselves into this interface.
5612 for (auto *Cat : From->known_categories()) {
5613 auto ToCatOrErr = import(Cat);
5614 if (!ToCatOrErr)
5615 return ToCatOrErr.takeError();
5616 }
5617
5618 // If we have an @implementation, import it as well.
5619 if (From->getImplementation()) {
5620 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5621 import(From->getImplementation()))
5622 To->setImplementation(*ToImplOrErr);
5623 else
5624 return ToImplOrErr.takeError();
5625 }
5626
5627 // Import all of the members of this class.
5628 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5629 return Err;
5630
5631 return Error::success();
5632}
5633
5636 if (!list)
5637 return nullptr;
5638
5640 for (auto *fromTypeParam : *list) {
5641 if (auto toTypeParamOrErr = import(fromTypeParam))
5642 toTypeParams.push_back(*toTypeParamOrErr);
5643 else
5644 return toTypeParamOrErr.takeError();
5645 }
5646
5647 auto LAngleLocOrErr = import(list->getLAngleLoc());
5648 if (!LAngleLocOrErr)
5649 return LAngleLocOrErr.takeError();
5650
5651 auto RAngleLocOrErr = import(list->getRAngleLoc());
5652 if (!RAngleLocOrErr)
5653 return RAngleLocOrErr.takeError();
5654
5655 return ObjCTypeParamList::create(Importer.getToContext(),
5656 *LAngleLocOrErr,
5657 toTypeParams,
5658 *RAngleLocOrErr);
5659}
5660
5662 // If this class has a definition in the translation unit we're coming from,
5663 // but this particular declaration is not that definition, import the
5664 // definition and map to that.
5666 if (Definition && Definition != D) {
5667 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5668 return Importer.MapImported(D, *ImportedDefOrErr);
5669 else
5670 return ImportedDefOrErr.takeError();
5671 }
5672
5673 // Import the major distinguishing characteristics of an @interface.
5674 DeclContext *DC, *LexicalDC;
5675 DeclarationName Name;
5676 SourceLocation Loc;
5677 NamedDecl *ToD;
5678 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5679 return std::move(Err);
5680 if (ToD)
5681 return ToD;
5682
5683 // Look for an existing interface with the same name.
5684 ObjCInterfaceDecl *MergeWithIface = nullptr;
5685 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5686 for (auto *FoundDecl : FoundDecls) {
5687 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5688 continue;
5689
5690 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5691 break;
5692 }
5693
5694 // Create an interface declaration, if one does not already exist.
5695 ObjCInterfaceDecl *ToIface = MergeWithIface;
5696 if (!ToIface) {
5697 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5698 if (!AtBeginLocOrErr)
5699 return AtBeginLocOrErr.takeError();
5700
5701 if (GetImportedOrCreateDecl(
5702 ToIface, D, Importer.getToContext(), DC,
5703 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5704 /*TypeParamList=*/nullptr,
5705 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5706 return ToIface;
5707 ToIface->setLexicalDeclContext(LexicalDC);
5708 LexicalDC->addDeclInternal(ToIface);
5709 }
5710 Importer.MapImported(D, ToIface);
5711 // Import the type parameter list after MapImported, to avoid
5712 // loops when bringing in their DeclContext.
5713 if (auto ToPListOrErr =
5715 ToIface->setTypeParamList(*ToPListOrErr);
5716 else
5717 return ToPListOrErr.takeError();
5718
5720 if (Error Err = ImportDefinition(D, ToIface))
5721 return std::move(Err);
5722
5723 return ToIface;
5724}
5725
5728 ObjCCategoryDecl *Category;
5729 if (Error Err = importInto(Category, D->getCategoryDecl()))
5730 return std::move(Err);
5731
5732 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5733 if (!ToImpl) {
5734 DeclContext *DC, *LexicalDC;
5735 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5736 return std::move(Err);
5737
5738 Error Err = Error::success();
5739 auto ToLocation = importChecked(Err, D->getLocation());
5740 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5741 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5742 if (Err)
5743 return std::move(Err);
5744
5745 if (GetImportedOrCreateDecl(
5746 ToImpl, D, Importer.getToContext(), DC,
5747 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5748 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5749 return ToImpl;
5750
5751 ToImpl->setLexicalDeclContext(LexicalDC);
5752 LexicalDC->addDeclInternal(ToImpl);
5753 Category->setImplementation(ToImpl);
5754 }
5755
5756 Importer.MapImported(D, ToImpl);
5757 if (Error Err = ImportDeclContext(D))
5758 return std::move(Err);
5759
5760 return ToImpl;
5761}
5762
5765 // Find the corresponding interface.
5766 ObjCInterfaceDecl *Iface;
5767 if (Error Err = importInto(Iface, D->getClassInterface()))
5768 return std::move(Err);
5769
5770 // Import the superclass, if any.
5771 ObjCInterfaceDecl *Super;
5772 if (Error Err = importInto(Super, D->getSuperClass()))
5773 return std::move(Err);
5774
5776 if (!Impl) {
5777 // We haven't imported an implementation yet. Create a new @implementation
5778 // now.
5779 DeclContext *DC, *LexicalDC;
5780 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5781 return std::move(Err);
5782
5783 Error Err = Error::success();
5784 auto ToLocation = importChecked(Err, D->getLocation());
5785 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5786 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5787 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5788 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5789 if (Err)
5790 return std::move(Err);
5791
5792 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5793 DC, Iface, Super,
5794 ToLocation,
5795 ToAtStartLoc,
5796 ToSuperClassLoc,
5797 ToIvarLBraceLoc,
5798 ToIvarRBraceLoc))
5799 return Impl;
5800
5801 Impl->setLexicalDeclContext(LexicalDC);
5802
5803 // Associate the implementation with the class it implements.
5804 Iface->setImplementation(Impl);
5805 Importer.MapImported(D, Iface->getImplementation());
5806 } else {
5807 Importer.MapImported(D, Iface->getImplementation());
5808
5809 // Verify that the existing @implementation has the same superclass.
5810 if ((Super && !Impl->getSuperClass()) ||
5811 (!Super && Impl->getSuperClass()) ||
5812 (Super && Impl->getSuperClass() &&
5814 Impl->getSuperClass()))) {
5815 Importer.ToDiag(Impl->getLocation(),
5816 diag::warn_odr_objc_superclass_inconsistent)
5817 << Iface->getDeclName();
5818 // FIXME: It would be nice to have the location of the superclass
5819 // below.
5820 if (Impl->getSuperClass())
5821 Importer.ToDiag(Impl->getLocation(),
5822 diag::note_odr_objc_superclass)
5823 << Impl->getSuperClass()->getDeclName();
5824 else
5825 Importer.ToDiag(Impl->getLocation(),
5826 diag::note_odr_objc_missing_superclass);
5827 if (D->getSuperClass())
5828 Importer.FromDiag(D->getLocation(),
5829 diag::note_odr_objc_superclass)
5830 << D->getSuperClass()->getDeclName();
5831 else
5832 Importer.FromDiag(D->getLocation(),
5833 diag::note_odr_objc_missing_superclass);
5834
5835 return make_error<ASTImportError>(ASTImportError::NameConflict);
5836 }
5837 }
5838
5839 // Import all of the members of this @implementation.
5840 if (Error Err = ImportDeclContext(D))
5841 return std::move(Err);
5842
5843 return Impl;
5844}
5845
5847 // Import the major distinguishing characteristics of an @property.
5848 DeclContext *DC, *LexicalDC;
5849 DeclarationName Name;
5850 SourceLocation Loc;
5851 NamedDecl *ToD;
5852 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5853 return std::move(Err);
5854 if (ToD)
5855 return ToD;
5856
5857 // Check whether we have already imported this property.
5858 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5859 for (auto *FoundDecl : FoundDecls) {
5860 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5861 // Instance and class properties can share the same name but are different
5862 // declarations.
5863 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5864 continue;
5865
5866 // Check property types.
5867 if (!Importer.IsStructurallyEquivalent(D->getType(),
5868 FoundProp->getType())) {
5869 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5870 << Name << D->getType() << FoundProp->getType();
5871 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5872 << FoundProp->getType();
5873
5874 return make_error<ASTImportError>(ASTImportError::NameConflict);
5875 }
5876
5877 // FIXME: Check property attributes, getters, setters, etc.?
5878
5879 // Consider these properties to be equivalent.
5880 Importer.MapImported(D, FoundProp);
5881 return FoundProp;
5882 }
5883 }
5884
5885 Error Err = Error::success();
5886 auto ToType = importChecked(Err, D->getType());
5887 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5888 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5889 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5890 if (Err)
5891 return std::move(Err);
5892
5893 // Create the new property.
5894 ObjCPropertyDecl *ToProperty;
5895 if (GetImportedOrCreateDecl(
5896 ToProperty, D, Importer.getToContext(), DC, Loc,
5897 Name.getAsIdentifierInfo(), ToAtLoc,
5898 ToLParenLoc, ToType,
5899 ToTypeSourceInfo, D->getPropertyImplementation()))
5900 return ToProperty;
5901
5902 auto ToGetterName = importChecked(Err, D->getGetterName());
5903 auto ToSetterName = importChecked(Err, D->getSetterName());
5904 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5905 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5906 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5907 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5908 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5909 if (Err)
5910 return std::move(Err);
5911
5912 ToProperty->setLexicalDeclContext(LexicalDC);
5913 LexicalDC->addDeclInternal(ToProperty);
5914
5918 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5919 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5920 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5921 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5922 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5923 return ToProperty;
5924}
5925
5929 if (Error Err = importInto(Property, D->getPropertyDecl()))
5930 return std::move(Err);
5931
5932 DeclContext *DC, *LexicalDC;
5933 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5934 return std::move(Err);
5935
5936 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5937
5938 // Import the ivar (for an @synthesize).
5939 ObjCIvarDecl *Ivar = nullptr;
5940 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5941 return std::move(Err);
5942
5943 ObjCPropertyImplDecl *ToImpl
5944 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5945 Property->getQueryKind());
5946 if (!ToImpl) {
5947
5948 Error Err = Error::success();
5949 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5950 auto ToLocation = importChecked(Err, D->getLocation());
5951 auto ToPropertyIvarDeclLoc =
5953 if (Err)
5954 return std::move(Err);
5955
5956 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5957 ToBeginLoc,
5958 ToLocation, Property,
5959 D->getPropertyImplementation(), Ivar,
5960 ToPropertyIvarDeclLoc))
5961 return ToImpl;
5962
5963 ToImpl->setLexicalDeclContext(LexicalDC);
5964 LexicalDC->addDeclInternal(ToImpl);
5965 } else {
5966 // Check that we have the same kind of property implementation (@synthesize
5967 // vs. @dynamic).
5969 Importer.ToDiag(ToImpl->getLocation(),
5970 diag::warn_odr_objc_property_impl_kind_inconsistent)
5971 << Property->getDeclName()
5972 << (ToImpl->getPropertyImplementation()
5974 Importer.FromDiag(D->getLocation(),
5975 diag::note_odr_objc_property_impl_kind)
5976 << D->getPropertyDecl()->getDeclName()
5978
5979 return make_error<ASTImportError>(ASTImportError::NameConflict);
5980 }
5981
5982 // For @synthesize, check that we have the same
5984 Ivar != ToImpl->getPropertyIvarDecl()) {
5985 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5986 diag::warn_odr_objc_synthesize_ivar_inconsistent)
5987 << Property->getDeclName()
5988 << ToImpl->getPropertyIvarDecl()->getDeclName()
5989 << Ivar->getDeclName();
5990 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5991 diag::note_odr_objc_synthesize_ivar_here)
5993
5994 return make_error<ASTImportError>(ASTImportError::NameConflict);
5995 }
5996
5997 // Merge the existing implementation with the new implementation.
5998 Importer.MapImported(D, ToImpl);
5999 }
6000
6001 return ToImpl;
6002}
6003
6006 Error Err = Error::success();
6007 auto ToType = importChecked(Err, D->getType());
6008 auto ToValue = importChecked(Err, D->getValue());
6009 if (Err)
6010 return std::move(Err);
6011
6013 auto Create = [this](QualType T, const APValue &V) {
6014 return Importer.ToContext.getTemplateParamObjectDecl(T, V);
6015 };
6016 (void)GetImportedOrCreateSpecialDecl(ToD, Create, D, ToType, ToValue);
6017 return ToD;
6018}
6019
6022 // For template arguments, we adopt the translation unit as our declaration
6023 // context. This context will be fixed when (during) the actual template
6024 // declaration is created.
6025
6026 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6027 if (!BeginLocOrErr)
6028 return BeginLocOrErr.takeError();
6029
6030 ExpectedSLoc LocationOrErr = import(D->getLocation());
6031 if (!LocationOrErr)
6032 return LocationOrErr.takeError();
6033
6034 TemplateTypeParmDecl *ToD = nullptr;
6035 if (GetImportedOrCreateDecl(
6036 ToD, D, Importer.getToContext(),
6037 Importer.getToContext().getTranslationUnitDecl(),
6038 *BeginLocOrErr, *LocationOrErr,
6039 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6041 D->hasTypeConstraint()))
6042 return ToD;
6043
6044 // Import the type-constraint
6045 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6046
6047 Error Err = Error::success();
6048 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6049 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6050 if (Err)
6051 return std::move(Err);
6052
6053 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6054 }
6055
6056 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6057 return Err;
6058
6059 return ToD;
6060}
6061
6064
6065 Error Err = Error::success();
6066 auto ToDeclName = importChecked(Err, D->getDeclName());
6067 auto ToLocation = importChecked(Err, D->getLocation());
6068 auto ToType = importChecked(Err, D->getType());
6069 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6070 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6071 if (Err)
6072 return std::move(Err);
6073
6074 NonTypeTemplateParmDecl *ToD = nullptr;
6075 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6076 Importer.getToContext().getTranslationUnitDecl(),
6077 ToInnerLocStart, ToLocation, D->getDepth(),
6078 D->getPosition(),
6079 ToDeclName.getAsIdentifierInfo(), ToType,
6080 D->isParameterPack(), ToTypeSourceInfo))
6081 return ToD;
6082
6083 Err = importTemplateParameterDefaultArgument(D, ToD);
6084 if (Err)
6085 return Err;
6086
6087 return ToD;
6088}
6089
6092 bool IsCanonical = false;
6093 if (auto *CanonD = Importer.getFromContext()
6094 .findCanonicalTemplateTemplateParmDeclInternal(D);
6095 CanonD == D)
6096 IsCanonical = true;
6097
6098 // Import the name of this declaration.
6099 auto NameOrErr = import(D->getDeclName());
6100 if (!NameOrErr)
6101 return NameOrErr.takeError();
6102
6103 // Import the location of this declaration.
6104 ExpectedSLoc LocationOrErr = import(D->getLocation());
6105 if (!LocationOrErr)
6106 return LocationOrErr.takeError();
6107
6108 // Import template parameters.
6109 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6110 if (!TemplateParamsOrErr)
6111 return TemplateParamsOrErr.takeError();
6112
6113 TemplateTemplateParmDecl *ToD = nullptr;
6114 if (GetImportedOrCreateDecl(
6115 ToD, D, Importer.getToContext(),
6116 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6117 D->getDepth(), D->getPosition(), D->isParameterPack(),
6118 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6119 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6120 return ToD;
6121
6122 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6123 return Err;
6124
6125 if (IsCanonical)
6126 return Importer.getToContext()
6127 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6128
6129 return ToD;
6130}
6131
6132// Returns the definition for a (forward) declaration of a TemplateDecl, if
6133// it has any definition in the redecl chain.
6134template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6135 assert(D->getTemplatedDecl() && "Should be called on templates only");
6136 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6137 if (!ToTemplatedDef)
6138 return nullptr;
6139 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6140 return cast_or_null<T>(TemplateWithDef);
6141}
6142
6144
6145 // Import the major distinguishing characteristics of this class template.
6146 DeclContext *DC, *LexicalDC;
6147 DeclarationName Name;
6148 SourceLocation Loc;
6149 NamedDecl *ToD;
6150 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6151 return std::move(Err);
6152 if (ToD)
6153 return ToD;
6154
6155 // Should check if a declaration is friend in a dependent context.
6156 // Such templates are not linked together in a declaration chain.
6157 // The ASTImporter strategy is to map existing forward declarations to
6158 // imported ones only if strictly necessary, otherwise import these as new
6159 // forward declarations. In case of the "dependent friend" declarations, new
6160 // declarations are created, but not linked in a declaration chain.
6161 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6162 return TD->getFriendObjectKind() != Decl::FOK_None &&
6163 TD->getLexicalDeclContext()->isDependentContext();
6164 };
6165 bool DependentFriend = IsDependentFriend(D);
6166
6167 ClassTemplateDecl *FoundByLookup = nullptr;
6168
6169 // We may already have a template of the same name; try to find and match it.
6170 if (!DC->isFunctionOrMethod()) {
6171 SmallVector<NamedDecl *, 4> ConflictingDecls;
6172 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6173 for (auto *FoundDecl : FoundDecls) {
6174 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6176 continue;
6177
6178 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6179 if (FoundTemplate) {
6180 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6181 continue;
6182
6183 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6184 bool IgnoreTemplateParmDepth =
6185 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6187 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6188 IgnoreTemplateParmDepth)) {
6189 if (DependentFriend || IsDependentFriend(FoundTemplate))
6190 continue;
6191
6192 ClassTemplateDecl *TemplateWithDef =
6193 getTemplateDefinition(FoundTemplate);
6194 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6195 return Importer.MapImported(D, TemplateWithDef);
6196 if (!FoundByLookup)
6197 FoundByLookup = FoundTemplate;
6198 // Search in all matches because there may be multiple decl chains,
6199 // see ASTTests test ImportExistingFriendClassTemplateDef.
6200 continue;
6201 }
6202 // When importing a friend, it is possible that multiple declarations
6203 // with same name can co-exist in specific cases (if a template contains
6204 // a friend template and has a specialization). For this case the
6205 // declarations should match, except that the "template depth" is
6206 // different. No linking of previous declaration is needed in this case.
6207 // FIXME: This condition may need refinement.
6208 if (D->getFriendObjectKind() != Decl::FOK_None &&
6209 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6210 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6211 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6212 /*IgnoreTemplateParmDepth=*/true))
6213 continue;
6214
6215 ConflictingDecls.push_back(FoundDecl);
6216 }
6217 }
6218
6219 if (!ConflictingDecls.empty()) {
6220 ExpectedName NameOrErr = Importer.HandleNameConflict(
6221 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6222 ConflictingDecls.size());
6223 if (NameOrErr)
6224 Name = NameOrErr.get();
6225 else
6226 return NameOrErr.takeError();
6227 }
6228 }
6229
6230 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6231
6232 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6233 if (!TemplateParamsOrErr)
6234 return TemplateParamsOrErr.takeError();
6235
6236 // Create the declaration that is being templated.
6237 CXXRecordDecl *ToTemplated;
6238 if (Error Err = importInto(ToTemplated, FromTemplated))
6239 return std::move(Err);
6240
6241 // Create the class template declaration itself.
6243 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6244 *TemplateParamsOrErr, ToTemplated))
6245 return D2;
6246
6247 ToTemplated->setDescribedClassTemplate(D2);
6248
6249 D2->setAccess(D->getAccess());
6250 D2->setLexicalDeclContext(LexicalDC);
6251
6252 addDeclToContexts(D, D2);
6253 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6254
6255 if (FoundByLookup) {
6256 auto *Recent =
6257 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6258
6259 // It is possible that during the import of the class template definition
6260 // we start the import of a fwd friend decl of the very same class template
6261 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6262 // had been created earlier and by that time the lookup could not find
6263 // anything existing, so it has no previous decl. Later, (still during the
6264 // import of the fwd friend decl) we start to import the definition again
6265 // and this time the lookup finds the previous fwd friend class template.
6266 // In this case we must set up the previous decl for the templated decl.
6267 if (!ToTemplated->getPreviousDecl()) {
6268 assert(FoundByLookup->getTemplatedDecl() &&
6269 "Found decl must have its templated decl set");
6270 CXXRecordDecl *PrevTemplated =
6271 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6272 if (ToTemplated != PrevTemplated)
6273 ToTemplated->setPreviousDecl(PrevTemplated);
6274 }
6275
6276 D2->setPreviousDecl(Recent);
6277 }
6278
6279 return D2;
6280}
6281
6284 ClassTemplateDecl *ClassTemplate;
6285 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6286 return std::move(Err);
6287
6288 // Import the context of this declaration.
6289 DeclContext *DC, *LexicalDC;
6290 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6291 return std::move(Err);
6292
6293 // Import template arguments.
6295 if (Error Err =
6296 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6297 return std::move(Err);
6298 // Try to find an existing specialization with these template arguments and
6299 // template parameter list.
6300 void *InsertPos = nullptr;
6301 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6303 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6304
6305 // Import template parameters.
6306 TemplateParameterList *ToTPList = nullptr;
6307
6308 if (PartialSpec) {
6309 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6310 if (!ToTPListOrErr)
6311 return ToTPListOrErr.takeError();
6312 ToTPList = *ToTPListOrErr;
6313 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6314 *ToTPListOrErr,
6315 InsertPos);
6316 } else
6317 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6318
6319 if (PrevDecl) {
6320 if (IsStructuralMatch(D, PrevDecl)) {
6321 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6322 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6323 Importer.MapImported(D, PrevDefinition);
6324 // Import those default field initializers which have been
6325 // instantiated in the "From" context, but not in the "To" context.
6326 for (auto *FromField : D->fields()) {
6327 auto ToOrErr = import(FromField);
6328 if (!ToOrErr)
6329 return ToOrErr.takeError();
6330 }
6331
6332 // Import those methods which have been instantiated in the
6333 // "From" context, but not in the "To" context.
6334 for (CXXMethodDecl *FromM : D->methods()) {
6335 auto ToOrErr = import(FromM);
6336 if (!ToOrErr)
6337 return ToOrErr.takeError();
6338 }
6339
6340 // TODO Import instantiated default arguments.
6341 // TODO Import instantiated exception specifications.
6342 //
6343 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6344 // what else could be fused during an AST merge.
6345 return PrevDefinition;
6346 }
6347 } else { // ODR violation.
6348 // FIXME HandleNameConflict
6349 return make_error<ASTImportError>(ASTImportError::NameConflict);
6350 }
6351 }
6352
6353 // Import the location of this declaration.
6354 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6355 if (!BeginLocOrErr)
6356 return BeginLocOrErr.takeError();
6357 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6358 if (!IdLocOrErr)
6359 return IdLocOrErr.takeError();
6360
6361 // Import TemplateArgumentListInfo.
6362 TemplateArgumentListInfo ToTAInfo;
6363 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6364 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6365 return std::move(Err);
6366 }
6367
6368 // Create the specialization.
6369 ClassTemplateSpecializationDecl *D2 = nullptr;
6370 if (PartialSpec) {
6371 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6372 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6373 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6374 /*CanonInjectedTST=*/CanQualType(),
6375 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6376 return D2;
6377
6378 // Update InsertPos, because preceding import calls may have invalidated
6379 // it by adding new specializations.
6381 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6382 InsertPos))
6383 // Add this partial specialization to the class template.
6384 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6386 import(PartialSpec->getInstantiatedFromMember()))
6387 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6388 else
6389 return ToInstOrErr.takeError();
6390
6391 updateLookupTableForTemplateParameters(*ToTPList);
6392 } else { // Not a partial specialization.
6393 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6394 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6395 TemplateArgs, D->hasStrictPackMatch(),
6396 PrevDecl))
6397 return D2;
6398
6399 // Update InsertPos, because preceding import calls may have invalidated
6400 // it by adding new specializations.
6401 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6402 // Add this specialization to the class template.
6403 ClassTemplate->AddSpecialization(D2, InsertPos);
6404 }
6405
6407
6408 // Set the context of this specialization/instantiation.
6409 D2->setLexicalDeclContext(LexicalDC);
6410
6411 // Add to the DC only if it was an explicit specialization/instantiation.
6413 LexicalDC->addDeclInternal(D2);
6414 }
6415
6416 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6417 D2->setBraceRange(*BraceRangeOrErr);
6418 else
6419 return BraceRangeOrErr.takeError();
6420
6421 if (Error Err = ImportTemplateParameterLists(D, D2))
6422 return std::move(Err);
6423
6424 // Import the qualifier, if any.
6425 if (auto LocOrErr = import(D->getQualifierLoc()))
6426 D2->setQualifierInfo(*LocOrErr);
6427 else
6428 return LocOrErr.takeError();
6429
6430 if (D->getTemplateArgsAsWritten())
6431 D2->setTemplateArgsAsWritten(ToTAInfo);
6432
6433 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6434 D2->setTemplateKeywordLoc(*LocOrErr);
6435 else
6436 return LocOrErr.takeError();
6437
6438 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6439 D2->setExternKeywordLoc(*LocOrErr);
6440 else
6441 return LocOrErr.takeError();
6442
6443 if (D->getPointOfInstantiation().isValid()) {
6444 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6445 D2->setPointOfInstantiation(*POIOrErr);
6446 else
6447 return POIOrErr.takeError();
6448 }
6449
6451
6452 if (auto P = D->getInstantiatedFrom()) {
6453 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6454 if (auto CTDorErr = import(CTD))
6455 D2->setInstantiationOf(*CTDorErr);
6456 } else {
6458 auto CTPSDOrErr = import(CTPSD);
6459 if (!CTPSDOrErr)
6460 return CTPSDOrErr.takeError();
6462 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6463 for (unsigned I = 0; I < DArgs.size(); ++I) {
6464 const TemplateArgument &DArg = DArgs[I];
6465 if (auto ArgOrErr = import(DArg))
6466 D2ArgsVec[I] = *ArgOrErr;
6467 else
6468 return ArgOrErr.takeError();
6469 }
6471 *CTPSDOrErr,
6472 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6473 }
6474 }
6475
6476 if (D->isCompleteDefinition())
6477 if (Error Err = ImportDefinition(D, D2))
6478 return std::move(Err);
6479
6480 return D2;
6481}
6482
6484 // Import the major distinguishing characteristics of this variable template.
6485 DeclContext *DC, *LexicalDC;
6486 DeclarationName Name;
6487 SourceLocation Loc;
6488 NamedDecl *ToD;
6489 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6490 return std::move(Err);
6491 if (ToD)
6492 return ToD;
6493
6494 // We may already have a template of the same name; try to find and match it.
6495 assert(!DC->isFunctionOrMethod() &&
6496 "Variable templates cannot be declared at function scope");
6497
6498 SmallVector<NamedDecl *, 4> ConflictingDecls;
6499 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6500 VarTemplateDecl *FoundByLookup = nullptr;
6501 for (auto *FoundDecl : FoundDecls) {
6502 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6503 continue;
6504
6505 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6506 // Use the templated decl, some linkage flags are set only there.
6507 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6508 D->getTemplatedDecl()))
6509 continue;
6510 if (IsStructuralMatch(D, FoundTemplate)) {
6511 // FIXME Check for ODR error if the two definitions have
6512 // different initializers?
6513 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6514 if (D->getDeclContext()->isRecord()) {
6515 assert(FoundTemplate->getDeclContext()->isRecord() &&
6516 "Member variable template imported as non-member, "
6517 "inconsistent imported AST?");
6518 if (FoundDef)
6519 return Importer.MapImported(D, FoundDef);
6521 return Importer.MapImported(D, FoundTemplate);
6522 } else {
6523 if (FoundDef && D->isThisDeclarationADefinition())
6524 return Importer.MapImported(D, FoundDef);
6525 }
6526 FoundByLookup = FoundTemplate;
6527 break;
6528 }
6529 ConflictingDecls.push_back(FoundDecl);
6530 }
6531 }
6532
6533 if (!ConflictingDecls.empty()) {
6534 ExpectedName NameOrErr = Importer.HandleNameConflict(
6535 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6536 ConflictingDecls.size());
6537 if (NameOrErr)
6538 Name = NameOrErr.get();
6539 else
6540 return NameOrErr.takeError();
6541 }
6542
6543 VarDecl *DTemplated = D->getTemplatedDecl();
6544
6545 // Import the type.
6546 // FIXME: Value not used?
6547 ExpectedType TypeOrErr = import(DTemplated->getType());
6548 if (!TypeOrErr)
6549 return TypeOrErr.takeError();
6550
6551 // Create the declaration that is being templated.
6552 VarDecl *ToTemplated;
6553 if (Error Err = importInto(ToTemplated, DTemplated))
6554 return std::move(Err);
6555
6556 // Create the variable template declaration itself.
6557 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6558 if (!TemplateParamsOrErr)
6559 return TemplateParamsOrErr.takeError();
6560
6561 VarTemplateDecl *ToVarTD;
6562 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6563 Name, *TemplateParamsOrErr, ToTemplated))
6564 return ToVarTD;
6565
6566 ToTemplated->setDescribedVarTemplate(ToVarTD);
6567
6568 ToVarTD->setAccess(D->getAccess());
6569 ToVarTD->setLexicalDeclContext(LexicalDC);
6570 LexicalDC->addDeclInternal(ToVarTD);
6571 if (DC != Importer.getToContext().getTranslationUnitDecl())
6572 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6573
6574 if (FoundByLookup) {
6575 auto *Recent =
6576 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6577 if (!ToTemplated->getPreviousDecl()) {
6578 auto *PrevTemplated =
6579 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6580 if (ToTemplated != PrevTemplated)
6581 ToTemplated->setPreviousDecl(PrevTemplated);
6582 }
6583 ToVarTD->setPreviousDecl(Recent);
6584 }
6585
6586 return ToVarTD;
6587}
6588
6591 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6592 // in an analog way (but specialized for this case).
6593
6595 auto RedeclIt = Redecls.begin();
6596 // Import the first part of the decl chain. I.e. import all previous
6597 // declarations starting from the canonical decl.
6598 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6599 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6600 if (!RedeclOrErr)
6601 return RedeclOrErr.takeError();
6602 }
6603 assert(*RedeclIt == D);
6604
6605 VarTemplateDecl *VarTemplate = nullptr;
6607 return std::move(Err);
6608
6609 // Import the context of this declaration.
6610 DeclContext *DC, *LexicalDC;
6611 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6612 return std::move(Err);
6613
6614 // Import the location of this declaration.
6615 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6616 if (!BeginLocOrErr)
6617 return BeginLocOrErr.takeError();
6618
6619 auto IdLocOrErr = import(D->getLocation());
6620 if (!IdLocOrErr)
6621 return IdLocOrErr.takeError();
6622
6623 // Import template arguments.
6625 if (Error Err =
6626 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6627 return std::move(Err);
6628
6629 // Try to find an existing specialization with these template arguments.
6630 void *InsertPos = nullptr;
6631 VarTemplateSpecializationDecl *FoundSpecialization =
6632 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6633 if (FoundSpecialization) {
6634 if (IsStructuralMatch(D, FoundSpecialization)) {
6635 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6636 if (D->getDeclContext()->isRecord()) {
6637 // In a record, it is allowed only to have one optional declaration and
6638 // one definition of the (static or constexpr) variable template.
6639 assert(
6640 FoundSpecialization->getDeclContext()->isRecord() &&
6641 "Member variable template specialization imported as non-member, "
6642 "inconsistent imported AST?");
6643 if (FoundDef)
6644 return Importer.MapImported(D, FoundDef);
6646 return Importer.MapImported(D, FoundSpecialization);
6647 } else {
6648 // If definition is imported and there is already one, map to it.
6649 // Otherwise create a new variable and link it to the existing.
6650 if (FoundDef && D->isThisDeclarationADefinition())
6651 return Importer.MapImported(D, FoundDef);
6652 }
6653 } else {
6654 return make_error<ASTImportError>(ASTImportError::NameConflict);
6655 }
6656 }
6657
6658 VarTemplateSpecializationDecl *D2 = nullptr;
6659
6660 TemplateArgumentListInfo ToTAInfo;
6661 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6662 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6663 return std::move(Err);
6664 }
6665
6666 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6667 // Create a new specialization.
6668 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6669 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6670 if (!ToTPListOrErr)
6671 return ToTPListOrErr.takeError();
6672
6673 PartVarSpecDecl *ToPartial;
6674 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6675 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6676 VarTemplate, QualType(), nullptr,
6677 D->getStorageClass(), TemplateArgs))
6678 return ToPartial;
6679
6680 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6681 import(FromPartial->getInstantiatedFromMember()))
6682 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6683 else
6684 return ToInstOrErr.takeError();
6685
6686 if (FromPartial->isMemberSpecialization())
6687 ToPartial->setMemberSpecialization();
6688
6689 D2 = ToPartial;
6690
6691 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6692 // to adopt template parameters.
6693 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6694 } else { // Full specialization
6695 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6696 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6697 QualType(), nullptr, D->getStorageClass(),
6698 TemplateArgs))
6699 return D2;
6700 }
6701
6702 // Update InsertPos, because preceding import calls may have invalidated
6703 // it by adding new specializations.
6704 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6705 VarTemplate->AddSpecialization(D2, InsertPos);
6706
6707 QualType T;
6708 if (Error Err = importInto(T, D->getType()))
6709 return std::move(Err);
6710 D2->setType(T);
6711
6712 auto TInfoOrErr = import(D->getTypeSourceInfo());
6713 if (!TInfoOrErr)
6714 return TInfoOrErr.takeError();
6715 D2->setTypeSourceInfo(*TInfoOrErr);
6716
6717 if (D->getPointOfInstantiation().isValid()) {
6718 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6719 D2->setPointOfInstantiation(*POIOrErr);
6720 else
6721 return POIOrErr.takeError();
6722 }
6723
6725
6726 if (D->getTemplateArgsAsWritten())
6727 D2->setTemplateArgsAsWritten(ToTAInfo);
6728
6729 if (auto LocOrErr = import(D->getQualifierLoc()))
6730 D2->setQualifierInfo(*LocOrErr);
6731 else
6732 return LocOrErr.takeError();
6733
6734 if (D->isConstexpr())
6735 D2->setConstexpr(true);
6736
6737 D2->setAccess(D->getAccess());
6738
6739 if (Error Err = ImportInitializer(D, D2))
6740 return std::move(Err);
6741
6742 if (FoundSpecialization)
6743 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6744
6745 addDeclToContexts(D, D2);
6746
6747 // Import the rest of the chain. I.e. import all subsequent declarations.
6748 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6749 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6750 if (!RedeclOrErr)
6751 return RedeclOrErr.takeError();
6752 }
6753
6754 return D2;
6755}
6756
6759 DeclContext *DC, *LexicalDC;
6760 DeclarationName Name;
6761 SourceLocation Loc;
6762 NamedDecl *ToD;
6763
6764 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6765 return std::move(Err);
6766
6767 if (ToD)
6768 return ToD;
6769
6770 const FunctionTemplateDecl *FoundByLookup = nullptr;
6771
6772 // Try to find a function in our own ("to") context with the same name, same
6773 // type, and in the same context as the function we're importing.
6774 // FIXME Split this into a separate function.
6775 if (!LexicalDC->isFunctionOrMethod()) {
6777 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6778 for (auto *FoundDecl : FoundDecls) {
6779 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6780 continue;
6781
6782 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6783 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6784 continue;
6785 if (IsStructuralMatch(D, FoundTemplate)) {
6786 FunctionTemplateDecl *TemplateWithDef =
6787 getTemplateDefinition(FoundTemplate);
6788 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6789 return Importer.MapImported(D, TemplateWithDef);
6790
6791 FoundByLookup = FoundTemplate;
6792 break;
6793 // TODO: handle conflicting names
6794 }
6795 }
6796 }
6797 }
6798
6799 auto ParamsOrErr = import(D->getTemplateParameters());
6800 if (!ParamsOrErr)
6801 return ParamsOrErr.takeError();
6802 TemplateParameterList *Params = *ParamsOrErr;
6803
6804 FunctionDecl *TemplatedFD;
6805 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6806 return std::move(Err);
6807
6808 // At creation of the template the template parameters are "adopted"
6809 // (DeclContext is changed). After this possible change the lookup table
6810 // must be updated.
6811 // At deduction guides the DeclContext of the template parameters may be
6812 // different from what we would expect, it may be the class template, or a
6813 // probably different CXXDeductionGuideDecl. This may come from the fact that
6814 // the template parameter objects may be shared between deduction guides or
6815 // the class template, and at creation of multiple FunctionTemplateDecl
6816 // objects (for deduction guides) the same parameters are re-used. The
6817 // "adoption" happens multiple times with different parent, even recursively
6818 // for TemplateTemplateParmDecl. The same happens at import when the
6819 // FunctionTemplateDecl objects are created, but in different order.
6820 // In this way the DeclContext of these template parameters is not necessarily
6821 // the same as in the "from" context.
6823 OldParamDC.reserve(Params->size());
6824 llvm::transform(*Params, std::back_inserter(OldParamDC),
6825 [](NamedDecl *ND) { return ND->getDeclContext(); });
6826
6827 FunctionTemplateDecl *ToFunc;
6828 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6829 Params, TemplatedFD))
6830 return ToFunc;
6831
6832 // Fail if TemplatedFD is already part of a template.
6833 // The template should have been found by structural equivalence check before,
6834 // or ToFunc should be already imported.
6835 // If not, there is AST incompatibility that can be caused by previous import
6836 // errors. (NameConflict is not exact here.)
6837 if (TemplatedFD->getDescribedTemplate())
6838 return make_error<ASTImportError>(ASTImportError::NameConflict);
6839
6840 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6841
6842 ToFunc->setAccess(D->getAccess());
6843 ToFunc->setLexicalDeclContext(LexicalDC);
6844 addDeclToContexts(D, ToFunc);
6845
6846 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6847 if (LT && !OldParamDC.empty()) {
6848 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6849 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6850 }
6851
6852 if (FoundByLookup) {
6853 auto *Recent =
6854 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6855 if (!TemplatedFD->getPreviousDecl()) {
6856 assert(FoundByLookup->getTemplatedDecl() &&
6857 "Found decl must have its templated decl set");
6858 auto *PrevTemplated =
6859 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6860 if (TemplatedFD != PrevTemplated)
6861 TemplatedFD->setPreviousDecl(PrevTemplated);
6862 }
6863 ToFunc->setPreviousDecl(Recent);
6864 }
6865
6866 return ToFunc;
6867}
6868
6870 DeclContext *DC, *LexicalDC;
6871 Error Err = ImportDeclContext(D, DC, LexicalDC);
6872 auto LocationOrErr = importChecked(Err, D->getLocation());
6873 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6874 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6875 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6876 if (Err)
6877 return std::move(Err);
6878
6879 ConceptDecl *To;
6880 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6881 NameDeclOrErr, ToTemplateParameters,
6882 ConstraintExpr))
6883 return To;
6884 To->setLexicalDeclContext(LexicalDC);
6885 LexicalDC->addDeclInternal(To);
6886 return To;
6887}
6888
6891 DeclContext *DC, *LexicalDC;
6892 Error Err = ImportDeclContext(D, DC, LexicalDC);
6893 auto RequiresLoc = importChecked(Err, D->getLocation());
6894 if (Err)
6895 return std::move(Err);
6896
6898 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
6899 return To;
6900 To->setLexicalDeclContext(LexicalDC);
6901 LexicalDC->addDeclInternal(To);
6902 return To;
6903}
6904
6907 DeclContext *DC, *LexicalDC;
6908 Error Err = ImportDeclContext(D, DC, LexicalDC);
6909 auto ToSL = importChecked(Err, D->getLocation());
6910 if (Err)
6911 return std::move(Err);
6912
6914 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
6915 return std::move(Err);
6916
6918 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
6919 return To;
6920 To->setLexicalDeclContext(LexicalDC);
6921 LexicalDC->addDeclInternal(To);
6922 return To;
6923}
6924
6925//----------------------------------------------------------------------------
6926// Import Statements
6927//----------------------------------------------------------------------------
6928
6930 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
6931 << S->getStmtClassName();
6932 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6933}
6934
6935
6937 if (Importer.returnWithErrorInTest())
6938 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6940 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6941 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
6942 // ToII is nullptr when no symbolic name is given for output operand
6943 // see ParseStmtAsm::ParseAsmOperandsOpt
6944 Names.push_back(ToII);
6945 }
6946
6947 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6948 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
6949 // ToII is nullptr when no symbolic name is given for input operand
6950 // see ParseStmtAsm::ParseAsmOperandsOpt
6951 Names.push_back(ToII);
6952 }
6953
6954 SmallVector<Expr *, 4> Clobbers;
6955 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
6956 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
6957 Clobbers.push_back(*ClobberOrErr);
6958 else
6959 return ClobberOrErr.takeError();
6960
6961 }
6962
6963 SmallVector<Expr *, 4> Constraints;
6964 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6965 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
6966 Constraints.push_back(*OutputOrErr);
6967 else
6968 return OutputOrErr.takeError();
6969 }
6970
6971 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6972 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
6973 Constraints.push_back(*InputOrErr);
6974 else
6975 return InputOrErr.takeError();
6976 }
6977
6979 S->getNumLabels());
6980 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
6981 return std::move(Err);
6982
6983 if (Error Err =
6984 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
6985 return std::move(Err);
6986
6987 if (Error Err = ImportArrayChecked(
6988 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
6989 return std::move(Err);
6990
6991 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
6992 if (!AsmLocOrErr)
6993 return AsmLocOrErr.takeError();
6994 auto AsmStrOrErr = import(S->getAsmStringExpr());
6995 if (!AsmStrOrErr)
6996 return AsmStrOrErr.takeError();
6997 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
6998 if (!RParenLocOrErr)
6999 return RParenLocOrErr.takeError();
7000
7001 return new (Importer.getToContext()) GCCAsmStmt(
7002 Importer.getToContext(),
7003 *AsmLocOrErr,
7004 S->isSimple(),
7005 S->isVolatile(),
7006 S->getNumOutputs(),
7007 S->getNumInputs(),
7008 Names.data(),
7009 Constraints.data(),
7010 Exprs.data(),
7011 *AsmStrOrErr,
7012 S->getNumClobbers(),
7013 Clobbers.data(),
7014 S->getNumLabels(),
7015 *RParenLocOrErr);
7016}
7017
7019
7020 Error Err = Error::success();
7021 auto ToDG = importChecked(Err, S->getDeclGroup());
7022 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7023 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7024 if (Err)
7025 return std::move(Err);
7026 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7027}
7028
7030 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7031 if (!ToSemiLocOrErr)
7032 return ToSemiLocOrErr.takeError();
7033 return new (Importer.getToContext()) NullStmt(
7034 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7035}
7036
7038 SmallVector<Stmt *, 8> ToStmts(S->size());
7039
7040 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7041 return std::move(Err);
7042
7043 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7044 if (!ToLBracLocOrErr)
7045 return ToLBracLocOrErr.takeError();
7046
7047 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7048 if (!ToRBracLocOrErr)
7049 return ToRBracLocOrErr.takeError();
7050
7051 FPOptionsOverride FPO =
7053 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7054 *ToLBracLocOrErr, *ToRBracLocOrErr);
7055}
7056
7058
7059 Error Err = Error::success();
7060 auto ToLHS = importChecked(Err, S->getLHS());
7061 auto ToRHS = importChecked(Err, S->getRHS());
7062 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7063 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7064 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7065 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7066 if (Err)
7067 return std::move(Err);
7068
7069 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7070 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7071 ToStmt->setSubStmt(ToSubStmt);
7072
7073 return ToStmt;
7074}
7075
7077
7078 Error Err = Error::success();
7079 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7080 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7081 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7082 if (Err)
7083 return std::move(Err);
7084
7085 return new (Importer.getToContext()) DefaultStmt(
7086 ToDefaultLoc, ToColonLoc, ToSubStmt);
7087}
7088
7090
7091 Error Err = Error::success();
7092 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7093 auto ToLabelDecl = importChecked(Err, S->getDecl());
7094 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7095 if (Err)
7096 return std::move(Err);
7097
7098 return new (Importer.getToContext()) LabelStmt(
7099 ToIdentLoc, ToLabelDecl, ToSubStmt);
7100}
7101
7103 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7104 if (!ToAttrLocOrErr)
7105 return ToAttrLocOrErr.takeError();
7106 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7107 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7108 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7109 return std::move(Err);
7110 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7111 if (!ToSubStmtOrErr)
7112 return ToSubStmtOrErr.takeError();
7113
7115 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7116}
7117
7119
7120 Error Err = Error::success();
7121 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7122 auto ToInit = importChecked(Err, S->getInit());
7123 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7124 auto ToCond = importChecked(Err, S->getCond());
7125 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7126 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7127 auto ToThen = importChecked(Err, S->getThen());
7128 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7129 auto ToElse = importChecked(Err, S->getElse());
7130 if (Err)
7131 return std::move(Err);
7132
7133 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7134 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7135 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7136}
7137
7139
7140 Error Err = Error::success();
7141 auto ToInit = importChecked(Err, S->getInit());
7142 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7143 auto ToCond = importChecked(Err, S->getCond());
7144 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7145 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7146 auto ToBody = importChecked(Err, S->getBody());
7147 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7148 if (Err)
7149 return std::move(Err);
7150
7151 auto *ToStmt =
7152 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7153 ToCond, ToLParenLoc, ToRParenLoc);
7154 ToStmt->setBody(ToBody);
7155 ToStmt->setSwitchLoc(ToSwitchLoc);
7156
7157 // Now we have to re-chain the cases.
7158 SwitchCase *LastChainedSwitchCase = nullptr;
7159 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7160 SC = SC->getNextSwitchCase()) {
7161 Expected<SwitchCase *> ToSCOrErr = import(SC);
7162 if (!ToSCOrErr)
7163 return ToSCOrErr.takeError();
7164 if (LastChainedSwitchCase)
7165 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7166 else
7167 ToStmt->setSwitchCaseList(*ToSCOrErr);
7168 LastChainedSwitchCase = *ToSCOrErr;
7169 }
7170
7171 return ToStmt;
7172}
7173
7175
7176 Error Err = Error::success();
7177 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7178 auto ToCond = importChecked(Err, S->getCond());
7179 auto ToBody = importChecked(Err, S->getBody());
7180 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7181 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7182 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7183 if (Err)
7184 return std::move(Err);
7185
7186 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7187 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7188}
7189
7191
7192 Error Err = Error::success();
7193 auto ToBody = importChecked(Err, S->getBody());
7194 auto ToCond = importChecked(Err, S->getCond());
7195 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7196 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7197 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7198 if (Err)
7199 return std::move(Err);
7200
7201 return new (Importer.getToContext()) DoStmt(
7202 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7203}
7204
7206
7207 Error Err = Error::success();
7208 auto ToInit = importChecked(Err, S->getInit());
7209 auto ToCond = importChecked(Err, S->getCond());
7210 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7211 auto ToInc = importChecked(Err, S->getInc());
7212 auto ToBody = importChecked(Err, S->getBody());
7213 auto ToForLoc = importChecked(Err, S->getForLoc());
7214 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7215 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7216 if (Err)
7217 return std::move(Err);
7218
7219 return new (Importer.getToContext()) ForStmt(
7220 Importer.getToContext(),
7221 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7222 ToRParenLoc);
7223}
7224
7226
7227 Error Err = Error::success();
7228 auto ToLabel = importChecked(Err, S->getLabel());
7229 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7230 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7231 if (Err)
7232 return std::move(Err);
7233
7234 return new (Importer.getToContext()) GotoStmt(
7235 ToLabel, ToGotoLoc, ToLabelLoc);
7236}
7237
7239
7240 Error Err = Error::success();
7241 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7242 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7243 auto ToTarget = importChecked(Err, S->getTarget());
7244 if (Err)
7245 return std::move(Err);
7246
7247 return new (Importer.getToContext()) IndirectGotoStmt(
7248 ToGotoLoc, ToStarLoc, ToTarget);
7249}
7250
7251template <typename StmtClass>
7253 ASTImporter &Importer, StmtClass *S) {
7254 Error Err = Error::success();
7255 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7256 auto ToLabelLoc = S->hasLabelTarget()
7257 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7258 : SourceLocation();
7259 auto ToDecl = S->hasLabelTarget()
7260 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7261 : nullptr;
7262 if (Err)
7263 return std::move(Err);
7264 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7265}
7266
7270
7274
7276
7277 Error Err = Error::success();
7278 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7279 auto ToRetValue = importChecked(Err, S->getRetValue());
7280 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7281 if (Err)
7282 return std::move(Err);
7283
7284 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7285 ToNRVOCandidate);
7286}
7287
7289
7290 Error Err = Error::success();
7291 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7292 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7293 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7294 if (Err)
7295 return std::move(Err);
7296
7297 return new (Importer.getToContext()) CXXCatchStmt (
7298 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7299}
7300
7302 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7303 if (!ToTryLocOrErr)
7304 return ToTryLocOrErr.takeError();
7305
7306 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7307 if (!ToTryBlockOrErr)
7308 return ToTryBlockOrErr.takeError();
7309
7310 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7311 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7312 CXXCatchStmt *FromHandler = S->getHandler(HI);
7313 if (auto ToHandlerOrErr = import(FromHandler))
7314 ToHandlers[HI] = *ToHandlerOrErr;
7315 else
7316 return ToHandlerOrErr.takeError();
7317 }
7318
7319 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7320 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7321}
7322
7324
7325 Error Err = Error::success();
7326 auto ToInit = importChecked(Err, S->getInit());
7327 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7328 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7329 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7330 auto ToCond = importChecked(Err, S->getCond());
7331 auto ToInc = importChecked(Err, S->getInc());
7332 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7333 auto ToBody = importChecked(Err, S->getBody());
7334 auto ToForLoc = importChecked(Err, S->getForLoc());
7335 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7336 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7337 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7338 if (Err)
7339 return std::move(Err);
7340
7341 return new (Importer.getToContext()) CXXForRangeStmt(
7342 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7343 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7344}
7345
7348 Error Err = Error::success();
7349 auto ToESD = importChecked(Err, S->getDecl());
7350 auto ToInit = importChecked(Err, S->getInit());
7351 auto ToExpansionVar = importChecked(Err, S->getExpansionVarStmt());
7352 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7353 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7354 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7355 if (Err)
7356 return std::move(Err);
7357
7358 switch (S->getKind()) {
7361 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToLParenLoc,
7362 ToColonLoc, ToRParenLoc);
7363
7365 auto ToRange = importChecked(Err, S->getRangeVarStmt());
7366 auto ToBegin = importChecked(Err, S->getBeginVarStmt());
7367 auto ToIter = importChecked(Err, S->getIterVarStmt());
7368 if (Err)
7369 return std::move(Err);
7370
7372 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToRange,
7373 ToBegin, ToIter, ToLParenLoc, ToColonLoc, ToRParenLoc);
7374 }
7375
7377 auto ToDecompositionDeclStmt =
7379 if (Err)
7380 return std::move(Err);
7381
7383 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7384 ToDecompositionDeclStmt, ToLParenLoc, ToColonLoc, ToRParenLoc);
7385 }
7386
7388 auto ToExpansionInitializer =
7390 if (Err)
7391 return std::move(Err);
7393 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7394 ToExpansionInitializer, ToLParenLoc, ToColonLoc, ToRParenLoc);
7395 }
7396 }
7397
7398 llvm_unreachable("invalid pattern kind");
7399}
7400
7403 Error Err = Error::success();
7404 SmallVector<Stmt *> ToInstantiations;
7405 SmallVector<Stmt *> ToSharedStmts;
7406 auto ToParent = importChecked(Err, S->getParent());
7407 for (Stmt *FromInst : S->getInstantiations())
7408 ToInstantiations.push_back(importChecked(Err, FromInst));
7409 for (Stmt *FromShared : S->getPreambleStmts())
7410 ToSharedStmts.push_back(importChecked(Err, FromShared));
7411
7412 if (Err)
7413 return std::move(Err);
7414
7416 Importer.getToContext(), ToParent, ToInstantiations, ToSharedStmts,
7418}
7419
7422 Error Err = Error::success();
7423 auto ToElement = importChecked(Err, S->getElement());
7424 auto ToCollection = importChecked(Err, S->getCollection());
7425 auto ToBody = importChecked(Err, S->getBody());
7426 auto ToForLoc = importChecked(Err, S->getForLoc());
7427 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7428 if (Err)
7429 return std::move(Err);
7430
7431 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7432 ToCollection,
7433 ToBody,
7434 ToForLoc,
7435 ToRParenLoc);
7436}
7437
7439
7440 Error Err = Error::success();
7441 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7442 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7443 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7444 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7445 if (Err)
7446 return std::move(Err);
7447
7448 return new (Importer.getToContext()) ObjCAtCatchStmt (
7449 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7450}
7451
7453 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7454 if (!ToAtFinallyLocOrErr)
7455 return ToAtFinallyLocOrErr.takeError();
7456 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7457 if (!ToAtFinallyStmtOrErr)
7458 return ToAtFinallyStmtOrErr.takeError();
7459 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7460 *ToAtFinallyStmtOrErr);
7461}
7462
7464
7465 Error Err = Error::success();
7466 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7467 auto ToTryBody = importChecked(Err, S->getTryBody());
7468 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7469 if (Err)
7470 return std::move(Err);
7471
7472 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7473 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7474 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7475 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7476 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7477 else
7478 return ToCatchStmtOrErr.takeError();
7479 }
7480
7481 return ObjCAtTryStmt::Create(Importer.getToContext(),
7482 ToAtTryLoc, ToTryBody,
7483 ToCatchStmts.begin(), ToCatchStmts.size(),
7484 ToFinallyStmt);
7485}
7486
7489
7490 Error Err = Error::success();
7491 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7492 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7493 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7494 if (Err)
7495 return std::move(Err);
7496
7497 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7498 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7499}
7500
7502 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7503 if (!ToThrowLocOrErr)
7504 return ToThrowLocOrErr.takeError();
7505 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7506 if (!ToThrowExprOrErr)
7507 return ToThrowExprOrErr.takeError();
7508 return new (Importer.getToContext()) ObjCAtThrowStmt(
7509 *ToThrowLocOrErr, *ToThrowExprOrErr);
7510}
7511
7514 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7515 if (!ToAtLocOrErr)
7516 return ToAtLocOrErr.takeError();
7517 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7518 if (!ToSubStmtOrErr)
7519 return ToSubStmtOrErr.takeError();
7520 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7521 *ToSubStmtOrErr);
7522}
7523
7524//----------------------------------------------------------------------------
7525// Import Expressions
7526//----------------------------------------------------------------------------
7528 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7529 << E->getStmtClassName();
7530 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7531}
7532
7534 Error Err = Error::success();
7535 auto ToType = importChecked(Err, E->getType());
7536 auto BLoc = importChecked(Err, E->getBeginLoc());
7537 auto RParenLoc = importChecked(Err, E->getEndLoc());
7538 if (Err)
7539 return std::move(Err);
7540 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7541 if (!ParentContextOrErr)
7542 return ParentContextOrErr.takeError();
7543
7544 return new (Importer.getToContext())
7545 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7546 RParenLoc, *ParentContextOrErr);
7547}
7548
7550
7551 Error Err = Error::success();
7552 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7553 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7554 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7555 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7556 auto ToType = importChecked(Err, E->getType());
7557 if (Err)
7558 return std::move(Err);
7559
7560 return new (Importer.getToContext())
7561 VAArgExpr(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7562 E->getVarargABI());
7563}
7564
7566
7567 Error Err = Error::success();
7568 auto ToCond = importChecked(Err, E->getCond());
7569 auto ToLHS = importChecked(Err, E->getLHS());
7570 auto ToRHS = importChecked(Err, E->getRHS());
7571 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7572 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7573 auto ToType = importChecked(Err, E->getType());
7574 if (Err)
7575 return std::move(Err);
7576
7578 ExprObjectKind OK = E->getObjectKind();
7579
7580 // The value of CondIsTrue only matters if the value is not
7581 // condition-dependent.
7582 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7583
7584 return new (Importer.getToContext())
7585 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7586 ToRParenLoc, CondIsTrue);
7587}
7588
7590 Error Err = Error::success();
7591 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7592 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7593 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7594 auto ToType = importChecked(Err, E->getType());
7595 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7596 if (Err)
7597 return std::move(Err);
7598
7600 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7601 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7603}
7604
7606 Error Err = Error::success();
7607 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7608 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7609 auto ToType = importChecked(Err, E->getType());
7610 const unsigned NumSubExprs = E->getNumSubExprs();
7611
7613 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7614 ToSubExprs.resize(NumSubExprs);
7615
7616 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7617 return std::move(Err);
7618
7619 return new (Importer.getToContext()) ShuffleVectorExpr(
7620 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7621}
7622
7624 ExpectedType TypeOrErr = import(E->getType());
7625 if (!TypeOrErr)
7626 return TypeOrErr.takeError();
7627
7628 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7629 if (!BeginLocOrErr)
7630 return BeginLocOrErr.takeError();
7631
7632 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7633}
7634
7637 Error Err = Error::success();
7638 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7639 Expr *ToControllingExpr = nullptr;
7640 TypeSourceInfo *ToControllingType = nullptr;
7641 if (E->isExprPredicate())
7642 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7643 else
7644 ToControllingType = importChecked(Err, E->getControllingType());
7645 assert((ToControllingExpr || ToControllingType) &&
7646 "Either the controlling expr or type must be nonnull");
7647 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7648 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7649 if (Err)
7650 return std::move(Err);
7651
7653 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7654 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7655 return std::move(Err);
7656
7657 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7658 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7659 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7660 return std::move(Err);
7661
7662 const ASTContext &ToCtx = Importer.getToContext();
7663 if (E->isResultDependent()) {
7664 if (ToControllingExpr) {
7666 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7667 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7669 }
7671 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7672 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7674 }
7675
7676 if (ToControllingExpr) {
7678 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7679 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7681 }
7683 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7684 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7686}
7687
7689
7690 Error Err = Error::success();
7691 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7692 auto ToType = importChecked(Err, E->getType());
7693 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7694 if (Err)
7695 return std::move(Err);
7696
7697 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7698 E->getIdentKind(), E->isTransparent(),
7699 ToFunctionName);
7700}
7701
7703
7704 Error Err = Error::success();
7705 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7706 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7707 auto ToDecl = importChecked(Err, E->getDecl());
7708 auto ToLocation = importChecked(Err, E->getLocation());
7709 auto ToType = importChecked(Err, E->getType());
7710 if (Err)
7711 return std::move(Err);
7712
7713 NamedDecl *ToFoundD = nullptr;
7714 if (E->getDecl() != E->getFoundDecl()) {
7715 auto FoundDOrErr = import(E->getFoundDecl());
7716 if (!FoundDOrErr)
7717 return FoundDOrErr.takeError();
7718 ToFoundD = *FoundDOrErr;
7719 }
7720
7721 TemplateArgumentListInfo ToTAInfo;
7722 TemplateArgumentListInfo *ToResInfo = nullptr;
7723 if (E->hasExplicitTemplateArgs()) {
7724 if (Error Err =
7726 E->template_arguments(), ToTAInfo))
7727 return std::move(Err);
7728 ToResInfo = &ToTAInfo;
7729 }
7730
7731 auto *ToE = DeclRefExpr::Create(
7732 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7733 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7734 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7735 if (E->hadMultipleCandidates())
7736 ToE->setHadMultipleCandidates(true);
7737 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7738 return ToE;
7739}
7740
7742 ExpectedType TypeOrErr = import(E->getType());
7743 if (!TypeOrErr)
7744 return TypeOrErr.takeError();
7745
7746 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7747}
7748
7750 ExpectedExpr ToInitOrErr = import(E->getInit());
7751 if (!ToInitOrErr)
7752 return ToInitOrErr.takeError();
7753
7754 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7755 if (!ToEqualOrColonLocOrErr)
7756 return ToEqualOrColonLocOrErr.takeError();
7757
7758 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7759 // List elements from the second, the first is Init itself
7760 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7761 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7762 ToIndexExprs[I - 1] = *ToArgOrErr;
7763 else
7764 return ToArgOrErr.takeError();
7765 }
7766
7767 SmallVector<Designator, 4> ToDesignators(E->size());
7768 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7769 return std::move(Err);
7770
7772 Importer.getToContext(), ToDesignators,
7773 ToIndexExprs, *ToEqualOrColonLocOrErr,
7774 E->usesGNUSyntax(), *ToInitOrErr);
7775}
7776
7779 ExpectedType ToTypeOrErr = import(E->getType());
7780 if (!ToTypeOrErr)
7781 return ToTypeOrErr.takeError();
7782
7783 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7784 if (!ToLocationOrErr)
7785 return ToLocationOrErr.takeError();
7786
7787 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7788 *ToTypeOrErr, *ToLocationOrErr);
7789}
7790
7792 ExpectedType ToTypeOrErr = import(E->getType());
7793 if (!ToTypeOrErr)
7794 return ToTypeOrErr.takeError();
7795
7796 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7797 if (!ToLocationOrErr)
7798 return ToLocationOrErr.takeError();
7799
7801 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7802}
7803
7804
7806 ExpectedType ToTypeOrErr = import(E->getType());
7807 if (!ToTypeOrErr)
7808 return ToTypeOrErr.takeError();
7809
7810 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7811 if (!ToLocationOrErr)
7812 return ToLocationOrErr.takeError();
7813
7815 Importer.getToContext(), E->getValue(), E->isExact(),
7816 *ToTypeOrErr, *ToLocationOrErr);
7817}
7818
7820 auto ToTypeOrErr = import(E->getType());
7821 if (!ToTypeOrErr)
7822 return ToTypeOrErr.takeError();
7823
7824 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7825 if (!ToSubExprOrErr)
7826 return ToSubExprOrErr.takeError();
7827
7828 return new (Importer.getToContext()) ImaginaryLiteral(
7829 *ToSubExprOrErr, *ToTypeOrErr);
7830}
7831
7833 auto ToTypeOrErr = import(E->getType());
7834 if (!ToTypeOrErr)
7835 return ToTypeOrErr.takeError();
7836
7837 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7838 if (!ToLocationOrErr)
7839 return ToLocationOrErr.takeError();
7840
7841 return new (Importer.getToContext()) FixedPointLiteral(
7842 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7843 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7844}
7845
7847 ExpectedType ToTypeOrErr = import(E->getType());
7848 if (!ToTypeOrErr)
7849 return ToTypeOrErr.takeError();
7850
7851 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7852 if (!ToLocationOrErr)
7853 return ToLocationOrErr.takeError();
7854
7855 return new (Importer.getToContext()) CharacterLiteral(
7856 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7857}
7858
7860 ExpectedType ToTypeOrErr = import(E->getType());
7861 if (!ToTypeOrErr)
7862 return ToTypeOrErr.takeError();
7863
7865 if (Error Err = ImportArrayChecked(
7866 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7867 return std::move(Err);
7868
7869 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7870 E->getKind(), E->isPascal(), *ToTypeOrErr,
7871 ToLocations);
7872}
7873
7875
7876 Error Err = Error::success();
7877 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7878 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7879 auto ToType = importChecked(Err, E->getType());
7880 auto ToInitializer = importChecked(Err, E->getInitializer());
7881 if (Err)
7882 return std::move(Err);
7883
7884 return new (Importer.getToContext()) CompoundLiteralExpr(
7885 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7886 ToInitializer, E->isFileScope());
7887}
7888
7890
7891 Error Err = Error::success();
7892 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7893 auto ToType = importChecked(Err, E->getType());
7894 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7895 if (Err)
7896 return std::move(Err);
7897
7899 if (Error Err = ImportArrayChecked(
7900 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7901 ToExprs.begin()))
7902 return std::move(Err);
7903
7904 return new (Importer.getToContext()) AtomicExpr(
7905
7906 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7907}
7908
7910 Error Err = Error::success();
7911 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7912 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7913 auto ToLabel = importChecked(Err, E->getLabel());
7914 auto ToType = importChecked(Err, E->getType());
7915 if (Err)
7916 return std::move(Err);
7917
7918 return new (Importer.getToContext()) AddrLabelExpr(
7919 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7920}
7922 Error Err = Error::success();
7923 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7924 auto ToResult = importChecked(Err, E->getAPValueResult());
7925 if (Err)
7926 return std::move(Err);
7927
7928 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7929}
7931 Error Err = Error::success();
7932 auto ToLParen = importChecked(Err, E->getLParen());
7933 auto ToRParen = importChecked(Err, E->getRParen());
7934 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7935 if (Err)
7936 return std::move(Err);
7937
7938 return new (Importer.getToContext())
7939 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7940}
7941
7943 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7944 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7945 return std::move(Err);
7946
7947 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7948 if (!ToLParenLocOrErr)
7949 return ToLParenLocOrErr.takeError();
7950
7951 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7952 if (!ToRParenLocOrErr)
7953 return ToRParenLocOrErr.takeError();
7954
7955 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7956 ToExprs, *ToRParenLocOrErr);
7957}
7958
7960 Error Err = Error::success();
7961 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7962 auto ToType = importChecked(Err, E->getType());
7963 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7964 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7965 if (Err)
7966 return std::move(Err);
7967
7968 return new (Importer.getToContext())
7969 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7970 E->getTemplateDepth());
7971}
7972
7974 Error Err = Error::success();
7975 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7976 auto ToType = importChecked(Err, E->getType());
7977 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7978 if (Err)
7979 return std::move(Err);
7980
7981 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7982 E->hasStoredFPFeatures());
7983 UO->setType(ToType);
7984 UO->setSubExpr(ToSubExpr);
7985 UO->setOpcode(E->getOpcode());
7986 UO->setOperatorLoc(ToOperatorLoc);
7987 UO->setCanOverflow(E->canOverflow());
7988 if (E->hasStoredFPFeatures())
7989 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7990
7991 return UO;
7992}
7993
7995
7997 Error Err = Error::success();
7998 auto ToType = importChecked(Err, E->getType());
7999 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8000 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8001 if (Err)
8002 return std::move(Err);
8003
8004 if (E->isArgumentType()) {
8005 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8006 import(E->getArgumentTypeInfo());
8007 if (!ToArgumentTypeInfoOrErr)
8008 return ToArgumentTypeInfoOrErr.takeError();
8009
8010 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8011 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8012 ToRParenLoc);
8013 }
8014
8015 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8016 if (!ToArgumentExprOrErr)
8017 return ToArgumentExprOrErr.takeError();
8018
8019 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8020 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8021}
8022
8024 Error Err = Error::success();
8025 auto ToLHS = importChecked(Err, E->getLHS());
8026 auto ToRHS = importChecked(Err, E->getRHS());
8027 auto ToType = importChecked(Err, E->getType());
8028 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8029 if (Err)
8030 return std::move(Err);
8031
8033 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8034 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8035 E->getFPFeatures());
8036}
8037
8039 Error Err = Error::success();
8040 auto ToCond = importChecked(Err, E->getCond());
8041 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8042 auto ToLHS = importChecked(Err, E->getLHS());
8043 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8044 auto ToRHS = importChecked(Err, E->getRHS());
8045 auto ToType = importChecked(Err, E->getType());
8046 if (Err)
8047 return std::move(Err);
8048
8049 return new (Importer.getToContext()) ConditionalOperator(
8050 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8051 E->getValueKind(), E->getObjectKind());
8052}
8053
8056 Error Err = Error::success();
8057 auto ToCommon = importChecked(Err, E->getCommon());
8058 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8059 auto ToCond = importChecked(Err, E->getCond());
8060 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8061 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8062 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8063 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8064 auto ToType = importChecked(Err, E->getType());
8065 if (Err)
8066 return std::move(Err);
8067
8068 return new (Importer.getToContext()) BinaryConditionalOperator(
8069 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8070 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8071 E->getObjectKind());
8072}
8073
8076 Error Err = Error::success();
8077 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8078 if (Err)
8079 return std::move(Err);
8080
8081 return new (Importer.getToContext())
8082 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8083}
8084
8086 Error Err = Error::success();
8087 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8088 auto ToQueriedTypeSourceInfo =
8090 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8091 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8092 auto ToType = importChecked(Err, E->getType());
8093 if (Err)
8094 return std::move(Err);
8095
8096 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8097 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8098 ToDimensionExpression, ToEndLoc, ToType);
8099}
8100
8102 Error Err = Error::success();
8103 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8104 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8105 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8106 auto ToType = importChecked(Err, E->getType());
8107 if (Err)
8108 return std::move(Err);
8109
8110 return new (Importer.getToContext()) ExpressionTraitExpr(
8111 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8112 ToEndLoc, ToType);
8113}
8114
8116 Error Err = Error::success();
8117 auto ToLocation = importChecked(Err, E->getLocation());
8118 auto ToType = importChecked(Err, E->getType());
8119 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8120 if (Err)
8121 return std::move(Err);
8122
8123 return new (Importer.getToContext()) OpaqueValueExpr(
8124 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8125}
8126
8128 Error Err = Error::success();
8129 auto ToLHS = importChecked(Err, E->getLHS());
8130 auto ToRHS = importChecked(Err, E->getRHS());
8131 auto ToType = importChecked(Err, E->getType());
8132 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8133 if (Err)
8134 return std::move(Err);
8135
8136 return new (Importer.getToContext()) ArraySubscriptExpr(
8137 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8138 ToRBracketLoc);
8139}
8140
8143 Error Err = Error::success();
8144 auto ToLHS = importChecked(Err, E->getLHS());
8145 auto ToRHS = importChecked(Err, E->getRHS());
8146 auto ToType = importChecked(Err, E->getType());
8147 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8148 auto ToComputationResultType =
8150 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8151 if (Err)
8152 return std::move(Err);
8153
8155 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8156 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8157 E->getFPFeatures(),
8158 ToComputationLHSType, ToComputationResultType);
8159}
8160
8163 CXXCastPath Path;
8164 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8165 if (auto SpecOrErr = import(*I))
8166 Path.push_back(*SpecOrErr);
8167 else
8168 return SpecOrErr.takeError();
8169 }
8170 return Path;
8171}
8172
8174 ExpectedType ToTypeOrErr = import(E->getType());
8175 if (!ToTypeOrErr)
8176 return ToTypeOrErr.takeError();
8177
8178 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8179 if (!ToSubExprOrErr)
8180 return ToSubExprOrErr.takeError();
8181
8182 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8183 if (!ToBasePathOrErr)
8184 return ToBasePathOrErr.takeError();
8185
8187 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8188 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8189}
8190
8192 Error Err = Error::success();
8193 auto ToType = importChecked(Err, E->getType());
8194 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8195 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8196 if (Err)
8197 return std::move(Err);
8198
8199 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8200 if (!ToBasePathOrErr)
8201 return ToBasePathOrErr.takeError();
8202 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8203
8204 switch (E->getStmtClass()) {
8205 case Stmt::CStyleCastExprClass: {
8206 auto *CCE = cast<CStyleCastExpr>(E);
8207 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8208 if (!ToLParenLocOrErr)
8209 return ToLParenLocOrErr.takeError();
8210 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8211 if (!ToRParenLocOrErr)
8212 return ToRParenLocOrErr.takeError();
8214 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8215 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8216 *ToLParenLocOrErr, *ToRParenLocOrErr);
8217 }
8218
8219 case Stmt::CXXFunctionalCastExprClass: {
8220 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8221 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8222 if (!ToLParenLocOrErr)
8223 return ToLParenLocOrErr.takeError();
8224 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8225 if (!ToRParenLocOrErr)
8226 return ToRParenLocOrErr.takeError();
8228 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8229 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8230 *ToLParenLocOrErr, *ToRParenLocOrErr);
8231 }
8232
8233 case Stmt::ObjCBridgedCastExprClass: {
8234 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8235 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8236 if (!ToLParenLocOrErr)
8237 return ToLParenLocOrErr.takeError();
8238 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8239 if (!ToBridgeKeywordLocOrErr)
8240 return ToBridgeKeywordLocOrErr.takeError();
8241 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8242 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8243 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8244 }
8245 case Stmt::BuiltinBitCastExprClass: {
8246 auto *BBC = cast<BuiltinBitCastExpr>(E);
8247 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8248 if (!ToKWLocOrErr)
8249 return ToKWLocOrErr.takeError();
8250 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8251 if (!ToRParenLocOrErr)
8252 return ToRParenLocOrErr.takeError();
8253 return new (Importer.getToContext()) BuiltinBitCastExpr(
8254 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8255 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8256 }
8257 default:
8258 llvm_unreachable("Cast expression of unsupported type!");
8259 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8260 }
8261}
8262
8265 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8266 const OffsetOfNode &FromNode = E->getComponent(I);
8267
8268 SourceLocation ToBeginLoc, ToEndLoc;
8269
8270 if (FromNode.getKind() != OffsetOfNode::Base) {
8271 Error Err = Error::success();
8272 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8273 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8274 if (Err)
8275 return std::move(Err);
8276 }
8277
8278 switch (FromNode.getKind()) {
8280 ToNodes.push_back(
8281 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8282 break;
8283 case OffsetOfNode::Base: {
8284 auto ToBSOrErr = import(FromNode.getBase());
8285 if (!ToBSOrErr)
8286 return ToBSOrErr.takeError();
8287 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8288 break;
8289 }
8290 case OffsetOfNode::Field: {
8291 auto ToFieldOrErr = import(FromNode.getField());
8292 if (!ToFieldOrErr)
8293 return ToFieldOrErr.takeError();
8294 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8295 break;
8296 }
8298 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8299 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8300 break;
8301 }
8302 }
8303 }
8304
8306 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8307 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8308 if (!ToIndexExprOrErr)
8309 return ToIndexExprOrErr.takeError();
8310 ToExprs[I] = *ToIndexExprOrErr;
8311 }
8312
8313 Error Err = Error::success();
8314 auto ToType = importChecked(Err, E->getType());
8315 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8316 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8317 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8318 if (Err)
8319 return std::move(Err);
8320
8321 return OffsetOfExpr::Create(
8322 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8323 ToExprs, ToRParenLoc);
8324}
8325
8327 Error Err = Error::success();
8328 auto ToType = importChecked(Err, E->getType());
8329 auto ToOperand = importChecked(Err, E->getOperand());
8330 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8331 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8332 if (Err)
8333 return std::move(Err);
8334
8335 CanThrowResult ToCanThrow;
8336 if (E->isValueDependent())
8337 ToCanThrow = CT_Dependent;
8338 else
8339 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8340
8341 return new (Importer.getToContext()) CXXNoexceptExpr(
8342 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8343}
8344
8346 Error Err = Error::success();
8347 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8348 auto ToType = importChecked(Err, E->getType());
8349 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8350 if (Err)
8351 return std::move(Err);
8352
8353 return new (Importer.getToContext()) CXXThrowExpr(
8354 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8355}
8356
8358 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8359 if (!ToUsedLocOrErr)
8360 return ToUsedLocOrErr.takeError();
8361
8362 auto ToParamOrErr = import(E->getParam());
8363 if (!ToParamOrErr)
8364 return ToParamOrErr.takeError();
8365
8366 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8367 if (!UsedContextOrErr)
8368 return UsedContextOrErr.takeError();
8369
8370 // Import the default arg if it was not imported yet.
8371 // This is needed because it can happen that during the import of the
8372 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8373 // encountered here. The default argument for a ParmVarDecl is set in the
8374 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8375 // see VisitParmVarDecl).
8376 ParmVarDecl *ToParam = *ToParamOrErr;
8377 if (!ToParam->getDefaultArg()) {
8378 std::optional<ParmVarDecl *> FromParam =
8379 Importer.getImportedFromDecl(ToParam);
8380 assert(FromParam && "ParmVarDecl was not imported?");
8381
8382 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8383 return std::move(Err);
8384 }
8385 Expr *RewrittenInit = nullptr;
8386 if (E->hasRewrittenInit()) {
8387 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8388 if (!ExprOrErr)
8389 return ExprOrErr.takeError();
8390 RewrittenInit = ExprOrErr.get();
8391 }
8392 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8393 *ToParamOrErr, RewrittenInit,
8394 *UsedContextOrErr);
8395}
8396
8399 Error Err = Error::success();
8400 auto ToType = importChecked(Err, E->getType());
8401 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8402 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8403 if (Err)
8404 return std::move(Err);
8405
8406 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8407 ToType, ToTypeSourceInfo, ToRParenLoc);
8408}
8409
8412 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8413 if (!ToSubExprOrErr)
8414 return ToSubExprOrErr.takeError();
8415
8416 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8417 if (!ToDtorOrErr)
8418 return ToDtorOrErr.takeError();
8419
8420 ASTContext &ToCtx = Importer.getToContext();
8421 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8422 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8423}
8424
8426
8428 Error Err = Error::success();
8429 auto ToConstructor = importChecked(Err, E->getConstructor());
8430 auto ToType = importChecked(Err, E->getType());
8431 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8432 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8433 if (Err)
8434 return std::move(Err);
8435
8437 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8438 return std::move(Err);
8439
8441 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8442 ToParenOrBraceRange, E->hadMultipleCandidates(),
8445}
8446
8449 DeclContext *DC, *LexicalDC;
8450 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8451 return std::move(Err);
8452
8453 Error Err = Error::success();
8454 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8455 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8456 if (Err)
8457 return std::move(Err);
8458 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8459
8461 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8462 D->getManglingNumber()))
8463 return To;
8464
8465 To->setLexicalDeclContext(LexicalDC);
8466 LexicalDC->addDeclInternal(To);
8467 return To;
8468}
8469
8472 Error Err = Error::success();
8473 auto ToType = importChecked(Err, E->getType());
8474 Expr *ToTemporaryExpr = importChecked(
8475 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8476 auto ToMaterializedDecl =
8478 if (Err)
8479 return std::move(Err);
8480
8481 if (!ToTemporaryExpr)
8482 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8483
8484 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8485 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8486 ToMaterializedDecl);
8487
8488 return ToMTE;
8489}
8490
8492 Error Err = Error::success();
8493 auto *ToPattern = importChecked(Err, E->getPattern());
8494 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8495 if (Err)
8496 return std::move(Err);
8497
8498 return new (Importer.getToContext())
8499 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8500}
8501
8503 Error Err = Error::success();
8504 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8505 auto ToPack = importChecked(Err, E->getPack());
8506 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8507 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8508 if (Err)
8509 return std::move(Err);
8510
8511 UnsignedOrNone Length = std::nullopt;
8512 if (!E->isValueDependent())
8513 Length = E->getPackLength();
8514
8515 SmallVector<TemplateArgument, 8> ToPartialArguments;
8516 if (E->isPartiallySubstituted()) {
8518 ToPartialArguments))
8519 return std::move(Err);
8520 }
8521
8523 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8524 Length, ToPartialArguments);
8525}
8526
8527
8529 Error Err = Error::success();
8530 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8531 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8532 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8533 auto ToArraySize = importChecked(Err, E->getArraySize());
8534 auto ToInitializer = importChecked(Err, E->getInitializer());
8535 auto ToType = importChecked(Err, E->getType());
8536 auto ToAllocatedTypeSourceInfo =
8538 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8539 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8540 if (Err)
8541 return std::move(Err);
8542
8543 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8544 if (Error Err =
8545 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8546 return std::move(Err);
8547
8548 return CXXNewExpr::Create(
8549 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8550 ToOperatorDelete, E->implicitAllocationParameters(),
8551 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8552 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8553 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8554}
8555
8557 Error Err = Error::success();
8558 auto ToType = importChecked(Err, E->getType());
8559 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8560 auto ToArgument = importChecked(Err, E->getArgument());
8561 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8562 if (Err)
8563 return std::move(Err);
8564
8565 return new (Importer.getToContext()) CXXDeleteExpr(
8566 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8567 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8568 ToBeginLoc);
8569}
8570
8572 Error Err = Error::success();
8573 auto ToType = importChecked(Err, E->getType());
8574 auto ToLocation = importChecked(Err, E->getLocation());
8575 auto ToConstructor = importChecked(Err, E->getConstructor());
8576 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8577 if (Err)
8578 return std::move(Err);
8579
8581 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8582 return std::move(Err);
8583
8585 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8586 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8589 ToParenOrBraceRange);
8591 return ToE;
8592}
8593
8595 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8596 if (!ToSubExprOrErr)
8597 return ToSubExprOrErr.takeError();
8598
8600 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8601 return std::move(Err);
8602
8604 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8605 ToObjects);
8606}
8607
8609 Error Err = Error::success();
8610 auto ToCallee = importChecked(Err, E->getCallee());
8611 auto ToType = importChecked(Err, E->getType());
8612 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8613 if (Err)
8614 return std::move(Err);
8615
8617 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8618 return std::move(Err);
8619
8620 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8621 ToType, E->getValueKind(), ToRParenLoc,
8622 E->getFPFeatures());
8623}
8624
8626 ExpectedType ToTypeOrErr = import(E->getType());
8627 if (!ToTypeOrErr)
8628 return ToTypeOrErr.takeError();
8629
8630 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8631 if (!ToLocationOrErr)
8632 return ToLocationOrErr.takeError();
8633
8634 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8635 *ToTypeOrErr, E->isImplicit());
8636}
8637
8639 ExpectedType ToTypeOrErr = import(E->getType());
8640 if (!ToTypeOrErr)
8641 return ToTypeOrErr.takeError();
8642
8643 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8644 if (!ToLocationOrErr)
8645 return ToLocationOrErr.takeError();
8646
8647 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8648 *ToTypeOrErr, *ToLocationOrErr);
8649}
8650
8652 Error Err = Error::success();
8653 auto ToBase = importChecked(Err, E->getBase());
8654 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8655 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8656 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8657 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8658 auto ToType = importChecked(Err, E->getType());
8659 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8660 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8661 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8662 if (Err)
8663 return std::move(Err);
8664
8665 DeclAccessPair ToFoundDecl =
8667
8668 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8669
8670 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8671 if (E->hasExplicitTemplateArgs()) {
8672 if (Error Err =
8674 E->template_arguments(), ToTAInfo))
8675 return std::move(Err);
8676 ResInfo = &ToTAInfo;
8677 }
8678
8679 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8680 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8681 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8682 ResInfo, ToType, E->getValueKind(),
8683 E->getObjectKind(), E->isNonOdrUse());
8684}
8685
8688 Error Err = Error::success();
8689 auto ToBase = importChecked(Err, E->getBase());
8690 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8691 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8692 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8693 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8694 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8695 if (Err)
8696 return std::move(Err);
8697
8699 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8700 const IdentifierInfo *ToII = Importer.Import(FromII);
8701 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8702 if (!ToDestroyedTypeLocOrErr)
8703 return ToDestroyedTypeLocOrErr.takeError();
8704 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8705 } else {
8706 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8707 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8708 else
8709 return ToTIOrErr.takeError();
8710 }
8711
8712 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8713 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8714 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8715}
8716
8719 Error Err = Error::success();
8720 auto ToType = importChecked(Err, E->getType());
8721 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8722 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8723 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8724 auto ToFirstQualifierFoundInScope =
8726 if (Err)
8727 return std::move(Err);
8728
8729 Expr *ToBase = nullptr;
8730 if (!E->isImplicitAccess()) {
8731 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8732 ToBase = *ToBaseOrErr;
8733 else
8734 return ToBaseOrErr.takeError();
8735 }
8736
8737 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8738
8739 if (E->hasExplicitTemplateArgs()) {
8740 if (Error Err =
8742 E->template_arguments(), ToTAInfo))
8743 return std::move(Err);
8744 ResInfo = &ToTAInfo;
8745 }
8746 auto ToMember = importChecked(Err, E->getMember());
8747 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8748 if (Err)
8749 return std::move(Err);
8750 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8751
8752 // Import additional name location/type info.
8753 if (Error Err =
8754 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8755 return std::move(Err);
8756
8758 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8759 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8760 ToMemberNameInfo, ResInfo);
8761}
8762
8765 Error Err = Error::success();
8766 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8767 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8768 auto ToDeclName = importChecked(Err, E->getDeclName());
8769 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8770 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8771 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8772 if (Err)
8773 return std::move(Err);
8774
8775 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8776 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8777 return std::move(Err);
8778
8779 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8780 TemplateArgumentListInfo *ResInfo = nullptr;
8781 if (E->hasExplicitTemplateArgs()) {
8782 if (Error Err =
8784 return std::move(Err);
8785 ResInfo = &ToTAInfo;
8786 }
8787
8789 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8790 ToNameInfo, ResInfo);
8791}
8792
8795 Error Err = Error::success();
8796 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8797 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8798 auto ToType = importChecked(Err, E->getType());
8799 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8800 if (Err)
8801 return std::move(Err);
8802
8804 if (Error Err =
8805 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8806 return std::move(Err);
8807
8809 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8810 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8811}
8812
8815 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8816 if (!ToNamingClassOrErr)
8817 return ToNamingClassOrErr.takeError();
8818
8819 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8820 if (!ToQualifierLocOrErr)
8821 return ToQualifierLocOrErr.takeError();
8822
8823 Error Err = Error::success();
8824 auto ToName = importChecked(Err, E->getName());
8825 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8826 if (Err)
8827 return std::move(Err);
8828 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8829
8830 // Import additional name location/type info.
8831 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8832 return std::move(Err);
8833
8834 UnresolvedSet<8> ToDecls;
8835 for (auto *D : E->decls())
8836 if (auto ToDOrErr = import(D))
8837 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8838 else
8839 return ToDOrErr.takeError();
8840
8841 if (E->hasExplicitTemplateArgs()) {
8842 TemplateArgumentListInfo ToTAInfo;
8845 ToTAInfo))
8846 return std::move(Err);
8847
8848 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8849 if (!ToTemplateKeywordLocOrErr)
8850 return ToTemplateKeywordLocOrErr.takeError();
8851
8852 const bool KnownDependent =
8853 (E->getDependence() & ExprDependence::TypeValue) ==
8854 ExprDependence::TypeValue;
8856 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8857 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8858 ToDecls.begin(), ToDecls.end(), KnownDependent,
8859 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8860 }
8861
8863 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8864 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8865 /*KnownDependent=*/E->isTypeDependent(),
8866 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8867}
8868
8871 Error Err = Error::success();
8872 auto ToType = importChecked(Err, E->getType());
8873 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8874 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8875 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8876 auto ToName = importChecked(Err, E->getName());
8877 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8878 if (Err)
8879 return std::move(Err);
8880
8881 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8882 // Import additional name location/type info.
8883 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8884 return std::move(Err);
8885
8886 UnresolvedSet<8> ToDecls;
8887 for (Decl *D : E->decls())
8888 if (auto ToDOrErr = import(D))
8889 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8890 else
8891 return ToDOrErr.takeError();
8892
8893 TemplateArgumentListInfo ToTAInfo;
8894 TemplateArgumentListInfo *ResInfo = nullptr;
8895 if (E->hasExplicitTemplateArgs()) {
8896 TemplateArgumentListInfo FromTAInfo;
8897 E->copyTemplateArgumentsInto(FromTAInfo);
8898 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8899 return std::move(Err);
8900 ResInfo = &ToTAInfo;
8901 }
8902
8903 Expr *ToBase = nullptr;
8904 if (!E->isImplicitAccess()) {
8905 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8906 ToBase = *ToBaseOrErr;
8907 else
8908 return ToBaseOrErr.takeError();
8909 }
8910
8912 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8913 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8914 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8915}
8916
8918 Error Err = Error::success();
8919 auto ToCallee = importChecked(Err, E->getCallee());
8920 auto ToType = importChecked(Err, E->getType());
8921 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8922 if (Err)
8923 return std::move(Err);
8924
8925 unsigned NumArgs = E->getNumArgs();
8926 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8927 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8928 return std::move(Err);
8929
8930 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8932 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8933 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8934 OCE->getADLCallKind());
8935 }
8936
8937 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8938 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8939 /*MinNumArgs=*/0, E->getADLCallKind());
8940}
8941
8943 CXXRecordDecl *FromClass = E->getLambdaClass();
8944 auto ToClassOrErr = import(FromClass);
8945 if (!ToClassOrErr)
8946 return ToClassOrErr.takeError();
8947 CXXRecordDecl *ToClass = *ToClassOrErr;
8948
8949 auto ToCallOpOrErr = import(E->getCallOperator());
8950 if (!ToCallOpOrErr)
8951 return ToCallOpOrErr.takeError();
8952
8953 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8954 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8955 return std::move(Err);
8956
8957 Error Err = Error::success();
8958 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8959 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8960 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8961 if (Err)
8962 return std::move(Err);
8963
8964 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8965 E->getCaptureDefault(), ToCaptureDefaultLoc,
8967 E->hasExplicitResultType(), ToCaptureInits,
8968 ToEndLoc, E->containsUnexpandedParameterPack());
8969}
8970
8971
8973 Error Err = Error::success();
8974 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8975 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8976 auto ToType = importChecked(Err, E->getType());
8977 if (Err)
8978 return std::move(Err);
8979
8980 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8981 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8982 return std::move(Err);
8983
8984 ASTContext &ToCtx = Importer.getToContext();
8985 InitListExpr *To = new (ToCtx)
8986 InitListExpr(ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc, E->isExplicit());
8987 To->setType(ToType);
8988
8989 if (E->hasArrayFiller()) {
8990 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8991 To->setArrayFiller(*ToFillerOrErr);
8992 else
8993 return ToFillerOrErr.takeError();
8994 }
8995
8996 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
8997 if (auto ToFDOrErr = import(FromFD))
8998 To->setInitializedFieldInUnion(*ToFDOrErr);
8999 else
9000 return ToFDOrErr.takeError();
9001 }
9002
9003 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9004 if (auto ToSyntFormOrErr = import(SyntForm))
9005 To->setSyntacticForm(*ToSyntFormOrErr);
9006 else
9007 return ToSyntFormOrErr.takeError();
9008 }
9009
9010 // Copy InitListExprBitfields, which are not handled in the ctor of
9011 // InitListExpr.
9013
9014 return To;
9015}
9016
9019 ExpectedType ToTypeOrErr = import(E->getType());
9020 if (!ToTypeOrErr)
9021 return ToTypeOrErr.takeError();
9022
9023 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9024 if (!ToSubExprOrErr)
9025 return ToSubExprOrErr.takeError();
9026
9027 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9028 *ToTypeOrErr, *ToSubExprOrErr);
9029}
9030
9033 Error Err = Error::success();
9034 auto ToLocation = importChecked(Err, E->getLocation());
9035 auto ToType = importChecked(Err, E->getType());
9036 auto ToConstructor = importChecked(Err, E->getConstructor());
9037 if (Err)
9038 return std::move(Err);
9039
9040 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9041 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9042 E->inheritedFromVBase());
9043}
9044
9046 Error Err = Error::success();
9047 auto ToType = importChecked(Err, E->getType());
9048 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9049 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9050 if (Err)
9051 return std::move(Err);
9052
9053 return new (Importer.getToContext()) ArrayInitLoopExpr(
9054 ToType, ToCommonExpr, ToSubExpr);
9055}
9056
9058 ExpectedType ToTypeOrErr = import(E->getType());
9059 if (!ToTypeOrErr)
9060 return ToTypeOrErr.takeError();
9061 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9062}
9063
9065 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9066 if (!ToBeginLocOrErr)
9067 return ToBeginLocOrErr.takeError();
9068
9069 auto ToFieldOrErr = import(E->getField());
9070 if (!ToFieldOrErr)
9071 return ToFieldOrErr.takeError();
9072
9073 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9074 if (!UsedContextOrErr)
9075 return UsedContextOrErr.takeError();
9076
9077 FieldDecl *ToField = *ToFieldOrErr;
9078 assert(ToField->hasInClassInitializer() &&
9079 "Field should have in-class initializer if there is a default init "
9080 "expression that uses it.");
9081 if (!ToField->getInClassInitializer()) {
9082 // The in-class initializer may be not yet set in "To" AST even if the
9083 // field is already there. This must be set here to make construction of
9084 // CXXDefaultInitExpr work.
9085 auto ToInClassInitializerOrErr =
9086 import(E->getField()->getInClassInitializer());
9087 if (!ToInClassInitializerOrErr)
9088 return ToInClassInitializerOrErr.takeError();
9089 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9090 }
9091
9092 Expr *RewrittenInit = nullptr;
9093 if (E->hasRewrittenInit()) {
9094 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9095 if (!ExprOrErr)
9096 return ExprOrErr.takeError();
9097 RewrittenInit = ExprOrErr.get();
9098 }
9099
9100 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9101 ToField, *UsedContextOrErr, RewrittenInit);
9102}
9103
9105 Error Err = Error::success();
9106 auto ToType = importChecked(Err, E->getType());
9107 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9108 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9109 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9110 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9111 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9112 if (Err)
9113 return std::move(Err);
9114
9116 CastKind CK = E->getCastKind();
9117 auto ToBasePathOrErr = ImportCastPath(E);
9118 if (!ToBasePathOrErr)
9119 return ToBasePathOrErr.takeError();
9120
9121 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9123 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9124 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9125 ToAngleBrackets);
9126 } else if (isa<CXXDynamicCastExpr>(E)) {
9128 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9129 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9130 } else if (isa<CXXReinterpretCastExpr>(E)) {
9132 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9133 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9134 } else if (isa<CXXConstCastExpr>(E)) {
9136 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9137 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9138 } else {
9139 llvm_unreachable("Unknown cast type");
9140 return make_error<ASTImportError>();
9141 }
9142}
9143
9146 Error Err = Error::success();
9147 auto ToType = importChecked(Err, E->getType());
9148 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9149 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9150 auto ToParamType = importChecked(Err, E->getParameterType());
9151 auto ToReplacement = importChecked(Err, E->getReplacement());
9152 if (Err)
9153 return std::move(Err);
9154
9155 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9156 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9157 ToParamType, E->getIndex(), E->getPackIndex(), E->getFinal());
9158}
9159
9161 Error Err = Error::success();
9162 auto ToType = importChecked(Err, E->getType());
9163 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9164 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9165 if (Err)
9166 return std::move(Err);
9167
9169 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9170 return std::move(Err);
9171
9172 if (E->isStoredAsBoolean()) {
9173 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9174 // Value is always false.
9175 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9176 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9177 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9178 }
9179 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9180 E->getTrait(), ToArgs, ToEndLoc,
9181 E->getAPValue());
9182}
9183
9185 ExpectedType ToTypeOrErr = import(E->getType());
9186 if (!ToTypeOrErr)
9187 return ToTypeOrErr.takeError();
9188
9189 auto ToSourceRangeOrErr = import(E->getSourceRange());
9190 if (!ToSourceRangeOrErr)
9191 return ToSourceRangeOrErr.takeError();
9192
9193 if (E->isTypeOperand()) {
9194 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9195 return new (Importer.getToContext()) CXXTypeidExpr(
9196 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9197 else
9198 return ToTSIOrErr.takeError();
9199 }
9200
9201 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9202 if (!ToExprOperandOrErr)
9203 return ToExprOperandOrErr.takeError();
9204
9205 return new (Importer.getToContext()) CXXTypeidExpr(
9206 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9207}
9208
9210 Error Err = Error::success();
9211
9212 QualType ToType = importChecked(Err, E->getType());
9213 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9214 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9215 Expr *ToLHS = importChecked(Err, E->getLHS());
9216 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9217 Expr *ToRHS = importChecked(Err, E->getRHS());
9218 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9219
9220 if (Err)
9221 return std::move(Err);
9222
9223 return new (Importer.getToContext())
9224 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9225 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9226}
9227
9229 Error Err = Error::success();
9230 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9231 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9232 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9233
9234 auto Body = importChecked(Err, E->getBody());
9235 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9236 if (Err)
9237 return std::move(Err);
9238 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9239 if (Error Err =
9240 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9241 return std::move(Err);
9243 E->getRequirements().size());
9244 if (Error Err =
9245 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9246 return std::move(Err);
9247 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9248 LParenLoc, LocalParameters, RParenLoc,
9249 Requirements, RBraceLoc);
9250}
9251
9254 Error Err = Error::success();
9255 auto CL = importChecked(Err, E->getConceptReference());
9256 auto CSD = importChecked(Err, E->getSpecializationDecl());
9257 if (Err)
9258 return std::move(Err);
9259 if (E->isValueDependent())
9261 Importer.getToContext(), CL,
9262 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9263 ConstraintSatisfaction Satisfaction;
9264 if (Error Err =
9266 return std::move(Err);
9268 Importer.getToContext(), CL,
9269 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9270}
9271
9274 Error Err = Error::success();
9275 auto ToType = importChecked(Err, E->getType());
9276 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9277 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9278 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9279 if (Err)
9280 return std::move(Err);
9281
9282 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9283 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9284 E->getIndex(), E->getFinal());
9285}
9286
9289 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9290 return std::move(Err);
9291 auto ToSyntOrErr = import(E->getSyntacticForm());
9292 if (!ToSyntOrErr)
9293 return ToSyntOrErr.takeError();
9294 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9295 ToSemantics, E->getResultExprIndex());
9296}
9297
9300 Error Err = Error::success();
9301 auto ToType = importChecked(Err, E->getType());
9302 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9303 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9304 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9305 if (Err)
9306 return std::move(Err);
9307
9308 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9309 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9310 return std::move(Err);
9311 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9312 E->getUserSpecifiedInitExprs().size(),
9313 ToInitLoc, ToBeginLoc, ToEndLoc);
9314}
9315
9318 Error Err = Error::success();
9319 auto ToRange = importChecked(Err, E->getRangeExpr());
9320 auto ToIndex = importChecked(Err, E->getIndexExpr());
9321 if (Err)
9322 return std::move(Err);
9323
9324 return new (Importer.getToContext())
9325 CXXExpansionSelectExpr(Importer.getToContext(), ToRange, ToIndex);
9326}
9327
9329 CXXMethodDecl *FromMethod) {
9330 Error ImportErrors = Error::success();
9331 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9332 if (auto ImportedOrErr = import(FromOverriddenMethod))
9334 (*ImportedOrErr)->getCanonicalDecl()));
9335 else
9336 ImportErrors =
9337 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9338 }
9339 return ImportErrors;
9340}
9341
9343 ASTContext &FromContext, FileManager &FromFileManager,
9344 bool MinimalImport,
9345 std::shared_ptr<ASTImporterSharedState> SharedState)
9346 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9347 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9348 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9349
9350 // Create a default state without the lookup table: LLDB case.
9351 if (!SharedState) {
9352 this->SharedState = std::make_shared<ASTImporterSharedState>();
9353 }
9354
9355 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9356 ToContext.getTranslationUnitDecl();
9357}
9358
9359ASTImporter::~ASTImporter() = default;
9360
9362 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9363 "Try to get field index for non-field.");
9364
9365 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9366 if (!Owner)
9367 return std::nullopt;
9368
9369 unsigned Index = 0;
9370 for (const auto *D : Owner->decls()) {
9371 if (D == F)
9372 return Index;
9373
9375 ++Index;
9376 }
9377
9378 llvm_unreachable("Field was not found in its parent context.");
9379
9380 return std::nullopt;
9381}
9382
9383ASTImporter::FoundDeclsTy
9384ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9385 // We search in the redecl context because of transparent contexts.
9386 // E.g. a simple C language enum is a transparent context:
9387 // enum E { A, B };
9388 // Now if we had a global variable in the TU
9389 // int A;
9390 // then the enum constant 'A' and the variable 'A' violates ODR.
9391 // We can diagnose this only if we search in the redecl context.
9392 DeclContext *ReDC = DC->getRedeclContext();
9393 if (SharedState->getLookupTable()) {
9394 if (ReDC->isNamespace()) {
9395 // Namespaces can be reopened.
9396 // Lookup table does not handle this, we must search here in all linked
9397 // namespaces.
9398 FoundDeclsTy Result;
9399 SmallVector<Decl *, 2> NSChain =
9401 dyn_cast<NamespaceDecl>(ReDC));
9402 for (auto *D : NSChain) {
9404 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9405 Name);
9407 }
9408 return Result;
9409 } else {
9411 SharedState->getLookupTable()->lookup(ReDC, Name);
9412 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9413 }
9414 } else {
9415 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9416 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9417 // We must search by the slow case of localUncachedLookup because that is
9418 // working even if there is no LookupPtr for the DC. We could use
9419 // DC::buildLookup() to create the LookupPtr, but that would load external
9420 // decls again, we must avoid that case.
9421 // Also, even if we had the LookupPtr, we must find Decls which are not
9422 // in the LookupPtr, so we need the slow case.
9423 // These cases are handled in ASTImporterLookupTable, but we cannot use
9424 // that with LLDB since that traverses through the AST which initiates the
9425 // load of external decls again via DC::decls(). And again, we must avoid
9426 // loading external decls during the import.
9427 if (Result.empty())
9428 ReDC->localUncachedLookup(Name, Result);
9429 return Result;
9430 }
9431}
9432
9433void ASTImporter::AddToLookupTable(Decl *ToD) {
9434 SharedState->addDeclToLookup(ToD);
9435}
9436
9438 // Import the decl using ASTNodeImporter.
9439 ASTNodeImporter Importer(*this);
9440 return Importer.Visit(FromD);
9441}
9442
9444 MapImported(FromD, ToD);
9445}
9446
9449 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9450 if (Expected<Expr *> R = Import(CLE))
9452 }
9453
9454 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9455 // ASTNodeImporter.
9456 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9457}
9458
9460 if (!FromT)
9461 return FromT;
9462
9463 // Check whether we've already imported this type.
9464 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9465 ImportedTypes.find(FromT);
9466 if (Pos != ImportedTypes.end())
9467 return Pos->second;
9468
9469 // Import the type.
9470 ASTNodeImporter Importer(*this);
9471 ExpectedType ToTOrErr = Importer.Visit(FromT);
9472 if (!ToTOrErr)
9473 return ToTOrErr.takeError();
9474
9475 // Record the imported type.
9476 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9477
9478 return ToTOrErr->getTypePtr();
9479}
9480
9482 if (FromT.isNull())
9483 return QualType{};
9484
9485 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9486 if (!ToTyOrErr)
9487 return ToTyOrErr.takeError();
9488
9489 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9490}
9491
9493 if (!FromTSI)
9494 return FromTSI;
9495
9496 // FIXME: For now we just create a "trivial" type source info based
9497 // on the type and a single location. Implement a real version of this.
9498 ExpectedType TOrErr = Import(FromTSI->getType());
9499 if (!TOrErr)
9500 return TOrErr.takeError();
9501 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9502 if (!BeginLocOrErr)
9503 return BeginLocOrErr.takeError();
9504
9505 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9506}
9507
9508namespace {
9509// To use this object, it should be created before the new attribute is created,
9510// and destructed after it is created. The construction already performs the
9511// import of the data.
9512template <typename T> struct AttrArgImporter {
9513 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9514 AttrArgImporter(AttrArgImporter<T> &&) = default;
9515 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9516 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9517
9518 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9519 : To(I.importChecked(Err, From)) {}
9520
9521 const T &value() { return To; }
9522
9523private:
9524 T To;
9525};
9526
9527// To use this object, it should be created before the new attribute is created,
9528// and destructed after it is created. The construction already performs the
9529// import of the data. The array data is accessible in a pointer form, this form
9530// is used by the attribute classes. This object should be created once for the
9531// array data to be imported (the array size is not imported, just copied).
9532template <typename T> struct AttrArgArrayImporter {
9533 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9534 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9535 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9536 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9537
9538 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9539 const llvm::iterator_range<T *> &From,
9540 unsigned ArraySize) {
9541 if (Err)
9542 return;
9543 To.reserve(ArraySize);
9544 Err = I.ImportContainerChecked(From, To);
9545 }
9546
9547 T *value() { return To.data(); }
9548
9549private:
9550 llvm::SmallVector<T, 2> To;
9551};
9552
9553class AttrImporter {
9554 Error Err{Error::success()};
9555 Attr *ToAttr = nullptr;
9556 ASTImporter &Importer;
9557 ASTNodeImporter NImporter;
9558
9559public:
9560 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9561
9562 // Create an "importer" for an attribute parameter.
9563 // Result of the 'value()' of that object is to be passed to the function
9564 // 'importAttr', in the order that is expected by the attribute class.
9565 template <class T> AttrArgImporter<T> importArg(const T &From) {
9566 return AttrArgImporter<T>(NImporter, Err, From);
9567 }
9568
9569 // Create an "importer" for an attribute parameter that has array type.
9570 // Result of the 'value()' of that object is to be passed to the function
9571 // 'importAttr', then the size of the array as next argument.
9572 template <typename T>
9573 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9574 unsigned ArraySize) {
9575 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9576 }
9577
9578 // Create an attribute object with the specified arguments.
9579 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9580 // should be values that are passed to the 'Create' function of the attribute.
9581 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9582 // used here.) As much data is copied or imported from the old attribute
9583 // as possible. The passed arguments should be already imported.
9584 // If an import error happens, the internal error is set to it, and any
9585 // further import attempt is ignored.
9586 template <typename T, typename... Arg>
9587 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9588 static_assert(std::is_base_of<Attr, T>::value,
9589 "T should be subclass of Attr.");
9590 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9591
9592 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9593 const IdentifierInfo *ToScopeName =
9594 Importer.Import(FromAttr->getScopeName());
9595 SourceRange ToAttrRange =
9596 NImporter.importChecked(Err, FromAttr->getRange());
9597 SourceLocation ToScopeLoc =
9598 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9599
9600 if (Err)
9601 return;
9602
9603 AttributeCommonInfo ToI(
9604 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9605 FromAttr->getParsedKind(), FromAttr->getForm());
9606 // The "SemanticSpelling" is not needed to be passed to the constructor.
9607 // That value is recalculated from the SpellingListIndex if needed.
9608 ToAttr = T::Create(Importer.getToContext(),
9609 std::forward<Arg>(ImportedArg)..., ToI);
9610
9611 ToAttr->setImplicit(FromAttr->isImplicit());
9612 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9613 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9614 ToInheritableAttr->setInherited(FromAttr->isInherited());
9615 }
9616
9617 // Create a clone of the 'FromAttr' and import its source range only.
9618 // This causes objects with invalid references to be created if the 'FromAttr'
9619 // contains other data that should be imported.
9620 void cloneAttr(const Attr *FromAttr) {
9621 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9622
9623 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9624 if (Err)
9625 return;
9626
9627 ToAttr = FromAttr->clone(Importer.getToContext());
9628 ToAttr->setRange(ToRange);
9629 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9630 }
9631
9632 // Get the result of the previous import attempt (can be used only once).
9633 llvm::Expected<Attr *> getResult() && {
9634 if (Err)
9635 return std::move(Err);
9636 assert(ToAttr && "Attribute should be created.");
9637 return ToAttr;
9638 }
9639};
9640} // namespace
9641
9643 AttrImporter AI(*this);
9644
9645 // FIXME: Is there some kind of AttrVisitor to use here?
9646 switch (FromAttr->getKind()) {
9647 case attr::Aligned: {
9648 auto *From = cast<AlignedAttr>(FromAttr);
9649 if (From->isAlignmentExpr())
9650 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9651 else
9652 AI.importAttr(From, false,
9653 AI.importArg(From->getAlignmentType()).value());
9654 break;
9655 }
9656
9657 case attr::AlignValue: {
9658 auto *From = cast<AlignValueAttr>(FromAttr);
9659 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9660 break;
9661 }
9662
9663 case attr::Format: {
9664 const auto *From = cast<FormatAttr>(FromAttr);
9665 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9666 From->getFirstArg());
9667 break;
9668 }
9669
9670 case attr::EnableIf: {
9671 const auto *From = cast<EnableIfAttr>(FromAttr);
9672 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9673 From->getMessage());
9674 break;
9675 }
9676
9677 case attr::AssertCapability: {
9678 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9679 AI.importAttr(From,
9680 AI.importArrayArg(From->args(), From->args_size()).value(),
9681 From->args_size());
9682 break;
9683 }
9684 case attr::AcquireCapability: {
9685 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9686 AI.importAttr(From,
9687 AI.importArrayArg(From->args(), From->args_size()).value(),
9688 From->args_size());
9689 break;
9690 }
9691 case attr::TryAcquireCapability: {
9692 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9693 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9694 AI.importArrayArg(From->args(), From->args_size()).value(),
9695 From->args_size());
9696 break;
9697 }
9698 case attr::ReleaseCapability: {
9699 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9700 AI.importAttr(From,
9701 AI.importArrayArg(From->args(), From->args_size()).value(),
9702 From->args_size());
9703 break;
9704 }
9705 case attr::RequiresCapability: {
9706 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9707 AI.importAttr(From,
9708 AI.importArrayArg(From->args(), From->args_size()).value(),
9709 From->args_size());
9710 break;
9711 }
9712 case attr::GuardedBy: {
9713 const auto *From = cast<GuardedByAttr>(FromAttr);
9714 AI.importAttr(From,
9715 AI.importArrayArg(From->args(), From->args_size()).value(),
9716 From->args_size());
9717 break;
9718 }
9719 case attr::PtGuardedBy: {
9720 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9721 AI.importAttr(From,
9722 AI.importArrayArg(From->args(), From->args_size()).value(),
9723 From->args_size());
9724 break;
9725 }
9726 case attr::AcquiredAfter: {
9727 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9728 AI.importAttr(From,
9729 AI.importArrayArg(From->args(), From->args_size()).value(),
9730 From->args_size());
9731 break;
9732 }
9733 case attr::AcquiredBefore: {
9734 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9735 AI.importAttr(From,
9736 AI.importArrayArg(From->args(), From->args_size()).value(),
9737 From->args_size());
9738 break;
9739 }
9740 case attr::LockReturned: {
9741 const auto *From = cast<LockReturnedAttr>(FromAttr);
9742 AI.importAttr(From, AI.importArg(From->getArg()).value());
9743 break;
9744 }
9745 case attr::LocksExcluded: {
9746 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9747 AI.importAttr(From,
9748 AI.importArrayArg(From->args(), From->args_size()).value(),
9749 From->args_size());
9750 break;
9751 }
9752 default: {
9753 // The default branch works for attributes that have no arguments to import.
9754 // FIXME: Handle every attribute type that has arguments of type to import
9755 // (most often Expr* or Decl* or type) in the switch above.
9756 AI.cloneAttr(FromAttr);
9757 break;
9758 }
9759 }
9760
9761 return std::move(AI).getResult();
9762}
9763
9765 return ImportedDecls.lookup(FromD);
9766}
9767
9769 auto FromDPos = ImportedFromDecls.find(ToD);
9770 if (FromDPos == ImportedFromDecls.end())
9771 return nullptr;
9772 return FromDPos->second->getTranslationUnitDecl();
9773}
9774
9776 if (!FromD)
9777 return nullptr;
9778
9779 // Push FromD to the stack, and remove that when we return.
9780 ImportPath.push(FromD);
9781 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9782
9783 // Check whether there was a previous failed import.
9784 // If yes return the existing error.
9785 if (auto Error = getImportDeclErrorIfAny(FromD))
9786 return make_error<ASTImportError>(*Error);
9787
9788 // Check whether we've already imported this declaration.
9789 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9790 if (ToD) {
9791 // Already imported (possibly from another TU) and with an error.
9792 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9793 setImportDeclError(FromD, *Error);
9794 return make_error<ASTImportError>(*Error);
9795 }
9796
9797 // If FromD has some updated flags after last import, apply it.
9798 updateFlags(FromD, ToD);
9799 // If we encounter a cycle during an import then we save the relevant part
9800 // of the import path associated to the Decl.
9801 if (ImportPath.hasCycleAtBack())
9802 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9803 return ToD;
9804 }
9805
9806 // Import the declaration.
9807 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9808 if (!ToDOrErr) {
9809 // Failed to import.
9810
9811 auto Pos = ImportedDecls.find(FromD);
9812 bool ToDWasCreated = Pos != ImportedDecls.end();
9813 // Capture the mapped decl before erasing: the iterator is invalidated by
9814 // the erase below under backward-shift deletion, but it is still needed
9815 // further down to record the import error.
9816 Decl *CreatedToD = ToDWasCreated ? Pos->second : nullptr;
9817 if (ToDWasCreated) {
9818 // Import failed after the object was created.
9819 // Remove all references to it.
9820 auto *ToD = CreatedToD;
9821 ImportedDecls.erase(Pos);
9822
9823 // Remove the imported type mapping as well.
9824 // The imported type can point to a declaration that failed to import
9825 // later.
9826 if (const auto *FromTD = dyn_cast<TagDecl>(FromD)) {
9827 if (const Type *FromTy =
9828 getFromContext().getCanonicalTagType(FromTD).getTypePtr()) {
9829 ImportedTypes.erase(FromTy);
9830 }
9831 }
9832
9833 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9834 // (e.g. with namespaces) that several decls from the 'from' context are
9835 // mapped to the same decl in the 'to' context. If we removed entries
9836 // from the LookupTable here then we may end up removing them multiple
9837 // times.
9838
9839 // The Lookuptable contains decls only which are in the 'to' context.
9840 // Remove from the Lookuptable only if it is *imported* into the 'to'
9841 // context (and do not remove it if it was added during the initial
9842 // traverse of the 'to' context).
9843 auto PosF = ImportedFromDecls.find(ToD);
9844 if (PosF != ImportedFromDecls.end()) {
9845 // In the case of TypedefNameDecl we create the Decl first and only
9846 // then we import and set its DeclContext. So, the DC might not be set
9847 // when we reach here.
9848 if (ToD->getDeclContext())
9849 SharedState->removeDeclFromLookup(ToD);
9850 ImportedFromDecls.erase(PosF);
9851 }
9852
9853 // FIXME: AST may contain remaining references to the failed object.
9854 // However, the ImportDeclErrors in the shared state contains all the
9855 // failed objects together with their error.
9856 }
9857
9858 // Error encountered for the first time.
9859 // After takeError the error is not usable any more in ToDOrErr.
9860 // Get a copy of the error object (any more simple solution for this?).
9861 ASTImportError ErrOut;
9862 handleAllErrors(ToDOrErr.takeError(),
9863 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9864 setImportDeclError(FromD, ErrOut);
9865 // Set the error for the mapped to Decl, which is in the "to" context.
9866 if (ToDWasCreated)
9867 SharedState->setImportDeclError(CreatedToD, ErrOut);
9868
9869 // Set the error for all nodes which have been created before we
9870 // recognized the error.
9871 for (const auto &Path : SavedImportPaths[FromD]) {
9872 // The import path contains import-dependency nodes first.
9873 // Save the node that was imported as dependency of the current node.
9874 Decl *PrevFromDi = FromD;
9875 for (Decl *FromDi : Path) {
9876 // Begin and end of the path equals 'FromD', skip it.
9877 if (FromDi == FromD)
9878 continue;
9879 // We should not set import error on a node and all following nodes in
9880 // the path if child import errors are ignored.
9881 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9882 PrevFromDi))
9883 break;
9884 PrevFromDi = FromDi;
9885 setImportDeclError(FromDi, ErrOut);
9886
9887 if (const auto *FromTDi = dyn_cast<TagDecl>(FromDi)) {
9888 if (const Type *FromTyi =
9889 getFromContext().getCanonicalTagType(FromTDi).getTypePtr()) {
9890 ImportedTypes.erase(FromTyi);
9891 }
9892 }
9893
9894 //FIXME Should we remove these Decls from ImportedDecls?
9895 // Set the error for the mapped to Decl, which is in the "to" context.
9896 auto Ii = ImportedDecls.find(FromDi);
9897 if (Ii != ImportedDecls.end())
9898 SharedState->setImportDeclError(Ii->second, ErrOut);
9899 // FIXME Should we remove these Decls from the LookupTable,
9900 // and from ImportedFromDecls?
9901 }
9902 }
9903 SavedImportPaths.erase(FromD);
9904
9905 // Do not return ToDOrErr, error was taken out of it.
9906 return make_error<ASTImportError>(ErrOut);
9907 }
9908
9909 ToD = *ToDOrErr;
9910
9911 // FIXME: Handle the "already imported with error" case. We can get here
9912 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9913 // previously failed create was requested).
9914 // Later GetImportedOrCreateDecl can be updated to return the error.
9915 if (!ToD) {
9916 auto Err = getImportDeclErrorIfAny(FromD);
9917 assert(Err);
9918 return make_error<ASTImportError>(*Err);
9919 }
9920
9921 // We could import from the current TU without error. But previously we
9922 // already had imported a Decl as `ToD` from another TU (with another
9923 // ASTImporter object) and with an error.
9924 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9925 setImportDeclError(FromD, *Error);
9926 return make_error<ASTImportError>(*Error);
9927 }
9928 // Make sure that ImportImpl registered the imported decl.
9929 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9930
9931 if (FromD->hasAttrs())
9932 for (const Attr *FromAttr : FromD->getAttrs()) {
9933 auto ToAttrOrErr = Import(FromAttr);
9934 if (ToAttrOrErr)
9935 ToD->addAttr(*ToAttrOrErr);
9936 else
9937 return ToAttrOrErr.takeError();
9938 }
9939
9940 // Notify subclasses.
9941 Imported(FromD, ToD);
9942
9943 updateFlags(FromD, ToD);
9944 SavedImportPaths.erase(FromD);
9945 return ToDOrErr;
9946}
9947
9950 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9951}
9952
9954 if (!FromDC)
9955 return FromDC;
9956
9957 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9958 if (!ToDCOrErr)
9959 return ToDCOrErr.takeError();
9960 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9961
9962 // When we're using a record/enum/Objective-C class/protocol as a context, we
9963 // need it to have a definition.
9964 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9965 auto *FromRecord = cast<RecordDecl>(FromDC);
9966 if (ToRecord->isCompleteDefinition())
9967 return ToDC;
9968
9969 // If FromRecord is not defined we need to force it to be.
9970 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9971 // it will start the definition but we never finish it.
9972 // If there are base classes they won't be imported and we will
9973 // be missing anything that we inherit from those bases.
9974 if (FromRecord->getASTContext().getExternalSource() &&
9975 !FromRecord->isCompleteDefinition())
9976 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9977
9978 if (FromRecord->isCompleteDefinition())
9979 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9980 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9981 return std::move(Err);
9982 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9983 auto *FromEnum = cast<EnumDecl>(FromDC);
9984 if (ToEnum->isCompleteDefinition()) {
9985 // Do nothing.
9986 } else if (FromEnum->isCompleteDefinition()) {
9987 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9988 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9989 return std::move(Err);
9990 } else {
9991 CompleteDecl(ToEnum);
9992 }
9993 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9994 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9995 if (ToClass->getDefinition()) {
9996 // Do nothing.
9997 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9998 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9999 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10000 return std::move(Err);
10001 } else {
10002 CompleteDecl(ToClass);
10003 }
10004 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10005 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10006 if (ToProto->getDefinition()) {
10007 // Do nothing.
10008 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10009 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10010 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10011 return std::move(Err);
10012 } else {
10013 CompleteDecl(ToProto);
10014 }
10015 }
10016
10017 return ToDC;
10018}
10019
10021 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10022 return cast_or_null<Expr>(*ToSOrErr);
10023 else
10024 return ToSOrErr.takeError();
10025}
10026
10028 if (!FromS)
10029 return nullptr;
10030
10031 // Check whether we've already imported this statement.
10032 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10033 if (Pos != ImportedStmts.end())
10034 return Pos->second;
10035
10036 // Import the statement.
10037 ASTNodeImporter Importer(*this);
10038 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10039 if (!ToSOrErr)
10040 return ToSOrErr;
10041
10042 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10043 auto *FromE = cast<Expr>(FromS);
10044 // Copy ExprBitfields, which may not be handled in Expr subclasses
10045 // constructors.
10046 ToE->setValueKind(FromE->getValueKind());
10047 ToE->setObjectKind(FromE->getObjectKind());
10048 ToE->setDependence(FromE->getDependence());
10049 }
10050
10051 // Record the imported statement object.
10052 ImportedStmts[FromS] = *ToSOrErr;
10053 return ToSOrErr;
10054}
10055
10057 switch (FromNNS.getKind()) {
10060 return FromNNS;
10062 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10063 auto NSOrErr = Import(Namespace);
10064 if (!NSOrErr)
10065 return NSOrErr.takeError();
10066 auto PrefixOrErr = Import(Prefix);
10067 if (!PrefixOrErr)
10068 return PrefixOrErr.takeError();
10069 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10070 *PrefixOrErr);
10071 }
10073 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10074 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10075 else
10076 return RDOrErr.takeError();
10078 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10079 return NestedNameSpecifier(*TyOrErr);
10080 } else {
10081 return TyOrErr.takeError();
10082 }
10083 }
10084 llvm_unreachable("Invalid nested name specifier kind");
10085}
10086
10089 // Copied from NestedNameSpecifier mostly.
10091 NestedNameSpecifierLoc NNS = FromNNS;
10092
10093 // Push each of the nested-name-specifiers's onto a stack for
10094 // serialization in reverse order.
10095 while (NNS) {
10096 NestedNames.push_back(NNS);
10097 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10098 }
10099
10101
10102 while (!NestedNames.empty()) {
10103 NNS = NestedNames.pop_back_val();
10104 NestedNameSpecifier Spec = std::nullopt;
10105 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10106 return std::move(Err);
10107
10108 NestedNameSpecifier::Kind Kind = Spec.getKind();
10109
10110 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10112 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10113 return std::move(Err);
10114
10116 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10117 return std::move(Err);
10118 }
10119
10120 switch (Kind) {
10122 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10123 ToLocalBeginLoc, ToLocalEndLoc);
10124 break;
10125
10127 SourceLocation ToTLoc;
10128 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10129 return std::move(Err);
10131 QualType(Spec.getAsType(), 0), ToTLoc);
10132 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10133 break;
10134 }
10135
10137 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10138 break;
10139
10141 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10142 if (!ToSourceRangeOrErr)
10143 return ToSourceRangeOrErr.takeError();
10144
10145 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10146 ToSourceRangeOrErr->getBegin(),
10147 ToSourceRangeOrErr->getEnd());
10148 break;
10149 }
10151 llvm_unreachable("unexpected null nested name specifier");
10152 }
10153 }
10154
10155 return Builder.getWithLocInContext(getToContext());
10156}
10157
10159 switch (From.getKind()) {
10161 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10162 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10163 else
10164 return ToTemplateOrErr.takeError();
10165
10168 UnresolvedSet<2> ToTemplates;
10169 for (auto *I : *FromStorage) {
10170 if (auto ToOrErr = Import(I))
10171 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10172 else
10173 return ToOrErr.takeError();
10174 }
10175 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10176 ToTemplates.end());
10177 }
10178
10181 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10182 if (!DeclNameOrErr)
10183 return DeclNameOrErr.takeError();
10184 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10185 }
10186
10189 auto QualifierOrErr = Import(QTN->getQualifier());
10190 if (!QualifierOrErr)
10191 return QualifierOrErr.takeError();
10192 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10193 if (!TNOrErr)
10194 return TNOrErr.takeError();
10195 return ToContext.getQualifiedTemplateName(
10196 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10197 }
10198
10201 auto QualifierOrErr = Import(DTN->getQualifier());
10202 if (!QualifierOrErr)
10203 return QualifierOrErr.takeError();
10204 return ToContext.getDependentTemplateName(
10205 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10206 }
10207
10211 auto ReplacementOrErr = Import(Subst->getReplacement());
10212 if (!ReplacementOrErr)
10213 return ReplacementOrErr.takeError();
10214
10215 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10216 if (!AssociatedDeclOrErr)
10217 return AssociatedDeclOrErr.takeError();
10218
10219 return ToContext.getSubstTemplateTemplateParm(
10220 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10221 Subst->getPackIndex(), Subst->getFinal());
10222 }
10223
10227 ASTNodeImporter Importer(*this);
10228 auto ArgPackOrErr =
10229 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10230 if (!ArgPackOrErr)
10231 return ArgPackOrErr.takeError();
10232
10233 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10234 if (!AssociatedDeclOrErr)
10235 return AssociatedDeclOrErr.takeError();
10236
10237 return ToContext.getSubstTemplateTemplateParmPack(
10238 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10239 SubstPack->getFinal());
10240 }
10242 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10243 if (!UsingOrError)
10244 return UsingOrError.takeError();
10245 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10246 }
10248 llvm_unreachable("Unexpected DeducedTemplate");
10249 }
10250
10251 llvm_unreachable("Invalid template name kind");
10252}
10253
10255 if (FromLoc.isInvalid())
10256 return SourceLocation{};
10257
10258 SourceManager &FromSM = FromContext.getSourceManager();
10259 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10260
10261 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10262 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10263 if (!ToFileIDOrErr)
10264 return ToFileIDOrErr.takeError();
10265 SourceManager &ToSM = ToContext.getSourceManager();
10266 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10267}
10268
10270 SourceLocation ToBegin, ToEnd;
10271 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10272 return std::move(Err);
10273 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10274 return std::move(Err);
10275
10276 return SourceRange(ToBegin, ToEnd);
10277}
10278
10280 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10281 if (Pos != ImportedFileIDs.end())
10282 return Pos->second;
10283
10284 SourceManager &FromSM = FromContext.getSourceManager();
10285 SourceManager &ToSM = ToContext.getSourceManager();
10286 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10287
10288 // Map the FromID to the "to" source manager.
10289 FileID ToID;
10290 if (FromSLoc.isExpansion()) {
10291 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10292 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10293 if (!ToSpLoc)
10294 return ToSpLoc.takeError();
10295 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10296 if (!ToExLocS)
10297 return ToExLocS.takeError();
10298 unsigned ExLength = FromSM.getFileIDSize(FromID);
10299 SourceLocation MLoc;
10300 if (FromEx.isMacroArgExpansion()) {
10301 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10302 } else {
10303 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10304 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10305 FromEx.isExpansionTokenRange());
10306 else
10307 return ToExLocE.takeError();
10308 }
10309 ToID = ToSM.getFileID(MLoc);
10310 } else {
10311 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10312
10313 if (!IsBuiltin && !Cache->BufferOverridden) {
10314 // Include location of this file.
10315 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10316 if (!ToIncludeLoc)
10317 return ToIncludeLoc.takeError();
10318
10319 // Every FileID that is not the main FileID needs to have a valid include
10320 // location so that the include chain points to the main FileID. When
10321 // importing the main FileID (which has no include location), we need to
10322 // create a fake include location in the main file to keep this property
10323 // intact.
10324 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10325 if (FromID == FromSM.getMainFileID())
10326 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10327
10328 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10329 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10330 // the disk again
10331 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10332 // than mmap the files several times.
10333 auto Entry =
10334 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10335 // FIXME: The filename may be a virtual name that does probably not
10336 // point to a valid file and we get no Entry here. In this case try with
10337 // the memory buffer below.
10338 if (Entry)
10339 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10340 FromSLoc.getFile().getFileCharacteristic());
10341 }
10342 }
10343
10344 if (ToID.isInvalid() || IsBuiltin) {
10345 // FIXME: We want to re-use the existing MemoryBuffer!
10346 std::optional<llvm::MemoryBufferRef> FromBuf =
10347 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10348 FromSM.getFileManager(), SourceLocation{});
10349 if (!FromBuf)
10350 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10351
10352 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10353 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10354 FromBuf->getBufferIdentifier());
10355 ToID = ToSM.createFileID(std::move(ToBuf),
10356 FromSLoc.getFile().getFileCharacteristic());
10357 }
10358 }
10359
10360 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10361
10362 ImportedFileIDs[FromID] = ToID;
10363 return ToID;
10364}
10365
10367 ExpectedExpr ToExprOrErr = Import(From->getInit());
10368 if (!ToExprOrErr)
10369 return ToExprOrErr.takeError();
10370
10371 auto LParenLocOrErr = Import(From->getLParenLoc());
10372 if (!LParenLocOrErr)
10373 return LParenLocOrErr.takeError();
10374
10375 auto RParenLocOrErr = Import(From->getRParenLoc());
10376 if (!RParenLocOrErr)
10377 return RParenLocOrErr.takeError();
10378
10379 if (From->isBaseInitializer()) {
10380 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10381 if (!ToTInfoOrErr)
10382 return ToTInfoOrErr.takeError();
10383
10384 SourceLocation EllipsisLoc;
10385 if (From->isPackExpansion())
10386 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10387 return std::move(Err);
10388
10389 return new (ToContext) CXXCtorInitializer(
10390 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10391 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10392 } else if (From->isMemberInitializer()) {
10393 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10394 if (!ToFieldOrErr)
10395 return ToFieldOrErr.takeError();
10396
10397 auto MemberLocOrErr = Import(From->getMemberLocation());
10398 if (!MemberLocOrErr)
10399 return MemberLocOrErr.takeError();
10400
10401 return new (ToContext) CXXCtorInitializer(
10402 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10403 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10404 } else if (From->isIndirectMemberInitializer()) {
10405 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10406 if (!ToIFieldOrErr)
10407 return ToIFieldOrErr.takeError();
10408
10409 auto MemberLocOrErr = Import(From->getMemberLocation());
10410 if (!MemberLocOrErr)
10411 return MemberLocOrErr.takeError();
10412
10413 return new (ToContext) CXXCtorInitializer(
10414 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10415 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10416 } else if (From->isDelegatingInitializer()) {
10417 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10418 if (!ToTInfoOrErr)
10419 return ToTInfoOrErr.takeError();
10420
10421 return new (ToContext)
10422 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10423 *ToExprOrErr, *RParenLocOrErr);
10424 } else {
10425 // FIXME: assert?
10426 return make_error<ASTImportError>();
10427 }
10428}
10429
10432 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10433 if (Pos != ImportedCXXBaseSpecifiers.end())
10434 return Pos->second;
10435
10436 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10437 if (!ToSourceRange)
10438 return ToSourceRange.takeError();
10440 if (!ToTSI)
10441 return ToTSI.takeError();
10442 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10443 if (!ToEllipsisLoc)
10444 return ToEllipsisLoc.takeError();
10445 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10446 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10447 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10448 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10449 return Imported;
10450}
10451
10453 ASTNodeImporter Importer(*this);
10454 return Importer.ImportAPValue(FromValue);
10455}
10456
10458 ExpectedDecl ToOrErr = Import(From);
10459 if (!ToOrErr)
10460 return ToOrErr.takeError();
10461 Decl *To = *ToOrErr;
10462
10463 auto *FromDC = cast<DeclContext>(From);
10464 ASTNodeImporter Importer(*this);
10465
10466 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10467 if (!ToRecord->getDefinition()) {
10468 return Importer.ImportDefinition(
10469 cast<RecordDecl>(FromDC), ToRecord,
10471 }
10472 }
10473
10474 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10475 if (!ToEnum->getDefinition()) {
10476 return Importer.ImportDefinition(
10478 }
10479 }
10480
10481 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10482 if (!ToIFace->getDefinition()) {
10483 return Importer.ImportDefinition(
10484 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10486 }
10487 }
10488
10489 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10490 if (!ToProto->getDefinition()) {
10491 return Importer.ImportDefinition(
10492 cast<ObjCProtocolDecl>(FromDC), ToProto,
10494 }
10495 }
10496
10497 return Importer.ImportDeclContext(FromDC, true);
10498}
10499
10501 if (!FromName)
10502 return DeclarationName{};
10503
10504 switch (FromName.getNameKind()) {
10506 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10507
10511 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10512 return DeclarationName(*ToSelOrErr);
10513 else
10514 return ToSelOrErr.takeError();
10515
10517 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10518 return ToContext.DeclarationNames.getCXXConstructorName(
10519 ToContext.getCanonicalType(*ToTyOrErr));
10520 else
10521 return ToTyOrErr.takeError();
10522 }
10523
10525 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10526 return ToContext.DeclarationNames.getCXXDestructorName(
10527 ToContext.getCanonicalType(*ToTyOrErr));
10528 else
10529 return ToTyOrErr.takeError();
10530 }
10531
10533 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10534 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10535 cast<TemplateDecl>(*ToTemplateOrErr));
10536 else
10537 return ToTemplateOrErr.takeError();
10538 }
10539
10541 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10542 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10543 ToContext.getCanonicalType(*ToTyOrErr));
10544 else
10545 return ToTyOrErr.takeError();
10546 }
10547
10549 return ToContext.DeclarationNames.getCXXOperatorName(
10550 FromName.getCXXOverloadedOperator());
10551
10553 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10554 Import(FromName.getCXXLiteralIdentifier()));
10555
10557 // FIXME: STATICS!
10559 }
10560
10561 llvm_unreachable("Invalid DeclarationName Kind!");
10562}
10563
10565 if (!FromId)
10566 return nullptr;
10567
10568 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10569
10570 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10571 ToId->setBuiltinID(FromId->getBuiltinID());
10572
10573 return ToId;
10574}
10575
10578 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10579 return Import(FromII);
10580 return FromIO.getOperator();
10581}
10582
10584 if (FromSel.isNull())
10585 return Selector{};
10586
10588 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10589 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10590 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10591 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10592}
10593
10597 llvm::Error Err = llvm::Error::success();
10598 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10599 for (unsigned Idx = 0; Idx < Size; Idx++) {
10600 APValue Tmp = importChecked(Err, From[Idx]);
10601 To[Idx] = Tmp;
10602 }
10603 };
10604 switch (FromValue.getKind()) {
10605 case APValue::None:
10607 case APValue::Int:
10608 case APValue::Float:
10612 Result = FromValue;
10613 break;
10614 case APValue::Vector: {
10615 Result.MakeVector();
10617 Result.setVectorUninit(FromValue.getVectorLength());
10618 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10619 Elts.data(), FromValue.getVectorLength());
10620 break;
10621 }
10622 case APValue::Matrix:
10623 // Matrix values cannot currently arise in APValue import contexts.
10624 llvm_unreachable("Matrix APValue import not yet supported");
10625 case APValue::Array:
10626 Result.MakeArray(FromValue.getArrayInitializedElts(),
10627 FromValue.getArraySize());
10628 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10629 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10630 FromValue.getArrayInitializedElts());
10631 break;
10632 case APValue::Struct:
10633 Result.MakeStruct(FromValue.getStructNumBases(),
10634 FromValue.getStructNumFields(),
10635 FromValue.getStructNumVirtualBases());
10636 ImportLoop(
10637 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10638 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10639 FromValue.getStructNumBases() + FromValue.getStructNumFields() +
10640 FromValue.getStructNumVirtualBases());
10641 break;
10642 case APValue::Union: {
10643 Result.MakeUnion();
10644 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10645 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10646 if (Err)
10647 return std::move(Err);
10648 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10649 break;
10650 }
10652 Result.MakeAddrLabelDiff();
10653 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10654 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10655 if (Err)
10656 return std::move(Err);
10657 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10658 cast<AddrLabelExpr>(ImpRHS));
10659 break;
10660 }
10662 const Decl *ImpMemPtrDecl =
10663 importChecked(Err, FromValue.getMemberPointerDecl());
10664 if (Err)
10665 return std::move(Err);
10667 Result.setMemberPointerUninit(
10668 cast<const ValueDecl>(ImpMemPtrDecl),
10670 FromValue.getMemberPointerPath().size());
10671 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10672 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10673 Idx++) {
10674 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10675 if (Err)
10676 return std::move(Err);
10677 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10678 }
10679 break;
10680 }
10681 case APValue::LValue:
10683 QualType FromElemTy;
10684 if (FromValue.getLValueBase()) {
10685 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10686 "in C++20 dynamic allocation are transient so they shouldn't "
10687 "appear in the AST");
10688 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10689 if (const auto *E =
10690 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10691 FromElemTy = E->getType();
10692 const Expr *ImpExpr = importChecked(Err, E);
10693 if (Err)
10694 return std::move(Err);
10695 Base = APValue::LValueBase(ImpExpr,
10696 FromValue.getLValueBase().getCallIndex(),
10697 FromValue.getLValueBase().getVersion());
10698 } else {
10699 FromElemTy =
10700 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10701 const Decl *ImpDecl = importChecked(
10702 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10703 if (Err)
10704 return std::move(Err);
10706 FromValue.getLValueBase().getCallIndex(),
10707 FromValue.getLValueBase().getVersion());
10708 }
10709 } else {
10710 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10711 const Type *ImpTypeInfo = importChecked(
10712 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10713 QualType ImpType =
10714 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10715 if (Err)
10716 return std::move(Err);
10718 ImpType);
10719 }
10720 }
10721 CharUnits Offset = FromValue.getLValueOffset();
10722 unsigned PathLength = FromValue.getLValuePath().size();
10723 Result.MakeLValue();
10724 if (FromValue.hasLValuePath()) {
10725 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10726 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10727 FromValue.isNullPointer());
10729 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10730 if (FromElemTy->isRecordType()) {
10731 const Decl *FromDecl =
10732 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10733 const Decl *ImpDecl = importChecked(Err, FromDecl);
10734 if (Err)
10735 return std::move(Err);
10736 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10737 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10738 else
10739 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10741 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10742 } else {
10743 FromElemTy =
10744 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10745 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10746 FromPath[LoopIdx].getAsArrayIndex());
10747 }
10748 }
10749 } else
10750 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10751 FromValue.isNullPointer());
10752 }
10753 if (Err)
10754 return std::move(Err);
10755 return Result;
10756}
10757
10759 DeclContext *DC,
10760 unsigned IDNS,
10761 NamedDecl **Decls,
10762 unsigned NumDecls) {
10763 if (ODRHandling == ODRHandlingType::Conservative)
10764 // Report error at any name conflict.
10765 return make_error<ASTImportError>(ASTImportError::NameConflict);
10766 else
10767 // Allow to create the new Decl with the same name.
10768 return Name;
10769}
10770
10772 if (LastDiagFromFrom)
10773 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10774 FromContext.getDiagnostics());
10775 LastDiagFromFrom = false;
10776 return ToContext.getDiagnostics().Report(Loc, DiagID);
10777}
10778
10780 if (!LastDiagFromFrom)
10781 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10782 ToContext.getDiagnostics());
10783 LastDiagFromFrom = true;
10784 return FromContext.getDiagnostics().Report(Loc, DiagID);
10785}
10786
10788 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10789 if (!ID->getDefinition())
10790 ID->startDefinition();
10791 }
10792 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10793 if (!PD->getDefinition())
10794 PD->startDefinition();
10795 }
10796 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10797 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10798 TD->startDefinition();
10799 TD->setCompleteDefinition(true);
10800 }
10801 }
10802 else {
10803 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10804 }
10805}
10806
10808 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10809 assert((Inserted || Pos->second == To) &&
10810 "Try to import an already imported Decl");
10811 if (!Inserted)
10812 return Pos->second;
10813 // This mapping should be maintained only in this function. Therefore do not
10814 // check for additional consistency.
10815 ImportedFromDecls[To] = From;
10816 // In the case of TypedefNameDecl we create the Decl first and only then we
10817 // import and set its DeclContext. So, the DC is still not set when we reach
10818 // here from GetImportedOrCreateDecl.
10819 if (To->getDeclContext())
10820 AddToLookupTable(To);
10821 return To;
10822}
10823
10824std::optional<ASTImportError>
10826 auto Pos = ImportDeclErrors.find(FromD);
10827 if (Pos != ImportDeclErrors.end())
10828 return Pos->second;
10829 else
10830 return std::nullopt;
10831}
10832
10834 auto InsertRes = ImportDeclErrors.insert({From, Error});
10835 (void)InsertRes;
10836 // Either we set the error for the first time, or we already had set one and
10837 // now we want to set the same error.
10838 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10839}
10840
10842 bool Complain) {
10843 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10844 ImportedTypes.find(From.getTypePtr());
10845 if (Pos != ImportedTypes.end()) {
10846 if (ExpectedType ToFromOrErr = Import(From)) {
10847 if (ToContext.hasSameType(*ToFromOrErr, To))
10848 return true;
10849 } else {
10850 llvm::consumeError(ToFromOrErr.takeError());
10851 }
10852 }
10853
10855 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10856 getStructuralEquivalenceKind(*this), false, Complain);
10857 return Ctx.IsEquivalent(From, To);
10858}
Defines the clang::ASTContext interface.
#define V(N, I)
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static ExpectedStmt ImportLoopControlStmt(ASTNodeImporter &NodeImporter, ASTImporter &Importer, StmtClass *S)
static auto getTemplateDefinition(T *D) -> T *
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::FileManager interface and associated types.
TokenType getType() const
Returns the token's type, e.g.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Result
Implement __builtin_bit_cast and related operations.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the Objective-C statement AST node classes.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
llvm::APInt getValue() const
unsigned getVersion() const
Definition APValue.cpp:113
QualType getTypeInfoType() const
Definition APValue.cpp:117
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition APValue.cpp:55
unsigned getCallIndex() const
Definition APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition APValue.h:208
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition APValue.h:216
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
const LValueBase getLValueBase() const
Definition APValue.cpp:1020
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1040
const FieldDecl * getUnionField() const
Definition APValue.h:695
unsigned getStructNumFields() const
Definition APValue.h:661
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition APValue.h:205
ValueKind getKind() const
Definition APValue.h:482
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:1025
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1110
unsigned getArrayInitializedElts() const
Definition APValue.h:648
unsigned getStructNumBases() const
Definition APValue.h:657
unsigned getStructNumVirtualBases() const
Definition APValue.h:665
bool hasLValuePath() const
Definition APValue.cpp:1035
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1103
APValue & getUnionValue()
Definition APValue.h:699
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:715
CharUnits & getLValueOffset()
Definition APValue.cpp:1030
unsigned getVectorLength() const
Definition APValue.h:593
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1117
unsigned getArraySize() const
Definition APValue.h:652
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:129
bool isNullPointer() const
Definition APValue.cpp:1056
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:711
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
Definition ASTContext.h:980
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
std::string toString() const
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition ASTImporter.h:62
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
static UnsignedOrNone getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
friend class ASTNodeImporter
Definition ASTImporter.h:63
llvm::Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition ASTImporter.h:65
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedStmt VisitCXXExpansionSelectExpr(CXXExpansionSelectExpr *E)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedStmt VisitCXXExpansionStmtPattern(CXXExpansionStmtPattern *S)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
StringRef ImportASTStringRef(StringRef FromStr)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedDecl VisitRequiresExprBodyDecl(RequiresExprBodyDecl *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitRequiresExpr(RequiresExpr *E)
ExpectedDecl VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitPseudoObjectExpr(PseudoObjectExpr *E)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitConceptDecl(ConceptDecl *D)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
ExpectedDecl VisitCXXExpansionStmtDecl(CXXExpansionStmtDecl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
SmallVector< TemplateArgument, 8 > TemplateArgsTy
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedStmt VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedDecl VisitFileScopeAsmDecl(FileScopeAsmDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
Expected< concepts::Requirement * > ImportNestedRequirement(concepts::NestedRequirement *From)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedStmt VisitCXXExpansionStmtInstantiation(CXXExpansionStmtInstantiation *S)
ExpectedStmt VisitCXXParenListInitExpr(CXXParenListInitExpr *E)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
ASTNodeImporter(ASTImporter &Importer)
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitConceptSpecializationExpr(ConceptSpecializationExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
Expected< concepts::Requirement * > ImportExprRequirement(concepts::ExprRequirement *From)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
Error ImportConstraintSatisfaction(const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
Expected< concepts::Requirement * > ImportTypeRequirement(concepts::TypeRequirement *From)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedStmt VisitBreakStmt(BreakStmt *S)
DesignatedInitExpr::Designator Designator
ExpectedDecl VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D)
SourceLocation getColonLoc() const
Definition Expr.h:4392
SourceLocation getQuestionLoc() const
Definition Expr.h:4391
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:4561
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4576
SourceLocation getLabelLoc() const
Definition Expr.h:4578
LabelDecl * getLabel() const
Definition Expr.h:4584
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6038
Represents a loop initializing the elements of an array.
Definition Expr.h:5985
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:6000
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:6005
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2732
SourceLocation getRBracketLoc() const
Definition Expr.h:2780
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2761
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:2999
uint64_t getValue() const
Definition ExprCXX.h:3047
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3037
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3039
Expr * getDimensionExpression() const
Definition ExprCXX.h:3049
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3045
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3036
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3836
bool isVolatile() const
Definition Stmt.h:3322
outputs_range outputs()
Definition Stmt.h:3429
SourceLocation getAsmLoc() const
Definition Stmt.h:3316
inputs_range inputs()
Definition Stmt.h:3400
unsigned getNumClobbers() const
Definition Stmt.h:3377
unsigned getNumOutputs() const
Definition Stmt.h:3345
unsigned getNumInputs() const
Definition Stmt.h:3367
bool isSimple() const
Definition Stmt.h:3319
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:6945
Expr ** getSubExprs()
Definition Expr.h:7020
SourceLocation getRParenLoc() const
Definition Expr.h:7074
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5282
AtomicOp getOp() const
Definition Expr.h:7008
SourceLocation getBuiltinLoc() const
Definition Expr.h:7073
Attr - This represents one attribute.
Definition Attr.h:46
attr::Kind getKind() const
Definition Attr.h:92
void setPackExpansion(bool PE)
Definition Attr.h:108
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition Attr.h:106
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition Stmt.h:2212
Stmt * getSubStmt()
Definition Stmt.h:2248
SourceLocation getAttrLoc() const
Definition Stmt.h:2243
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2244
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition Stmt.cpp:441
Represents a C++ declaration that introduces decls from somewhere else.
Definition DeclCXX.h:3521
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3516
shadow_range shadows() const
Definition DeclCXX.h:3587
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4464
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4518
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4502
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4506
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4511
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4499
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4049
Expr * getLHS() const
Definition Expr.h:4099
SourceLocation getOperatorLoc() const
Definition Expr.h:4091
Expr * getRHS() const
Definition Expr.h:4101
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:5108
Opcode getOpcode() const
Definition Expr.h:4094
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4269
A binding in a decomposition declaration.
Definition DeclCXX.h:4210
void setDecomposedDecl(DecompositionDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4254
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4236
DecompositionDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4243
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:4248
BreakStmt - This represents a break.
Definition Stmt.h:3144
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5475
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:3241
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition Expr.cpp:2113
Represents a base class of a C++ class.
Definition DeclCXX.h:146
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition DeclCXX.h:242
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition DeclCXX.h:221
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition DeclCXX.h:203
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition DeclCXX.h:254
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the 'class' keyword (vs.
Definition DeclCXX.h:207
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition DeclCXX.h:193
Represents binding an expression to a temporary.
Definition ExprCXX.h:1496
CXXTemporary * getTemporary()
Definition ExprCXX.h:1514
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition ExprCXX.cpp:1125
const Expr * getSubExpr() const
Definition ExprCXX.h:1518
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:726
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition ExprCXX.h:738
bool getValue() const
Definition ExprCXX.h:743
SourceLocation getLocation() const
Definition ExprCXX.h:749
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:29
SourceLocation getCatchLoc() const
Definition StmtCXX.h:49
Stmt * getHandlerBlock() const
Definition StmtCXX.h:52
VarDecl * getExceptionDecl() const
Definition StmtCXX.h:50
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:899
Represents a call to a C++ constructor.
Definition ExprCXX.h:1551
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1732
void setIsImmediateEscalating(bool Set)
Definition ExprCXX.h:1713
bool isElidable() const
Whether this construction is elidable.
Definition ExprCXX.h:1620
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition ExprCXX.h:1625
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition ExprCXX.cpp:1187
arg_range arguments()
Definition ExprCXX.h:1675
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1644
bool isImmediateEscalating() const
Definition ExprCXX.h:1709
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition ExprCXX.h:1653
SourceLocation getLocation() const
Definition ExprCXX.h:1616
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1614
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1633
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1691
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1662
Represents a C++ constructor within a class.
Definition DeclCXX.h:2637
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2972
Represents a C++ base or member initializer.
Definition DeclCXX.h:2402
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2542
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2502
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2604
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2601
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2512
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2600
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2507
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2536
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2480
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2474
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2486
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2562
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2556
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2528
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1996
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2079
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1273
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition ExprCXX.h:1347
const ParmVarDecl * getParam() const
Definition ExprCXX.h:1315
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1343
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1046
bool hasRewrittenInit() const
Definition ExprCXX.h:1318
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1380
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Definition ExprCXX.cpp:1100
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1437
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition ExprCXX.h:1425
bool hasRewrittenInit() const
Definition ExprCXX.h:1409
FieldDecl * getField()
Get the field whose initializer will be used.
Definition ExprCXX.h:1414
SourceLocation getBeginLoc() const
Definition ExprCXX.h:1444
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2629
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2668
bool isArrayForm() const
Definition ExprCXX.h:2655
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2679
bool isGlobalDelete() const
Definition ExprCXX.h:2654
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2664
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2656
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3869
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:3968
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:3971
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition ExprCXX.cpp:1557
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:4023
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4015
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4002
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4042
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4011
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4031
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4007
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:3995
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:3959
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:3982
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:3951
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4070
Represents a C++ destructor within a class.
Definition DeclCXX.h:2902
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3172
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:813
Helper that selects an expression from an InitListExpr depending on the current expansion index.
Definition ExprCXX.h:5557
InitListExpr * getRangeExpr()
Definition ExprCXX.h:5567
Represents a C++26 expansion statement declaration.
CXXExpansionStmtPattern * getExpansionPattern()
CXXExpansionStmtInstantiation * getInstantiations()
void setInstantiations(CXXExpansionStmtInstantiation *S)
NonTypeTemplateParmDecl * getIndexTemplateParm()
void setExpansionPattern(CXXExpansionStmtPattern *S)
Represents the code generated for an expanded expansion statement.
Definition StmtCXX.h:1028
ArrayRef< Stmt * > getInstantiations() const
Definition StmtCXX.h:1069
bool shouldApplyLifetimeExtensionToPreamble() const
Definition StmtCXX.h:1077
CXXExpansionStmtDecl * getParent()
Definition StmtCXX.h:1088
ArrayRef< Stmt * > getPreambleStmts() const
Definition StmtCXX.h:1073
static CXXExpansionStmtInstantiation * Create(ASTContext &C, CXXExpansionStmtDecl *Parent, ArrayRef< Stmt * > Instantiations, ArrayRef< Stmt * > PreambleStmts, bool ShouldApplyLifetimeExtensionToPreamble)
Definition StmtCXX.cpp:261
CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement.
Definition StmtCXX.h:675
ExpansionStmtKind getKind() const
Definition StmtCXX.h:774
static CXXExpansionStmtPattern * CreateIterating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, DeclStmt *Range, DeclStmt *Begin, DeclStmt *Iter, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create an iterating expansion statement pattern.
Definition StmtCXX.cpp:194
const DeclStmt * getIterVarStmt() const
Definition StmtCXX.h:865
DeclStmt * getExpansionVarStmt()
Definition StmtCXX.h:803
static CXXExpansionStmtPattern * CreateDependent(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, Expr *ExpansionInitializer, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create a dependent expansion statement pattern.
Definition StmtCXX.cpp:155
SourceLocation getRParenLoc() const
Definition StmtCXX.h:768
static CXXExpansionStmtPattern * CreateDestructuring(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, Stmt *DecompositionDeclStmt, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create a destructuring expansion statement pattern.
Definition StmtCXX.cpp:167
const DeclStmt * getBeginVarStmt() const
Definition StmtCXX.h:840
SourceLocation getColonLoc() const
Definition StmtCXX.h:767
const DeclStmt * getRangeVarStmt() const
Definition StmtCXX.h:815
CXXExpansionStmtDecl * getDecl()
Definition StmtCXX.h:791
static CXXExpansionStmtPattern * CreateEnumerating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create an enumerating expansion statement pattern.
Definition StmtCXX.cpp:185
SourceLocation getLParenLoc() const
Definition StmtCXX.h:766
Represents a folding of a pack over an operator.
Definition ExprCXX.h:5031
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5053
Expr * getRHS() const
Definition ExprCXX.h:5057
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5073
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5075
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5078
Expr * getLHS() const
Definition ExprCXX.h:5056
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5074
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5076
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:136
DeclStmt * getBeginStmt()
Definition StmtCXX.h:164
DeclStmt * getLoopVarStmt()
Definition StmtCXX.h:170
DeclStmt * getEndStmt()
Definition StmtCXX.h:167
SourceLocation getForLoc() const
Definition StmtCXX.h:203
DeclStmt * getRangeStmt()
Definition StmtCXX.h:163
SourceLocation getRParenLoc() const
Definition StmtCXX.h:206
SourceLocation getColonLoc() const
Definition StmtCXX.h:205
SourceLocation getCoawaitLoc() const
Definition StmtCXX.h:204
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, SourceLocation RPLoc)
Definition ExprCXX.cpp:925
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1754
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1795
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1791
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1807
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1805
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:182
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition ExprCXX.cpp:699
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2805
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2828
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2258
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:378
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:409
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:416
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:412
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2358
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, const ImplicitAllocationParameters &IAP, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition ExprCXX.cpp:298
SourceRange getDirectInitRange() const
Definition ExprCXX.h:2612
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2575
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:2472
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2530
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2565
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2464
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2497
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2441
SourceRange getSourceRange() const
Definition ExprCXX.h:2613
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2519
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2559
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2462
bool isGlobalNew() const
Definition ExprCXX.h:2524
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2536
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4308
bool getValue() const
Definition ExprCXX.h:4331
SourceLocation getEndLoc() const
Definition ExprCXX.h:4328
Expr * getOperand() const
Definition ExprCXX.h:4325
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4327
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:771
SourceLocation getLocation() const
Definition ExprCXX.h:785
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL, bool IsReversed=false)
Definition ExprCXX.cpp:629
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5140
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Definition ExprCXX.cpp:1997
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5196
SourceLocation getInitLoc() const LLVM_READONLY
Definition ExprCXX.h:5198
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5180
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5194
MutableArrayRef< Expr * > getUserSpecifiedInitExprs()
Definition ExprCXX.h:5186
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2748
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2842
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2812
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2826
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2833
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2801
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2857
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2830
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2815
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:2849
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition DeclCXX.h:539
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition DeclCXX.cpp:2032
method_range methods() const
Definition DeclCXX.h:650
CXXRecordDecl * getDefinition() const
Definition DeclCXX.h:548
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition DeclCXX.cpp:142
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition DeclCXX.cpp:2062
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2045
void setLambdaContextDecl(Decl *ContextDecl)
Set the context declaration for a lambda class.
Definition DeclCXX.cpp:1842
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2058
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers for a lambda class.
Definition DeclCXX.cpp:1847
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition DeclCXX.cpp:2039
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2073
CXXRecordDecl * getPreviousDecl()
Definition DeclCXX.h:530
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:877
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:289
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:307
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition ExprCXX.h:325
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2199
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2218
SourceLocation getRParenLoc() const
Definition ExprCXX.h:2222
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:787
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:803
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1902
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition ExprCXX.cpp:1153
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:1931
Represents a C++ temporary.
Definition ExprCXX.h:1462
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition ExprCXX.cpp:1120
Represents the this expression in C++.
Definition ExprCXX.h:1157
bool isImplicit() const
Definition ExprCXX.h:1180
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition ExprCXX.cpp:1592
SourceLocation getLocation() const
Definition ExprCXX.h:1174
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1211
const Expr * getSubExpr() const
Definition ExprCXX.h:1231
SourceLocation getThrowLoc() const
Definition ExprCXX.h:1234
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition ExprCXX.h:1241
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:70
SourceLocation getTryLoc() const
Definition StmtCXX.h:96
CXXCatchStmt * getHandler(unsigned i)
Definition StmtCXX.h:109
unsigned getNumHandlers() const
Definition StmtCXX.h:108
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition StmtCXX.cpp:26
CompoundStmt * getTryBlock()
Definition StmtCXX.h:101
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:851
bool isTypeOperand() const
Definition ExprCXX.h:887
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition ExprCXX.h:894
Expr * getExprOperand() const
Definition ExprCXX.h:898
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:905
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3743
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3787
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3798
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition ExprCXX.cpp:1495
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3781
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3792
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3801
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2954
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1523
ADLCallKind getADLCallKind() const
Definition Expr.h:3105
Expr * getCallee()
Definition Expr.h:3101
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3253
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3145
arg_range arguments()
Definition Expr.h:3206
SourceLocation getRParenLoc() const
Definition Expr.h:3285
CaseStmt - Represent a case statement.
Definition Stmt.h:1929
Stmt * getSubStmt()
Definition Stmt.h:2042
Expr * getLHS()
Definition Stmt.h:2012
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:1998
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition Stmt.cpp:1306
SourceLocation getCaseLoc() const
Definition Stmt.h:1994
Expr * getRHS()
Definition Stmt.h:2024
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3687
path_iterator path_begin()
Definition Expr.h:3757
CastKind getCastKind() const
Definition Expr.h:3731
path_iterator path_end()
Definition Expr.h:3758
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3807
Expr * getSubExpr()
Definition Expr.h:3737
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1632
unsigned getValue() const
Definition Expr.h:1640
CharacterLiteralKind getKind() const
Definition Expr.h:1633
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:4859
SourceLocation getBuiltinLoc() const
Definition Expr.h:4906
Expr * getLHS() const
Definition Expr.h:4901
bool isConditionDependent() const
Definition Expr.h:4889
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4882
Expr * getRHS() const
Definition Expr.h:4903
SourceLocation getRParenLoc() const
Definition Expr.h:4909
Expr * getCond() const
Definition Expr.h:4899
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4311
QualType getComputationLHSType() const
Definition Expr.h:4345
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:5130
QualType getComputationResultType() const
Definition Expr.h:4348
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3616
SourceLocation getLParenLoc() const
Definition Expr.h:3651
bool isFileScope() const
Definition Expr.h:3648
const Expr * getInitializer() const
Definition Expr.h:3644
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3654
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1749
unsigned size() const
Definition Stmt.h:1794
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1799
body_range body()
Definition Stmt.h:1812
SourceLocation getLBracLoc() const
Definition Stmt.h:1866
bool hasStoredFPFeatures() const
Definition Stmt.h:1796
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition Stmt.cpp:399
SourceLocation getRBracLoc() const
Definition Stmt.h:1867
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
A reference to a concept and its template args, as it appears in the code.
Definition ASTConcept.h:130
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ASTConcept.h:170
NamedDecl * getFoundDecl() const
Definition ASTConcept.h:197
const DeclarationNameInfo & getConceptNameInfo() const
Definition ASTConcept.h:174
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:203
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
TemplateDecl * getNamedConcept() const
Definition ASTConcept.h:201
SourceLocation getTemplateKWLoc() const
Definition ASTConcept.h:180
Represents the specialization of a concept - evaluates to a prvalue of type bool.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
ConceptReference * getConceptReference() const
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
ConditionalOperator - The ?
Definition Expr.h:4402
Expr * getLHS() const
Definition Expr.h:4436
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4425
Expr * getRHS() const
Definition Expr.h:4437
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1093
APValue getAPValueResult() const
Definition Expr.cpp:419
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:356
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:47
llvm::SmallVector< UnsatisfiedConstraintRecord, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition ASTConcept.h:67
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition DeclCXX.h:3702
ContinueStmt - This represents a continue.
Definition Stmt.h:3128
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4730
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4798
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4834
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:5695
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4831
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4823
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4820
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
AccessSpecifier getAccess() const
The results of name lookup within a DeclContext.
Definition DeclBase.h:1399
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h:2607
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2219
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isRecord() const
Definition DeclBase.h:2206
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
void removeDecl(Decl *D)
Removes a declaration from this context.
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition DeclBase.h:2718
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition DeclBase.h:2403
bool isFunctionOrMethod() const
Definition DeclBase.h:2178
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition DeclGroup.h:64
iterator begin()
Definition DeclGroup.h:95
bool isNull() const
Definition DeclGroup.h:75
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1281
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1392
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1436
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1485
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1408
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition Expr.cpp:494
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1416
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1374
ValueDecl * getDecl()
Definition Expr.h:1349
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1462
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1479
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1468
SourceLocation getLocation() const
Definition Expr.h:1357
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1424
bool isImmediateEscalating() const
Definition Expr.h:1489
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1640
SourceLocation getEndLoc() const
Definition Stmt.h:1663
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1658
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1666
A simple visitor class that helps create declaration visitors.
Definition DeclVisitor.h:68
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:443
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition DeclBase.cpp:285
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition DeclBase.h:1243
bool hasAttrs() const
Definition DeclBase.h:526
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
void addAttr(Attr *A)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:601
@ FOK_None
Not a friend object.
Definition DeclBase.h:1234
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition DeclBase.h:1197
void setAccess(AccessSpecifier AS)
Definition DeclBase.h:510
SourceLocation getLocation() const
Definition DeclBase.h:447
const char * getDeclKindName() const
Definition DeclBase.cpp:169
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
void setImplicit(bool I=true)
Definition DeclBase.h:602
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition DeclBase.h:616
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:579
DeclContext * getDeclContext()
Definition DeclBase.h:456
AccessSpecifier getAccess() const
Definition DeclBase.h:515
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:443
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:439
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:535
AttrVec & getAttrs()
Definition DeclBase.h:532
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:385
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:935
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:389
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:995
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:831
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:814
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2017
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:845
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
A decomposition declaration.
Definition DeclCXX.h:4274
SourceLocation getDefaultLoc() const
Definition Stmt.h:2094
Stmt * getSubStmt()
Definition Stmt.h:2090
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3509
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition ExprCXX.cpp:549
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3583
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3557
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3575
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3617
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3593
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3567
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3548
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3545
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:5611
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5738
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5692
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5728
SourceLocation getFieldLoc() const
Definition Expr.h:5719
SourceLocation getRBracketLoc() const
Definition Expr.h:5767
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4799
SourceLocation getEllipsisLoc() const
Definition Expr.h:5761
SourceLocation getDotLoc() const
Definition Expr.h:5714
SourceLocation getLBracketLoc() const
Definition Expr.h:5755
Represents a C99 designated initializer expression.
Definition Expr.h:5568
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5850
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5832
MutableArrayRef< Designator > designators()
Definition Expr.h:5801
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5836
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5798
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5823
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5848
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4840
A little helper class used to produce diagnostics.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2841
Stmt * getBody()
Definition Stmt.h:2866
Expr * getCond()
Definition Stmt.h:2859
SourceLocation getWhileLoc() const
Definition Stmt.h:2872
SourceLocation getDoLoc() const
Definition Stmt.h:2870
SourceLocation getRParenLoc() const
Definition Stmt.h:2874
Symbolic representation of a dynamic allocation.
Definition APValue.h:65
Represents an empty-declaration.
Definition Decl.h:5313
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3557
llvm::APSInt getInitVal() const
Definition Decl.h:3577
const Expr * getInitExpr() const
Definition Decl.h:3575
Represents an enum.
Definition Decl.h:4145
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4417
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4363
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4355
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4366
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4327
EnumDecl * getMostRecentDecl()
Definition Decl.h:4250
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4372
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5157
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4318
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5217
EnumDecl * getDefinition() const
Definition Decl.h:4257
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4344
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4310
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3939
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3961
Store information needed for an explicit specifier.
Definition DeclCXX.h:1944
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1952
const Expr * getExpr() const
Definition DeclCXX.h:1953
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3660
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3695
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3684
unsigned getNumObjects() const
Definition ExprCXX.h:3688
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3666
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition ExprCXX.cpp:1471
This represents one expression.
Definition Expr.h:112
void setType(QualType t)
Definition Expr.h:145
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:447
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:241
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:454
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:223
QualType getType() const
Definition Expr.h:144
ExprDependence getDependence() const
Definition Expr.h:164
An expression trait intrinsic.
Definition ExprCXX.h:3072
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3104
Expr * getQueriedExpression() const
Definition ExprCXX.h:3111
ExpressionTrait getTrait() const
Definition ExprCXX.h:3107
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3105
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:3294
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3394
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4788
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3474
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3468
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4798
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3410
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3518
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4898
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:52
SourceLocation getAsmLoc() const
Definition Decl.h:4747
const Expr * getAsmStringExpr() const
Definition Decl.h:4754
SourceLocation getRParenLoc() const
Definition Decl.h:4748
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1592
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1586
SourceLocation getLocation() const
Definition Expr.h:1718
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1082
llvm::APFloat getValue() const
Definition Expr.h:1677
bool isExact() const
Definition Expr.h:1710
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2897
Stmt * getInit()
Definition Stmt.h:2912
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getRParenLoc() const
Definition Stmt.h:2957
Stmt * getBody()
Definition Stmt.h:2941
Expr * getInc()
Definition Stmt.h:2940
SourceLocation getForLoc() const
Definition Stmt.h:2953
Expr * getCond()
Definition Stmt.h:2939
SourceLocation getLParenLoc() const
Definition Stmt.h:2955
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:1073
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, FPOptionsOverride FPFeatures, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3127
Represents a function declaration or definition.
Definition Decl.h:2058
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3267
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2602
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3182
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4241
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4236
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3341
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3148
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2831
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3594
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:3039
SourceLocation getDefaultLoc() const
Definition Decl.h:2524
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2904
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2515
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2503
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2574
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4215
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4366
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2528
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2439
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4432
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2074
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2077
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:3018
void setTrivial(bool IT)
Definition Decl.h:2504
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2837
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4187
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4254
bool isDeletedAsWritten() const
Definition Decl.h:2670
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:4421
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2479
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:2475
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3598
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3602
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3606
void setRangeEnd(SourceLocation E)
Definition Decl.h:2331
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2511
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4260
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4460
void setDefaulted(bool D=true)
Definition Decl.h:2512
void setBody(Stmt *B)
Definition Decl.cpp:3279
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2470
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3157
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2520
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4208
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2324
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3187
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:3029
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5421
QualType desugar() const
Definition TypeBase.h:6002
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5710
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5875
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5861
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:4973
QualType getReturnType() const
Definition TypeBase.h:4957
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3455
unsigned getNumLabels() const
Definition Stmt.h:3605
labels_range labels()
Definition Stmt.h:3628
SourceLocation getRParenLoc() const
Definition Stmt.h:3477
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3570
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3557
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3583
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3546
const Expr * getAsmStringExpr() const
Definition Stmt.h:3482
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3662
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4934
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4951
Represents a C11 generic selection.
Definition Expr.h:6199
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6476
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6496
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6457
SourceLocation getGenericLoc() const
Definition Expr.h:6554
SourceLocation getRParenLoc() const
Definition Expr.h:6558
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6446
SourceLocation getDefaultLoc() const
Definition Expr.h:6557
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:4729
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6453
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6464
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6501
GotoStmt - This represents a direct goto.
Definition Stmt.h:2978
SourceLocation getLabelLoc() const
Definition Stmt.h:2996
SourceLocation getGotoLoc() const
Definition Stmt.h:2994
LabelDecl * getLabel() const
Definition Stmt.h:2991
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:2268
Stmt * getThen()
Definition Stmt.h:2357
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition Stmt.cpp:1044
SourceLocation getIfLoc() const
Definition Stmt.h:2434
IfStatementKind getStatementKind() const
Definition Stmt.h:2469
SourceLocation getElseLoc() const
Definition Stmt.h:2437
Stmt * getInit()
Definition Stmt.h:2418
SourceLocation getLParenLoc() const
Definition Stmt.h:2486
Expr * getCond()
Definition Stmt.h:2345
Stmt * getElse()
Definition Stmt.h:2366
SourceLocation getRParenLoc() const
Definition Stmt.h:2488
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1742
const Expr * getSubExpr() const
Definition Expr.h:1754
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3864
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2081
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1809
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6074
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5187
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3601
unsigned getChainingSize() const
Definition Decl.h:3626
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3622
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3017
SourceLocation getGotoLoc() const
Definition Stmt.h:3033
SourceLocation getStarLoc() const
Definition Stmt.h:3035
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2608
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2621
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2620
Describes an C or C++ initializer list.
Definition Expr.h:5319
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5432
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5493
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5446
unsigned getNumInits() const
Definition Expr.h:5352
SourceLocation getLBraceLoc() const
Definition Expr.h:5477
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2449
InitListExpr * getSyntacticForm() const
Definition Expr.h:5489
bool hadArrayRangeDesignator() const
Definition Expr.h:5500
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5422
bool isExplicit() const
Definition Expr.h:5462
SourceLocation getRBraceLoc() const
Definition Expr.h:5479
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5452
ArrayRef< Expr * > inits() const
Definition Expr.h:5372
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5503
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:981
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1547
Represents the declaration of a label.
Definition Decl.h:524
bool isGnuLocal() const
Definition Decl.h:551
LabelStmt * getStmt() const
Definition Decl.h:548
void setStmt(LabelStmt *T)
Definition Decl.h:549
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2155
LabelDecl * getDecl() const
Definition Stmt.h:2173
Stmt * getSubStmt()
Definition Stmt.h:2177
SourceLocation getIdentLoc() const
Definition Stmt.h:2170
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool capturesVariable() const
Determine whether this capture handles a variable.
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition ExprCXX.cpp:1271
ValueDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
SourceLocation getLocation() const
Retrieve the source location of the capture.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1971
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition ExprCXX.cpp:1319
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2189
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition ExprCXX.h:2174
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition ExprCXX.h:2122
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2052
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition ExprCXX.cpp:1411
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition ExprCXX.h:2177
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition ExprCXX.h:2029
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2086
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition ExprCXX.h:2024
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1407
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition DeclCXX.h:3333
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3379
Represents a linkage specification.
Definition DeclCXX.h:3040
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3082
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3063
SourceLocation getExternLoc() const
Definition DeclCXX.h:3079
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3080
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3074
Represents the results of name lookup.
Definition Lookup.h:147
iterator end() const
Definition Lookup.h:359
iterator begin() const
Definition Lookup.h:358
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4919
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4936
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:4988
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:4959
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3375
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3547
SourceLocation getOperatorLoc() const
Definition Expr.h:3557
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3492
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3477
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3458
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3519
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3599
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition Expr.cpp:1758
Expr * getBase() const
Definition Expr.h:3452
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3508
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3500
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3552
bool isArrow() const
Definition Expr.h:3559
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3462
Provides information a specialization of a member of a class template, which may be a member function...
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
This represents a decl that may have a name.
Definition Decl.h:274
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1182
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents a C++ namespace alias.
Definition DeclCXX.h:3226
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3287
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3309
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3312
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3315
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3296
Represent a C++ namespace.
Definition Decl.h:592
SourceLocation getRBraceLoc() const
Definition Decl.h:692
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:691
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:675
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:657
void setRBraceLoc(SourceLocation L)
Definition Decl.h:694
Class that aids in the construction of nested-name-specifiers along with source-location information ...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1712
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1726
SourceLocation getSemiLoc() const
Definition Stmt.h:1723
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:1676
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2335
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:2397
ObjCCategoryImplDecl * getImplementation() const
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2378
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2383
protocol_iterator protocol_end() const
Definition DeclObjC.h:2417
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2420
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2470
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2472
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2427
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2413
void setImplementation(ObjCCategoryImplDecl *ImplD)
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2406
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2466
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2551
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2578
ObjCCategoryDecl * getCategoryDecl() const
SourceLocation getAtStartLoc() const
Definition DeclObjC.h:1102
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:2492
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2603
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2750
SourceLocation getSuperClassLoc() const
Definition DeclObjC.h:2743
const ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.h:2741
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2748
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
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:1491
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition DeclObjC.h:1899
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition DeclObjC.h:1309
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:1398
void setImplementation(ObjCImplementationDecl *ImplD)
known_categories_range known_categories() const
Definition DeclObjC.h:1693
void setSuperClass(TypeSourceInfo *superClass)
Definition DeclObjC.h:1594
protocol_iterator protocol_end() const
Definition DeclObjC.h:1380
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:1529
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition DeclObjC.cpp:340
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:1362
ObjCImplementationDecl * getImplementation() const
protocol_iterator protocol_begin() const
Definition DeclObjC.h:1369
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:1391
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:1921
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:1548
TypeSourceInfo * getSuperClassTInfo() const
Definition DeclObjC.h:1579
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1958
AccessControl getAccessControl() const
Definition DeclObjC.h:2006
bool getSynthesize() const
Definition DeclObjC.h:2013
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
ImplicitParamDecl * getSelfDecl() const
Definition DeclObjC.h:421
ArrayRef< ParmVarDecl * > parameters() const
Definition DeclObjC.h:376
unsigned param_size() const
Definition DeclObjC.h:350
bool isPropertyAccessor() const
Definition DeclObjC.h:439
param_const_iterator param_end() const
Definition DeclObjC.h:361
param_const_iterator param_begin() const
Definition DeclObjC.h:357
bool isVariadic() const
Definition DeclObjC.h:434
SourceLocation getEndLoc() const LLVM_READONLY
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition DeclObjC.h:346
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs={})
Sets the method's parameters and selector source locations.
Definition DeclObjC.cpp:962
bool isSynthesizedAccessorStub() const
Definition DeclObjC.h:447
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type.
Definition DeclObjC.h:259
bool isInstanceMethod() const
Definition DeclObjC.h:429
bool isDefined() const
Definition DeclObjC.h:455
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
QualType getReturnType() const
Definition DeclObjC.h:332
ParmVarDecl *const * param_iterator
Definition DeclObjC.h:353
ObjCImplementationControl getImplementationControl() const
Definition DeclObjC.h:503
ObjCInterfaceDecl * getClassInterface()
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition DeclObjC.cpp:956
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:734
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:902
SourceLocation getGetterNameLoc() const
Definition DeclObjC.h:892
ObjCMethodDecl * getGetterMethodDecl() const
Definition DeclObjC.h:907
bool isInstanceProperty() const
Definition DeclObjC.h:860
ObjCMethodDecl * getSetterMethodDecl() const
Definition DeclObjC.h:910
SourceLocation getSetterNameLoc() const
Definition DeclObjC.h:900
SourceLocation getAtLoc() const
Definition DeclObjC.h:802
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:825
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:930
Selector getSetterName() const
Definition DeclObjC.h:899
TypeSourceInfo * getTypeSourceInfo() const
Definition DeclObjC.h:808
QualType getType() const
Definition DeclObjC.h:810
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:837
Selector getGetterName() const
Definition DeclObjC.h:891
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition DeclObjC.h:926
SourceLocation getLParenLoc() const
Definition DeclObjC.h:805
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:911
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition DeclObjC.h:833
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition DeclObjC.h:821
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:894
PropertyControl getPropertyImplementation() const
Definition DeclObjC.h:918
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:908
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2811
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:2885
SourceLocation getPropertyIvarDeclLoc() const
Definition DeclObjC.h:2888
Kind getPropertyImplementation() const
Definition DeclObjC.h:2881
ObjCPropertyDecl * getPropertyDecl() const
Definition DeclObjC.h:2876
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclObjC.h:2873
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2090
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition DeclObjC.h:2267
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:2215
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition DeclObjC.h:2256
void startDefinition()
Starts the definition of this Objective-C protocol.
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2164
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2171
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2185
protocol_iterator protocol_end() const
Definition DeclObjC.h:2178
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2192
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:581
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition DeclObjC.h:639
const Type * getTypeForDecl() const
Definition Decl.h:3672
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition DeclObjC.h:647
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition DeclObjC.h:626
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition DeclObjC.h:636
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:665
SourceLocation getRAngleLoc() const
Definition DeclObjC.h:714
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:713
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2538
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2597
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2571
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2585
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1661
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2578
unsigned getNumExpressions() const
Definition Expr.h:2609
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2575
unsigned getNumComponents() const
Definition Expr.h:2593
Helper class for OffsetOfExpr.
Definition Expr.h:2432
const IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1696
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2490
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2496
@ Array
An index into an array.
Definition Expr.h:2437
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2441
@ Field
A field.
Definition Expr.h:2439
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2444
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2518
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2486
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2519
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2506
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1189
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1239
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1211
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3283
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3265
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3238
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3244
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3257
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3253
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3230
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition ExprCXX.h:3341
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3241
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3273
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3336
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:4362
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4391
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4402
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4398
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2193
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2218
const Expr * getSubExpr() const
Definition Expr.h:2210
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2222
ArrayRef< Expr * > exprs() const
Definition Expr.h:6144
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4980
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6127
SourceLocation getLParenLoc() const
Definition Expr.h:6146
SourceLocation getRParenLoc() const
Definition Expr.h:6147
Represents a parameter to a function.
Definition Decl.h:1819
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1900
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1879
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1887
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3009
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1915
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1960
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1948
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3034
bool isObjCMethodParameter() const
Definition Decl.h:1862
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1883
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1852
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1952
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1847
bool hasInheritedDefaultArg() const
Definition Decl.h:1964
void setKNRPromoted(bool promoted)
Definition Decl.h:1903
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1911
Expr * getDefaultArg()
Definition Decl.cpp:2997
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3039
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3045
unsigned getFunctionScopeDepth() const
Definition Decl.h:1869
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1968
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2016
SourceLocation getBeginLoc() const
Definition Expr.h:2081
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:639
bool isTransparent() const
Definition Expr.h:2055
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2051
StringLiteral * getFunctionName()
Definition Expr.h:2060
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2697
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6821
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6863
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5202
ArrayRef< Expr * > semantics()
Definition Expr.h:6893
unsigned getNumSemanticExprs() const
Definition Expr.h:6878
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6858
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8504
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8536
Represents a template name as written in source code.
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Represents a struct/union/class.
Definition Decl.h:4459
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5309
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4515
field_range fields() const
Definition Decl.h:4662
RecordDecl * getMostRecentDecl()
Definition Decl.h:4485
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5354
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4643
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4511
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:5464
Represents the body of a requires-expression.
Definition DeclCXX.h:2114
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
SourceLocation getRBraceLoc() const
SourceLocation getRequiresKWLoc() const
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
RequiresExprBodyDecl * getBody() const
ArrayRef< concepts::Requirement * > getRequirements() const
ArrayRef< ParmVarDecl * > getLocalParameters() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3169
SourceLocation getReturnLoc() const
Definition Stmt.h:3218
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3205
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition Stmt.cpp:1290
Expr * getRetValue()
Definition Stmt.h:3196
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:4654
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4690
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4687
SourceLocation getRParenLoc() const
Definition Expr.h:4674
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4677
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4440
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4502
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4525
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1715
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4530
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4499
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4505
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4508
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4514
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5037
SourceLocation getBeginLoc() const
Definition Expr.h:5082
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5078
SourceLocation getEndLoc() const
Definition Expr.h:5083
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5057
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:4161
bool isFailed() const
Definition DeclCXX.h:4190
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4192
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4606
CompoundStmt * getSubStmt()
Definition Expr.h:4623
unsigned getTemplateDepth() const
Definition Expr.h:4635
SourceLocation getRParenLoc() const
Definition Expr.h:4632
SourceLocation getLParenLoc() const
Definition Expr.h:4630
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:85
StmtClass getStmtClass() const
Definition Stmt.h:1502
const char * getStmtClassName() const
Definition Stmt.cpp:86
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1810
bool isPascal() const
Definition Expr.h:1933
tokloc_iterator tokloc_begin() const
Definition Expr.h:1976
tokloc_iterator tokloc_end() const
Definition Expr.h:1980
StringLiteralKind getKind() const
Definition Expr.h:1923
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
Definition Expr.cpp:1194
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1886
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1951
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4663
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4708
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4716
QualType getParameterType() const
Determine the substituted type of the template parameter.
Definition ExprCXX.h:4727
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4714
SourceLocation getNameLoc() const
Definition ExprCXX.h:4698
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4753
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition ExprCXX.cpp:1791
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
Definition ExprCXX.h:4801
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4787
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4791
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:1904
SourceLocation getColonLoc() const
Definition Stmt.h:1908
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1902
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2518
SourceLocation getSwitchLoc() const
Definition Stmt.h:2653
SourceLocation getLParenLoc() const
Definition Stmt.h:2655
SourceLocation getRParenLoc() const
Definition Stmt.h:2657
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition Stmt.cpp:1167
Expr * getCond()
Definition Stmt.h:2581
Stmt * getBody()
Definition Stmt.h:2593
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2598
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2649
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3851
SourceRange getBraceRange() const
Definition Decl.h:3928
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3972
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4992
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3947
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3952
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4105
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:4088
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4969
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4964
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:5006
TagKind getTagKind() const
Definition Decl.h:4051
void setBraceRange(SourceRange R)
Definition Decl.h:3929
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3955
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.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
UnsignedOrNone getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isCanonicalExpr() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
A template parameter object.
const APValue & getValue() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
SourceLocation getRAngleLoc() const
SourceLocation getLAngleLoc() const
SourceLocation getTemplateLoc() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
TemplateNameKind templateParameterKind() const
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
unsigned getIndex() const
Retrieve the index of the template parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
The top declaration context.
Definition Decl.h:105
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3822
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3840
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition ASTConcept.h:227
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3681
Symbolic representation of typeid(T) for some type T.
Definition APValue.h:44
const Type * getType() const
Definition APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition TypeLoc.cpp:193
A container of type source information.
Definition TypeBase.h:8475
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:267
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8486
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2899
bool getBoolValue() const
Definition ExprCXX.h:2950
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2970
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
Definition ExprCXX.cpp:1906
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2975
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2961
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2942
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2974
const APValue & getAPValue() const
Definition ExprCXX.h:2955
bool isStoredAsBoolean() const
Definition ExprCXX.h:2946
An operation on a type.
Definition TypeVisitor.h:64
The base class of the type hierarchy.
Definition TypeBase.h:1879
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
bool isArrayType() const
Definition TypeBase.h:8840
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9293
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2557
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition TypeBase.h:2475
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9340
bool isRecordType() const
Definition TypeBase.h:8868
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3801
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3696
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3746
QualType getUnderlyingType() const
Definition Decl.h:3751
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2636
SourceLocation getRParenLoc() const
Definition Expr.h:2712
SourceLocation getOperatorLoc() const
Definition Expr.h:2709
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2682
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2668
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2255
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2300
Expr * getSubExpr() const
Definition Expr.h:2296
Opcode getOpcode() const
Definition Expr.h:2291
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2392
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2395
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5144
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2309
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3389
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3463
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3458
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition ExprCXX.cpp:437
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4125
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4217
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4220
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4211
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4198
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition ExprCXX.cpp:1658
bool isImplicitAccess() const
True if this is an implicit access, i.e., one in which the member being accessed was not written in t...
Definition ExprCXX.cpp:1651
void addDecl(NamedDecl *D)
A set of unresolved declarations.
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4062
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4092
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4096
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4089
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4113
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3965
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3996
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4006
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:4013
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4023
Represents a C++ using-declaration.
Definition DeclCXX.h:3616
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3665
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3650
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3657
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3643
Represents C++ using-directive.
Definition DeclCXX.h:3121
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3192
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3357
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3188
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3196
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3199
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3166
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3817
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3841
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3853
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3837
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3898
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3927
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3931
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3424
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3488
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3487
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4968
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:5001
SourceLocation getBuiltinLoc() const
Definition Expr.h:5004
SourceLocation getRParenLoc() const
Definition Expr.h:5007
VarArgKind getVarargABI() const
Definition Expr.h:4992
const Expr * getSubExpr() const
Definition Expr.h:4988
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
void setType(QualType newType)
Definition Decl.h:724
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:932
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2781
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1593
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2906
VarDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition Decl.cpp:2241
bool isInlineSpecified() const
Definition Decl.h:1578
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2347
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2552
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2538
void setInlineSpecified()
Definition Decl.h:1582
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2743
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1365
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1179
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1575
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1183
const Expr * getInit() const
Definition Decl.h:1391
void setConstexpr(bool IC)
Definition Decl.h:1596
void setInit(Expr *I)
Definition Decl.cpp:2458
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2786
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
void setImplicitlyInline()
Definition Decl.h:1587
VarDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1381
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2869
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateDecl * getMostRecentDecl()
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the variable template specialization.
void setPointOfInstantiation(SourceLocation Loc)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
VarTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
VarTemplateSpecializationDecl * getMostRecentDecl()
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2706
Expr * getCond()
Definition Stmt.h:2758
SourceLocation getWhileLoc() const
Definition Stmt.h:2811
SourceLocation getRParenLoc() const
Definition Stmt.h:2816
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1247
SourceLocation getLParenLoc() const
Definition Stmt.h:2814
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition Stmt.cpp:1229
Stmt * getBody()
Definition Stmt.h:2770
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
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
Definition Address.h:330
llvm::Expected< SourceLocation > ExpectedSLoc
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
llvm::Expected< const Type * > ExpectedTypePtr
CanThrowResult
Possible results from evaluation of a noexcept expression.
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition Specifiers.h:150
std::pair< FileID, unsigned > FileIDAndOffset
llvm::Expected< DeclarationName > ExpectedName
llvm::Expected< Decl * > ExpectedDecl
@ Property
The type of a property.
Definition TypeBase.h:912
@ Result
The result type of a method or function.
Definition TypeBase.h:906
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
llvm::Expected< QualType > ExpectedType
@ Template
We are parsing a template declaration.
Definition Parser.h:81
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
@ VarTemplate
The name was classified as a variable template name.
Definition Sema.h:580
std::pair< SourceLocation, StringRef > ConstraintSubstitutionDiagnostic
Unsatisfied constraint expressions if the template arguments could be substituted into them,...
Definition ASTConcept.h:40
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition Specifiers.h:133
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:147
llvm::Expected< Expr * > ExpectedExpr
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition DeclBase.h:1305
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:189
U cast(CodeGen::Address addr)
Definition Address.h:327
llvm::Expected< Stmt * > ExpectedStmt
static void updateFlags(const Decl *From, Decl *To)
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
const UnsatisfiedConstraintRecord * end() const
Definition ASTConcept.h:100
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
const UnsatisfiedConstraintRecord * begin() const
Definition ASTConcept.h:96
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
const Expr * ConstraintExpr
Definition Decl.h:88
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition Decl.h:885
unsigned HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:899
unsigned HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:907
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5490
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5494
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5480
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5483
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5486
Extra information about a function prototype.
Definition TypeBase.h:5506
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