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 Expected<FriendDecl::FriendUnion> importFriendUnion(FriendDecl *D);
189
190 // Use this to import pointers of specific type.
191 template <typename ImportT>
192 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
193 auto ToOrErr = Importer.Import(From);
194 if (ToOrErr)
195 To = cast_or_null<ImportT>(*ToOrErr);
196 return ToOrErr.takeError();
197 }
198
199 // Call the import function of ASTImporter for a baseclass of type `T` and
200 // cast the return value to `T`.
201 template <typename T>
202 auto import(T *From)
203 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
205 auto ToOrErr = Importer.Import(From);
206 if (!ToOrErr)
207 return ToOrErr.takeError();
208 return cast_or_null<T>(*ToOrErr);
209 }
210
211 template <typename T>
212 auto import(const T *From) {
213 return import(const_cast<T *>(From));
214 }
215
216 // Call the import function of ASTImporter for type `T`.
217 template <typename T>
218 Expected<T> import(const T &From) {
219 return Importer.Import(From);
220 }
221
222 // Import an std::optional<T> by importing the contained T, if any.
223 template <typename T>
224 Expected<std::optional<T>> import(std::optional<T> From) {
225 if (!From)
226 return std::nullopt;
227 return import(*From);
228 }
229
230 ExplicitSpecifier importExplicitSpecifier(Error &Err,
231 ExplicitSpecifier ESpec);
232
233 // Wrapper for an overload set.
234 template <typename ToDeclT> struct CallOverloadedCreateFun {
235 template <typename... Args> decltype(auto) operator()(Args &&... args) {
236 return ToDeclT::Create(std::forward<Args>(args)...);
237 }
238 };
239
240 // Always use these functions to create a Decl during import. There are
241 // certain tasks which must be done after the Decl was created, e.g. we
242 // must immediately register that as an imported Decl. The parameter `ToD`
243 // will be set to the newly created Decl or if had been imported before
244 // then to the already imported Decl. Returns a bool value set to true if
245 // the `FromD` had been imported before.
246 template <typename ToDeclT, typename FromDeclT, typename... Args>
247 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
248 Args &&...args) {
249 // There may be several overloads of ToDeclT::Create. We must make sure
250 // to call the one which would be chosen by the arguments, thus we use a
251 // wrapper for the overload set.
252 CallOverloadedCreateFun<ToDeclT> OC;
253 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
254 std::forward<Args>(args)...);
255 }
256 // Use this overload if a special Type is needed to be created. E.g if we
257 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
258 // then:
259 // TypedefNameDecl *ToTypedef;
260 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
261 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
262 typename... Args>
263 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
264 Args &&...args) {
265 CallOverloadedCreateFun<NewDeclT> OC;
266 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
267 std::forward<Args>(args)...);
268 }
269 // Use this version if a special create function must be
270 // used, e.g. CXXRecordDecl::CreateLambda .
271 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
272 typename... Args>
273 [[nodiscard]] bool
274 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
275 FromDeclT *FromD, Args &&...args) {
276 if (Importer.getImportDeclErrorIfAny(FromD)) {
277 ToD = nullptr;
278 return true; // Already imported but with error.
279 }
280 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
281 if (ToD)
282 return true; // Already imported.
283 ToD = CreateFun(std::forward<Args>(args)...);
284 // Keep track of imported Decls.
285 Importer.RegisterImportedDecl(FromD, ToD);
286 Importer.SharedState->markAsNewDecl(ToD);
287 InitializeImportedDecl(FromD, ToD);
288 return false; // A new Decl is created.
289 }
290
291 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
292 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
293 if (FromD->isUsed())
294 ToD->setIsUsed();
295 if (FromD->isImplicit())
296 ToD->setImplicit();
297 }
298
299 // Check if we have found an existing definition. Returns with that
300 // definition if yes, otherwise returns null.
301 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
302 const FunctionDecl *Definition = nullptr;
303 if (D->doesThisDeclarationHaveABody() &&
304 FoundFunction->hasBody(Definition))
305 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
306 return nullptr;
307 }
308
309 void addDeclToContexts(Decl *FromD, Decl *ToD) {
310 if (Importer.isMinimalImport()) {
311 // In minimal import case the decl must be added even if it is not
312 // contained in original context, for LLDB compatibility.
313 // FIXME: Check if a better solution is possible.
314 if (!FromD->getDescribedTemplate() &&
315 FromD->getFriendObjectKind() == Decl::FOK_None)
317 return;
318 }
319
320 DeclContext *FromDC = FromD->getDeclContext();
321 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
322 DeclContext *ToDC = ToD->getDeclContext();
323 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
324
325 bool Visible = false;
326 if (FromDC->containsDeclAndLoad(FromD)) {
327 ToDC->addDeclInternal(ToD);
328 Visible = true;
329 }
330 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
331 ToLexicalDC->addDeclInternal(ToD);
332 Visible = true;
333 }
334
335 // If the Decl was added to any context, it was made already visible.
336 // Otherwise it is still possible that it should be visible.
337 if (!Visible) {
338 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
339 auto *ToNamed = cast<NamedDecl>(ToD);
340 DeclContextLookupResult FromLookup =
341 FromDC->lookup(FromNamed->getDeclName());
342 if (llvm::is_contained(FromLookup, FromNamed))
343 ToDC->makeDeclVisibleInContext(ToNamed);
344 }
345 }
346 }
347
348 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
349 DeclContext *OldDC) {
350 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
351 if (!LT)
352 return;
353
354 for (NamedDecl *TP : Params)
355 LT->update(TP, OldDC);
356 }
357
358 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
359 updateLookupTableForTemplateParameters(
360 Params, Importer.getToContext().getTranslationUnitDecl());
361 }
362
363 template <typename TemplateParmDeclT>
364 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
365 TemplateParmDeclT *ToD) {
366 if (D->hasDefaultArgument()) {
367 if (D->defaultArgumentWasInherited()) {
368 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
369 import(D->getDefaultArgStorage().getInheritedFrom());
370 if (!ToInheritedFromOrErr)
371 return ToInheritedFromOrErr.takeError();
372 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
373 if (!ToInheritedFrom->hasDefaultArgument()) {
374 // Resolve possible circular dependency between default value of the
375 // template argument and the template declaration.
376 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
377 import(D->getDefaultArgStorage()
378 .getInheritedFrom()
379 ->getDefaultArgument());
380 if (!ToInheritedDefaultArgOrErr)
381 return ToInheritedDefaultArgOrErr.takeError();
382 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
383 *ToInheritedDefaultArgOrErr);
384 }
385 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
386 ToInheritedFrom);
387 } else {
388 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
389 import(D->getDefaultArgument());
390 if (!ToDefaultArgOrErr)
391 return ToDefaultArgOrErr.takeError();
392 // Default argument could have been set in the
393 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
394 if (!ToD->hasDefaultArgument())
395 ToD->setDefaultArgument(Importer.getToContext(),
396 *ToDefaultArgOrErr);
397 }
398 }
399 return Error::success();
400 }
401
402 public:
403 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
404
408
409 // Importing types
411#define TYPE(Class, Base) \
412 ExpectedType Visit##Class##Type(const Class##Type *T);
413#include "clang/AST/TypeNodes.inc"
414
415 // Importing declarations
417 SourceLocation &Loc);
419 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
420 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
421 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
424 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
426 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
428
429 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
431 Expected<APValue> ImportAPValue(const APValue &FromValue);
432
434
435 /// What we should import from the definition.
437 /// Import the default subset of the definition, which might be
438 /// nothing (if minimal import is set) or might be everything (if minimal
439 /// import is not set).
441 /// Import everything.
443 /// Import only the bare bones needed to establish a valid
444 /// DeclContext.
446 };
447
449 return IDK == IDK_Everything ||
450 (IDK == IDK_Default && !Importer.isMinimalImport());
451 }
452
455 RecordDecl *From, RecordDecl *To,
458 EnumDecl *From, EnumDecl *To,
470
471 template <typename InContainerTy>
473 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
474
475 template<typename InContainerTy>
477 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
478 const InContainerTy &Container, TemplateArgumentListInfo &Result);
479
482 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
485 FunctionDecl *FromFD);
486
487 template <typename DeclTy>
488 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
489
491
493
495 ParmVarDecl *ToParam);
496
499
500 // Use for allocating string for newly imported object.
501 StringRef ImportASTStringRef(StringRef FromStr);
510
511 template <typename T>
513
514 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
515 bool IgnoreTemplateParmDepth = false);
565
568
587
588 // Importing statements
608 // FIXME: MSAsmStmt
609 // FIXME: SEHExceptStmt
610 // FIXME: SEHFinallyStmt
611 // FIXME: SEHTryStmt
612 // FIXME: SEHLeaveStmt
613 // FIXME: CapturedStmt
620 // FIXME: MSDependentExistsStmt
628
629 // Importing expressions
715
716 // Helper for chaining together multiple imports. If an error is detected,
717 // subsequent imports will return default constructed nodes, so that failure
718 // can be detected with a single conditional branch after a sequence of
719 // imports.
720 template <typename T> T importChecked(Error &Err, const T &From) {
721 // Don't attempt to import nodes if we hit an error earlier.
722 if (Err)
723 return T{};
724 Expected<T> MaybeVal = import(From);
725 if (!MaybeVal) {
726 Err = MaybeVal.takeError();
727 return T{};
728 }
729 return *MaybeVal;
730 }
731
732 template<typename IIter, typename OIter>
733 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
734 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
735 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
736 Expected<ItemT> ToOrErr = import(*Ibegin);
737 if (!ToOrErr)
738 return ToOrErr.takeError();
739 *Obegin = *ToOrErr;
740 }
741 return Error::success();
742 }
743
744 // Import every item from a container structure into an output container.
745 // If error occurs, stops at first error and returns the error.
746 // The output container should have space for all needed elements (it is not
747 // expanded, new items are put into from the beginning).
748 template<typename InContainerTy, typename OutContainerTy>
750 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
751 return ImportArrayChecked(
752 InContainer.begin(), InContainer.end(), OutContainer.begin());
753 }
754
755 template<typename InContainerTy, typename OIter>
756 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
757 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
758 }
759
761 CXXMethodDecl *FromMethod);
762
765 };
766
767template <typename InContainerTy>
769 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
770 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
771 auto ToLAngleLocOrErr = import(FromLAngleLoc);
772 if (!ToLAngleLocOrErr)
773 return ToLAngleLocOrErr.takeError();
774 auto ToRAngleLocOrErr = import(FromRAngleLoc);
775 if (!ToRAngleLocOrErr)
776 return ToRAngleLocOrErr.takeError();
777
778 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
779 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
780 return Err;
781 Result = std::move(ToTAInfo);
782 return Error::success();
783}
784
785template <>
791
792template <>
800
803 FunctionDecl *FromFD) {
804 assert(FromFD->getTemplatedKind() ==
806
808
809 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
810 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
811 return std::move(Err);
812
813 // Import template arguments.
814 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
815 std::get<1>(Result)))
816 return std::move(Err);
817
818 return Result;
819}
820
821template <>
823ASTNodeImporter::import(TemplateParameterList *From) {
825 if (Error Err = ImportContainerChecked(*From, To))
826 return std::move(Err);
827
828 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
829 if (!ToRequiresClause)
830 return ToRequiresClause.takeError();
831
832 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
833 if (!ToTemplateLocOrErr)
834 return ToTemplateLocOrErr.takeError();
835 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
836 if (!ToLAngleLocOrErr)
837 return ToLAngleLocOrErr.takeError();
838 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
839 if (!ToRAngleLocOrErr)
840 return ToRAngleLocOrErr.takeError();
841
843 Importer.getToContext(),
844 *ToTemplateLocOrErr,
845 *ToLAngleLocOrErr,
846 To,
847 *ToRAngleLocOrErr,
848 *ToRequiresClause);
849}
850
851template <>
853ASTNodeImporter::import(const TemplateArgument &From) {
854 switch (From.getKind()) {
856 return TemplateArgument();
857
859 ExpectedType ToTypeOrErr = import(From.getAsType());
860 if (!ToTypeOrErr)
861 return ToTypeOrErr.takeError();
862 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
863 From.getIsDefaulted());
864 }
865
867 ExpectedType ToTypeOrErr = import(From.getIntegralType());
868 if (!ToTypeOrErr)
869 return ToTypeOrErr.takeError();
870 return TemplateArgument(From, *ToTypeOrErr);
871 }
872
874 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
875 if (!ToOrErr)
876 return ToOrErr.takeError();
877 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
878 if (!ToTypeOrErr)
879 return ToTypeOrErr.takeError();
880 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
881 *ToTypeOrErr, From.getIsDefaulted());
882 }
883
885 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
886 if (!ToTypeOrErr)
887 return ToTypeOrErr.takeError();
888 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
889 From.getIsDefaulted());
890 }
891
893 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
894 if (!ToTypeOrErr)
895 return ToTypeOrErr.takeError();
896 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
897 if (!ToValueOrErr)
898 return ToValueOrErr.takeError();
899 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
900 *ToValueOrErr);
901 }
902
904 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
905 if (!ToTemplateOrErr)
906 return ToTemplateOrErr.takeError();
907
908 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
909 }
910
912 Expected<TemplateName> ToTemplateOrErr =
913 import(From.getAsTemplateOrTemplatePattern());
914 if (!ToTemplateOrErr)
915 return ToTemplateOrErr.takeError();
916
917 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
918 From.getIsDefaulted());
919 }
920
922 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
923 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
924 From.getIsDefaulted());
925 else
926 return ToExpr.takeError();
927
930 ToPack.reserve(From.pack_size());
931 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
932 return std::move(Err);
933
934 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
935 }
936 }
937
938 llvm_unreachable("Invalid template argument kind");
939}
940
941template <>
943ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
944 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
945 if (!ArgOrErr)
946 return ArgOrErr.takeError();
947 TemplateArgument Arg = *ArgOrErr;
948
949 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
950
953 ExpectedExpr E = import(FromInfo.getAsExpr());
954 if (!E)
955 return E.takeError();
956 ToInfo = TemplateArgumentLocInfo(*E);
957 } else if (Arg.getKind() == TemplateArgument::Type) {
958 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
959 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
960 else
961 return TSIOrErr.takeError();
962 } else {
963 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
964 if (!ToTemplateKWLocOrErr)
965 return ToTemplateKWLocOrErr.takeError();
966 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
967 if (!ToTemplateQualifierLocOrErr)
968 return ToTemplateQualifierLocOrErr.takeError();
969 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
970 if (!ToTemplateNameLocOrErr)
971 return ToTemplateNameLocOrErr.takeError();
972 auto ToTemplateEllipsisLocOrErr =
973 import(FromInfo.getTemplateEllipsisLoc());
974 if (!ToTemplateEllipsisLocOrErr)
975 return ToTemplateEllipsisLocOrErr.takeError();
977 Importer.getToContext(), *ToTemplateKWLocOrErr,
978 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
979 *ToTemplateEllipsisLocOrErr);
980 }
981
982 return TemplateArgumentLoc(Arg, ToInfo);
983}
984
985template <>
986Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
987 if (DG.isNull())
988 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
989 size_t NumDecls = DG.end() - DG.begin();
991 ToDecls.reserve(NumDecls);
992 for (Decl *FromD : DG) {
993 if (auto ToDOrErr = import(FromD))
994 ToDecls.push_back(*ToDOrErr);
995 else
996 return ToDOrErr.takeError();
997 }
998 return DeclGroupRef::Create(Importer.getToContext(),
999 ToDecls.begin(),
1000 NumDecls);
1001}
1002
1003template <>
1005ASTNodeImporter::import(const Designator &D) {
1006 if (D.isFieldDesignator()) {
1007 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
1008
1009 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
1010 if (!ToDotLocOrErr)
1011 return ToDotLocOrErr.takeError();
1012
1013 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1014 if (!ToFieldLocOrErr)
1015 return ToFieldLocOrErr.takeError();
1016
1018 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1019 }
1020
1021 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1022 if (!ToLBracketLocOrErr)
1023 return ToLBracketLocOrErr.takeError();
1024
1025 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1026 if (!ToRBracketLocOrErr)
1027 return ToRBracketLocOrErr.takeError();
1028
1029 if (D.isArrayDesignator())
1031 *ToLBracketLocOrErr,
1032 *ToRBracketLocOrErr);
1033
1034 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1035 if (!ToEllipsisLocOrErr)
1036 return ToEllipsisLocOrErr.takeError();
1037
1038 assert(D.isArrayRangeDesignator());
1040 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1041 *ToRBracketLocOrErr);
1042}
1043
1044template <>
1045Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1046 Error Err = Error::success();
1047 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1048 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1049 auto ToConceptNameLoc =
1050 importChecked(Err, From->getConceptNameInfo().getLoc());
1051 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1052 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1053 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1054 if (Err)
1055 return std::move(Err);
1056 TemplateArgumentListInfo ToTAInfo;
1057 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1058 if (ASTTemplateArgs)
1059 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1060 return std::move(Err);
1061 auto *ConceptRef = ConceptReference::Create(
1062 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1063 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1064 ToNamedConcept,
1065 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1066 Importer.getToContext(), ToTAInfo)
1067 : nullptr);
1068 return ConceptRef;
1069}
1070
1071StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1072 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1073 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1074 return StringRef(ToStore, FromStr.size());
1075}
1076
1078 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1079 ToSat.IsSatisfied = FromSat.IsSatisfied;
1080 ToSat.ContainsErrors = FromSat.ContainsErrors;
1081 if (!ToSat.IsSatisfied) {
1082 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1083 if (const Expr *E = dyn_cast<const Expr *>(*Record)) {
1084 ExpectedExpr ToSecondExpr = import(E);
1085 if (!ToSecondExpr)
1086 return ToSecondExpr.takeError();
1087 ToSat.Details.emplace_back(ToSecondExpr.get());
1088 } else if (auto CR = dyn_cast<const ConceptReference *>(*Record)) {
1089 Expected<ConceptReference *> ToCROrErr = import(CR);
1090 if (!ToCROrErr)
1091 return ToCROrErr.takeError();
1092 ToSat.Details.emplace_back(ToCROrErr.get());
1093 } else {
1094 auto Pair = dyn_cast<const ConstraintSubstitutionDiagnostic *>(*Record);
1095
1096 ExpectedSLoc ToPairFirst = import(Pair->first);
1097 if (!ToPairFirst)
1098 return ToPairFirst.takeError();
1099 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1100 ToSat.Details.emplace_back(new (Importer.getToContext())
1102 ToPairFirst.get(), ToPairSecond});
1103 }
1104 }
1105 }
1106 return Error::success();
1107}
1108
1109template <>
1111ASTNodeImporter::import(
1113 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1114 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1115 if (!ToLoc)
1116 return ToLoc.takeError();
1117 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1118 return new (Importer.getToContext())
1120 ToDiagMessage};
1121}
1122
1125 using namespace concepts;
1126
1127 if (From->isSubstitutionFailure()) {
1128 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1129 if (!DiagOrErr)
1130 return DiagOrErr.takeError();
1131 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1132 } else {
1133 Expected<TypeSourceInfo *> ToType = import(From->getType());
1134 if (!ToType)
1135 return ToType.takeError();
1136 return new (Importer.getToContext()) TypeRequirement(*ToType);
1137 }
1138}
1139
1142 using namespace concepts;
1143
1144 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1145 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1146
1147 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1148 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1149
1150 if (IsRKSimple) {
1151 Req.emplace();
1152 } else {
1153 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1155
1156 if (FromTypeRequirement.isTypeConstraint()) {
1157 const bool IsDependent = FromTypeRequirement.isDependent();
1158 auto ParamsOrErr =
1159 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1160 if (!ParamsOrErr)
1161 return ParamsOrErr.takeError();
1162 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1163 auto SubstConstraintExprOrErr =
1165 if (!SubstConstraintExprOrErr)
1166 return SubstConstraintExprOrErr.takeError();
1167 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1168 }
1169 Req.emplace(ParamsOrErr.get(), IsDependent);
1170 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1171 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1172 if (!DiagOrErr)
1173 return DiagOrErr.takeError();
1174 Req.emplace(DiagOrErr.get());
1175 } else {
1176 Req.emplace();
1177 }
1178 }
1179
1180 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1181 if (!NoexceptLocOrErr)
1182 return NoexceptLocOrErr.takeError();
1183
1184 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1185 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1186 if (!DiagOrErr)
1187 return DiagOrErr.takeError();
1188 return new (Importer.getToContext()) ExprRequirement(
1189 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1190 } else {
1191 Expected<Expr *> ExprOrErr = import(From->getExpr());
1192 if (!ExprOrErr)
1193 return ExprOrErr.takeError();
1194 return new (Importer.getToContext()) concepts::ExprRequirement(
1195 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1196 SubstitutedConstraintExpr);
1197 }
1198}
1199
1202 using namespace concepts;
1203
1204 const ASTConstraintSatisfaction &FromSatisfaction =
1206 if (From->hasInvalidConstraint()) {
1207 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1208 ASTConstraintSatisfaction *ToSatisfaction =
1209 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1210 FromSatisfaction);
1211 return new (Importer.getToContext())
1212 NestedRequirement(ToEntity, ToSatisfaction);
1213 } else {
1214 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1215 if (!ToExpr)
1216 return ToExpr.takeError();
1217 if (ToExpr.get()->isInstantiationDependent()) {
1218 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1219 } else {
1220 ConstraintSatisfaction Satisfaction;
1221 if (Error Err =
1222 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1223 return std::move(Err);
1224 return new (Importer.getToContext()) NestedRequirement(
1225 Importer.getToContext(), ToExpr.get(), Satisfaction);
1226 }
1227 }
1228}
1229
1230template <>
1232ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1233 switch (FromRequire->getKind()) {
1242 }
1243 llvm_unreachable("Unhandled requirement kind");
1244}
1245
1246template <>
1247Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1248 ValueDecl *Var = nullptr;
1249 if (From.capturesVariable()) {
1250 if (auto VarOrErr = import(From.getCapturedVar()))
1251 Var = *VarOrErr;
1252 else
1253 return VarOrErr.takeError();
1254 }
1255
1256 auto LocationOrErr = import(From.getLocation());
1257 if (!LocationOrErr)
1258 return LocationOrErr.takeError();
1259
1260 SourceLocation EllipsisLoc;
1261 if (From.isPackExpansion())
1262 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1263 return std::move(Err);
1264
1265 return LambdaCapture(
1266 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1267 EllipsisLoc);
1268}
1269
1270template <typename T>
1272 if (Found->getLinkageInternal() != From->getLinkageInternal())
1273 return false;
1274
1275 if (From->hasExternalFormalLinkage())
1276 return Found->hasExternalFormalLinkage();
1277 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1278 return false;
1279 if (From->isInAnonymousNamespace())
1280 return Found->isInAnonymousNamespace();
1281 else
1282 return !Found->isInAnonymousNamespace() &&
1283 !Found->hasExternalFormalLinkage();
1284}
1285
1286template <>
1288 TypedefNameDecl *From) {
1289 if (Found->getLinkageInternal() != From->getLinkageInternal())
1290 return false;
1291
1292 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1293 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1294 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1295}
1296
1297} // namespace clang
1298
1299//----------------------------------------------------------------------------
1300// Import Types
1301//----------------------------------------------------------------------------
1302
1303using namespace clang;
1304
1306 const FunctionDecl *D) {
1307 const FunctionDecl *LambdaD = nullptr;
1308 if (!isCycle(D) && D) {
1309 FunctionDeclsWithImportInProgress.insert(D);
1310 LambdaD = D;
1311 }
1312 return llvm::scope_exit([this, LambdaD]() {
1313 if (LambdaD) {
1314 FunctionDeclsWithImportInProgress.erase(LambdaD);
1315 }
1316 });
1317}
1318
1320 const FunctionDecl *D) const {
1321 return FunctionDeclsWithImportInProgress.find(D) !=
1322 FunctionDeclsWithImportInProgress.end();
1323}
1324
1326 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1327 << T->getTypeClassName();
1328 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1329}
1330
1331ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1332 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1333 if (!UnderlyingTypeOrErr)
1334 return UnderlyingTypeOrErr.takeError();
1335
1336 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1337}
1338
1339ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1340 switch (T->getKind()) {
1341#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1342 case BuiltinType::Id: \
1343 return Importer.getToContext().SingletonId;
1344#include "clang/Basic/OpenCLImageTypes.def"
1345#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1346 case BuiltinType::Id: \
1347 return Importer.getToContext().Id##Ty;
1348#include "clang/Basic/OpenCLExtensionTypes.def"
1349#define SVE_TYPE(Name, Id, SingletonId) \
1350 case BuiltinType::Id: \
1351 return Importer.getToContext().SingletonId;
1352#include "clang/Basic/AArch64ACLETypes.def"
1353#define PPC_VECTOR_TYPE(Name, Id, Size) \
1354 case BuiltinType::Id: \
1355 return Importer.getToContext().Id##Ty;
1356#include "clang/Basic/PPCTypes.def"
1357#define RVV_TYPE(Name, Id, SingletonId) \
1358 case BuiltinType::Id: \
1359 return Importer.getToContext().SingletonId;
1360#include "clang/Basic/RISCVVTypes.def"
1361#define WASM_TYPE(Name, Id, SingletonId) \
1362 case BuiltinType::Id: \
1363 return Importer.getToContext().SingletonId;
1364#include "clang/Basic/WebAssemblyReferenceTypes.def"
1365#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1366 case BuiltinType::Id: \
1367 return Importer.getToContext().SingletonId;
1368#include "clang/Basic/AMDGPUTypes.def"
1369#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1370 case BuiltinType::Id: \
1371 return Importer.getToContext().SingletonId;
1372#include "clang/Basic/HLSLIntangibleTypes.def"
1373#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
1374 case BuiltinType::Id: \
1375 return Importer.getToContext().SingletonId;
1376#include "clang/Basic/HLSLPackedTypes.def"
1377#define SPIRV_TYPE(Name, Id, SingletonId) \
1378 case BuiltinType::Id: \
1379 return Importer.getToContext().SingletonId;
1380#include "clang/Basic/SPIRVTypes.def"
1381#define SHARED_SINGLETON_TYPE(Expansion)
1382#define BUILTIN_TYPE(Id, SingletonId) \
1383 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1384#include "clang/AST/BuiltinTypes.def"
1385
1386 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1387 // context supports C++.
1388
1389 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1390 // context supports ObjC.
1391
1392 case BuiltinType::Char_U:
1393 // The context we're importing from has an unsigned 'char'. If we're
1394 // importing into a context with a signed 'char', translate to
1395 // 'unsigned char' instead.
1396 if (Importer.getToContext().getLangOpts().CharIsSigned)
1397 return Importer.getToContext().UnsignedCharTy;
1398
1399 return Importer.getToContext().CharTy;
1400
1401 case BuiltinType::Char_S:
1402 // The context we're importing from has an unsigned 'char'. If we're
1403 // importing into a context with a signed 'char', translate to
1404 // 'unsigned char' instead.
1405 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1406 return Importer.getToContext().SignedCharTy;
1407
1408 return Importer.getToContext().CharTy;
1409
1410 case BuiltinType::WChar_S:
1411 case BuiltinType::WChar_U:
1412 // FIXME: If not in C++, shall we translate to the C equivalent of
1413 // wchar_t?
1414 return Importer.getToContext().WCharTy;
1415 }
1416
1417 llvm_unreachable("Invalid BuiltinType Kind!");
1418}
1419
1420ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1421 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1422 if (!ToOriginalTypeOrErr)
1423 return ToOriginalTypeOrErr.takeError();
1424
1425 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1426}
1427
1428ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1429 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1430 if (!ToElementTypeOrErr)
1431 return ToElementTypeOrErr.takeError();
1432
1433 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1434}
1435
1436ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1437 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1438 if (!ToPointeeTypeOrErr)
1439 return ToPointeeTypeOrErr.takeError();
1440
1441 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1442}
1443
1444ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1445 // FIXME: Check for blocks support in "to" context.
1446 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1447 if (!ToPointeeTypeOrErr)
1448 return ToPointeeTypeOrErr.takeError();
1449
1450 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1451}
1452
1454ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1455 // FIXME: Check for C++ support in "to" context.
1456 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1457 if (!ToPointeeTypeOrErr)
1458 return ToPointeeTypeOrErr.takeError();
1459
1460 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1461}
1462
1464ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1465 // FIXME: Check for C++0x support in "to" context.
1466 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1467 if (!ToPointeeTypeOrErr)
1468 return ToPointeeTypeOrErr.takeError();
1469
1470 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1471}
1472
1474ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1475 // FIXME: Check for C++ support in "to" context.
1476 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1477 if (!ToPointeeTypeOrErr)
1478 return ToPointeeTypeOrErr.takeError();
1479
1480 auto QualifierOrErr = import(T->getQualifier());
1481 if (!QualifierOrErr)
1482 return QualifierOrErr.takeError();
1483
1484 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1485 if (!ClsOrErr)
1486 return ClsOrErr.takeError();
1487
1488 return Importer.getToContext().getMemberPointerType(
1489 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1490}
1491
1493ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1494 Error Err = Error::success();
1495 auto ToElementType = importChecked(Err, T->getElementType());
1496 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1497 if (Err)
1498 return std::move(Err);
1499
1500 return Importer.getToContext().getConstantArrayType(
1501 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1502 T->getIndexTypeCVRQualifiers());
1503}
1504
1506ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1507 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1508 if (!ToArrayTypeOrErr)
1509 return ToArrayTypeOrErr.takeError();
1510
1511 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1512}
1513
1515ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1516 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1517 if (!ToElementTypeOrErr)
1518 return ToElementTypeOrErr.takeError();
1519
1520 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1521 T->getSizeModifier(),
1522 T->getIndexTypeCVRQualifiers());
1523}
1524
1526ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1527 Error Err = Error::success();
1528 QualType ToElementType = importChecked(Err, T->getElementType());
1529 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1530 if (Err)
1531 return std::move(Err);
1532 return Importer.getToContext().getVariableArrayType(
1533 ToElementType, ToSizeExpr, T->getSizeModifier(),
1534 T->getIndexTypeCVRQualifiers());
1535}
1536
1537ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1538 const DependentSizedArrayType *T) {
1539 Error Err = Error::success();
1540 QualType ToElementType = importChecked(Err, T->getElementType());
1541 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1542 if (Err)
1543 return std::move(Err);
1544 // SizeExpr may be null if size is not specified directly.
1545 // For example, 'int a[]'.
1546
1547 return Importer.getToContext().getDependentSizedArrayType(
1548 ToElementType, ToSizeExpr, T->getSizeModifier(),
1549 T->getIndexTypeCVRQualifiers());
1550}
1551
1552ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1553 const DependentSizedExtVectorType *T) {
1554 Error Err = Error::success();
1555 QualType ToElementType = importChecked(Err, T->getElementType());
1556 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1557 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1558 if (Err)
1559 return std::move(Err);
1560 return Importer.getToContext().getDependentSizedExtVectorType(
1561 ToElementType, ToSizeExpr, ToAttrLoc);
1562}
1563
1564ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1565 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1566 if (!ToElementTypeOrErr)
1567 return ToElementTypeOrErr.takeError();
1568
1569 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1570 T->getNumElements(),
1571 T->getVectorKind());
1572}
1573
1574ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1575 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1576 if (!ToElementTypeOrErr)
1577 return ToElementTypeOrErr.takeError();
1578
1579 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1580 T->getNumElements());
1581}
1582
1584ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1585 // FIXME: What happens if we're importing a function without a prototype
1586 // into C++? Should we make it variadic?
1587 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1588 if (!ToReturnTypeOrErr)
1589 return ToReturnTypeOrErr.takeError();
1590
1591 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1592 T->getExtInfo());
1593}
1594
1596ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1597 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1598 if (!ToReturnTypeOrErr)
1599 return ToReturnTypeOrErr.takeError();
1600
1601 // Import argument types
1602 SmallVector<QualType, 4> ArgTypes;
1603 for (const auto &A : T->param_types()) {
1604 ExpectedType TyOrErr = import(A);
1605 if (!TyOrErr)
1606 return TyOrErr.takeError();
1607 ArgTypes.push_back(*TyOrErr);
1608 }
1609
1610 // Import exception types
1611 SmallVector<QualType, 4> ExceptionTypes;
1612 for (const auto &E : T->exceptions()) {
1613 ExpectedType TyOrErr = import(E);
1614 if (!TyOrErr)
1615 return TyOrErr.takeError();
1616 ExceptionTypes.push_back(*TyOrErr);
1617 }
1618
1619 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
1620 Error Err = Error::success();
1621 FunctionProtoType::ExtProtoInfo ToEPI;
1622 ToEPI.ExtInfo = FromEPI.ExtInfo;
1623 ToEPI.Variadic = FromEPI.Variadic;
1624 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1625 ToEPI.TypeQuals = FromEPI.TypeQuals;
1626 ToEPI.RefQualifier = FromEPI.RefQualifier;
1627 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1629 importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr);
1631 importChecked(Err, FromEPI.ExceptionSpec.SourceDecl);
1633 importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate);
1634 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1635
1636 if (Err)
1637 return std::move(Err);
1638
1639 return Importer.getToContext().getFunctionType(
1640 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1641}
1642
1643ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1644 const UnresolvedUsingType *T) {
1645 auto ToQualifierOrErr = import(T->getQualifier());
1646 if (!ToQualifierOrErr)
1647 return ToQualifierOrErr.takeError();
1648 auto ToDeclOrErr = import(T->getDecl());
1649 if (!ToDeclOrErr)
1650 return ToDeclOrErr.takeError();
1651
1653 return Importer.getToContext().getCanonicalUnresolvedUsingType(
1654 *ToDeclOrErr);
1655 return Importer.getToContext().getUnresolvedUsingType(
1656 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr);
1657}
1658
1659ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1660 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1661 if (!ToInnerTypeOrErr)
1662 return ToInnerTypeOrErr.takeError();
1663
1664 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1665}
1666
1668ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1669
1670 ExpectedType Pattern = import(T->getPattern());
1671 if (!Pattern)
1672 return Pattern.takeError();
1673 ExpectedExpr Index = import(T->getIndexExpr());
1674 if (!Index)
1675 return Index.takeError();
1676 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1677}
1678
1679ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1680 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1681 if (!ToDeclOrErr)
1682 return ToDeclOrErr.takeError();
1683
1684 auto ToQualifierOrErr = import(T->getQualifier());
1685 if (!ToQualifierOrErr)
1686 return ToQualifierOrErr.takeError();
1687
1688 ExpectedType ToUnderlyingTypeOrErr =
1689 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1690 if (!ToUnderlyingTypeOrErr)
1691 return ToUnderlyingTypeOrErr.takeError();
1692
1693 return Importer.getToContext().getTypedefType(
1694 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1695}
1696
1697ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1698 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1699 if (!ToExprOrErr)
1700 return ToExprOrErr.takeError();
1701 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1702}
1703
1704ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1705 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1706 if (!ToUnderlyingTypeOrErr)
1707 return ToUnderlyingTypeOrErr.takeError();
1708 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1709 T->getKind());
1710}
1711
1712ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1713 auto ToQualifierOrErr = import(T->getQualifier());
1714 if (!ToQualifierOrErr)
1715 return ToQualifierOrErr.takeError();
1716 auto ToDeclOrErr = import(T->getDecl());
1717 if (!ToDeclOrErr)
1718 return ToDeclOrErr.takeError();
1719
1720 ExpectedType ToTypeOrErr = import(T->desugar());
1721 if (!ToTypeOrErr)
1722 return ToTypeOrErr.takeError();
1723 return Importer.getToContext().getUsingType(
1724 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToTypeOrErr);
1725}
1726
1727ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1728 // FIXME: Make sure that the "to" context supports C++0x!
1729 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1730 if (!ToExprOrErr)
1731 return ToExprOrErr.takeError();
1732
1733 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1734 if (!ToUnderlyingTypeOrErr)
1735 return ToUnderlyingTypeOrErr.takeError();
1736
1737 return Importer.getToContext().getDecltypeType(
1738 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1739}
1740
1742ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1743 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1744 if (!ToBaseTypeOrErr)
1745 return ToBaseTypeOrErr.takeError();
1746
1747 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1748 if (!ToUnderlyingTypeOrErr)
1749 return ToUnderlyingTypeOrErr.takeError();
1750
1751 return Importer.getToContext().getUnaryTransformType(
1752 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1753}
1754
1755ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1756 // FIXME: Make sure that the "to" context supports C++11!
1757 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1758 if (!ToDeducedTypeOrErr)
1759 return ToDeducedTypeOrErr.takeError();
1760
1761 TemplateName ToTypeConstraint;
1762 if (TemplateName FromTypeConstraint = T->getTypeConstraintConcept();
1763 !FromTypeConstraint.isNull()) {
1764 Expected<TemplateName> ToTypeConstraintOrErr = import(FromTypeConstraint);
1765 if (!ToTypeConstraintOrErr)
1766 return ToTypeConstraintOrErr.takeError();
1767 ToTypeConstraint = *ToTypeConstraintOrErr;
1768 }
1769
1770 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1771 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1772 ToTemplateArgs))
1773 return std::move(Err);
1774
1775 return Importer.getToContext().getAutoType(
1776 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1777 ToTypeConstraint, ToTemplateArgs);
1778}
1779
1780ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1781 const DeducedTemplateSpecializationType *T) {
1782 // FIXME: Make sure that the "to" context supports C++17!
1783 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1784 if (!ToTemplateNameOrErr)
1785 return ToTemplateNameOrErr.takeError();
1786 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1787 if (!ToDeducedTypeOrErr)
1788 return ToDeducedTypeOrErr.takeError();
1789
1790 return Importer.getToContext().getDeducedTemplateSpecializationType(
1791 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1792 *ToTemplateNameOrErr);
1793}
1794
1795ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1796 TagDecl *DeclForType = T->getDecl();
1797 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1798 if (!ToDeclOrErr)
1799 return ToDeclOrErr.takeError();
1800
1801 // If there is a definition of the 'OriginalDecl', it should be imported to
1802 // have all information for the type in the "To" AST. (In some cases no
1803 // other reference may exist to the definition decl and it would not be
1804 // imported otherwise.)
1805 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1806 if (!ToDefDeclOrErr)
1807 return ToDefDeclOrErr.takeError();
1808
1810 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1811
1812 auto ToQualifierOrErr = import(T->getQualifier());
1813 if (!ToQualifierOrErr)
1814 return ToQualifierOrErr.takeError();
1815
1816 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1817 *ToDeclOrErr, T->isTagOwned());
1818}
1819
1820ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1821 return VisitTagType(T);
1822}
1823
1824ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1825 return VisitTagType(T);
1826}
1827
1829ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1830 return VisitTagType(T);
1831}
1832
1833ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1834 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1835 if (!ToModifiedTypeOrErr)
1836 return ToModifiedTypeOrErr.takeError();
1837 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1838 if (!ToEquivalentTypeOrErr)
1839 return ToEquivalentTypeOrErr.takeError();
1840
1841 return Importer.getToContext().getAttributedType(
1842 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1843 T->getAttr());
1844}
1845
1847ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1848 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1849 if (!ToWrappedTypeOrErr)
1850 return ToWrappedTypeOrErr.takeError();
1851
1852 Error Err = Error::success();
1853 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1854
1855 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1856 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1857 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1858 if (!ToDeclOrErr)
1859 return ToDeclOrErr.takeError();
1860 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1861 }
1862
1863 return Importer.getToContext().getCountAttributedType(
1864 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1865 ArrayRef(CoupledDecls));
1866}
1867
1869ASTNodeImporter::VisitLateParsedAttrType(const LateParsedAttrType *T) {
1870 llvm_unreachable("should be replaced with a concrete type before AST import");
1871}
1872
1873ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1874 const TemplateTypeParmType *T) {
1875 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1876 if (!ToDeclOrErr)
1877 return ToDeclOrErr.takeError();
1878
1879 return Importer.getToContext().getTemplateTypeParmType(
1880 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1881}
1882
1883ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1884 const SubstTemplateTypeParmType *T) {
1885 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1886 if (!ReplacedOrErr)
1887 return ReplacedOrErr.takeError();
1888
1889 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1890 if (!ToReplacementTypeOrErr)
1891 return ToReplacementTypeOrErr.takeError();
1892
1893 return Importer.getToContext().getSubstTemplateTypeParmType(
1894 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1895 T->getFinal());
1896}
1897
1898ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1899 const SubstTemplateTypeParmPackType *T) {
1900 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1901 if (!ReplacedOrErr)
1902 return ReplacedOrErr.takeError();
1903
1904 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1905 if (!ToArgumentPack)
1906 return ToArgumentPack.takeError();
1907
1908 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1909 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1910}
1911
1912ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1913 const SubstBuiltinTemplatePackType *T) {
1914 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1915 if (!ToArgumentPack)
1916 return ToArgumentPack.takeError();
1917 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1918}
1919
1920ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1921 const TemplateSpecializationType *T) {
1922 auto ToTemplateOrErr = import(T->getTemplateName());
1923 if (!ToTemplateOrErr)
1924 return ToTemplateOrErr.takeError();
1925
1926 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1927 if (Error Err =
1928 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1929 return std::move(Err);
1930
1931 ExpectedType ToUnderlyingOrErr =
1932 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1933 if (!ToUnderlyingOrErr)
1934 return ToUnderlyingOrErr.takeError();
1935 return Importer.getToContext().getTemplateSpecializationType(
1936 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1937 *ToUnderlyingOrErr);
1938}
1939
1941ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1942 ExpectedType ToPatternOrErr = import(T->getPattern());
1943 if (!ToPatternOrErr)
1944 return ToPatternOrErr.takeError();
1945
1946 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1947 T->getNumExpansions(),
1948 /*ExpactPack=*/false);
1949}
1950
1952ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1953 auto ToQualifierOrErr = import(T->getQualifier());
1954 if (!ToQualifierOrErr)
1955 return ToQualifierOrErr.takeError();
1956
1957 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1958 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1959 *ToQualifierOrErr, Name);
1960}
1961
1963ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1964 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1965 if (!ToDeclOrErr)
1966 return ToDeclOrErr.takeError();
1967
1968 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1969}
1970
1971ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1972 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1973 if (!ToBaseTypeOrErr)
1974 return ToBaseTypeOrErr.takeError();
1975
1976 SmallVector<QualType, 4> TypeArgs;
1977 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1978 if (ExpectedType TyOrErr = import(TypeArg))
1979 TypeArgs.push_back(*TyOrErr);
1980 else
1981 return TyOrErr.takeError();
1982 }
1983
1984 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1985 for (auto *P : T->quals()) {
1986 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1987 Protocols.push_back(*ProtocolOrErr);
1988 else
1989 return ProtocolOrErr.takeError();
1990
1991 }
1992
1993 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1994 Protocols,
1995 T->isKindOfTypeAsWritten());
1996}
1997
1999ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
2000 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
2001 if (!ToPointeeTypeOrErr)
2002 return ToPointeeTypeOrErr.takeError();
2003
2004 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
2005}
2006
2008ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
2009 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
2010 if (!ToUnderlyingTypeOrErr)
2011 return ToUnderlyingTypeOrErr.takeError();
2012
2013 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
2014 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
2015 ToIdentifier);
2016}
2017
2018ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
2019 Error Err = Error::success();
2020 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
2021 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
2022 if (Err)
2023 return std::move(Err);
2024
2025 return Importer.getToContext().getAdjustedType(ToOriginalType,
2026 ToAdjustedType);
2027}
2028
2029ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
2030 return Importer.getToContext().getBitIntType(T->isUnsigned(),
2031 T->getNumBits());
2032}
2033
2034ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
2035 const clang::BTFTagAttributedType *T) {
2036 Error Err = Error::success();
2037 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
2038 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2039 if (Err)
2040 return std::move(Err);
2041
2042 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
2043 ToWrappedType);
2044}
2045
2046ExpectedType clang::ASTNodeImporter::VisitOverflowBehaviorType(
2047 const clang::OverflowBehaviorType *T) {
2048 Error Err = Error::success();
2049 OverflowBehaviorType::OverflowBehaviorKind ToKind = T->getBehaviorKind();
2050 QualType ToUnderlyingType = importChecked(Err, T->getUnderlyingType());
2051 if (Err)
2052 return std::move(Err);
2053
2054 return Importer.getToContext().getOverflowBehaviorType(ToKind,
2056}
2057
2058ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2059 const clang::HLSLAttributedResourceType *T) {
2060 Error Err = Error::success();
2061 HLSLAttributedResourceType::Attributes ToAttrs = T->getAttrs();
2062 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2063 QualType ToContainedType = importChecked(Err, T->getContainedType());
2064 ToAttrs.SampleCountExpr = importChecked(Err, T->getSampleCountExpr());
2065 if (Err)
2066 return std::move(Err);
2067
2068 return Importer.getToContext().getHLSLAttributedResourceType(
2069 ToWrappedType, ToContainedType, ToAttrs);
2070}
2071
2072ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2073 const clang::HLSLInlineSpirvType *T) {
2074 Error Err = Error::success();
2075
2076 uint32_t ToOpcode = T->getOpcode();
2077 uint32_t ToSize = T->getSize();
2078 uint32_t ToAlignment = T->getAlignment();
2079
2080 llvm::SmallVector<SpirvOperand> ToOperands;
2081
2082 for (auto &Operand : T->getOperands()) {
2083 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2084
2085 switch (Operand.getKind()) {
2086 case SpirvOperandKind::ConstantId:
2087 ToOperands.push_back(SpirvOperand::createConstant(
2088 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2089 break;
2090 case SpirvOperandKind::Literal:
2091 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2092 break;
2093 case SpirvOperandKind::TypeId:
2094 ToOperands.push_back(SpirvOperand::createType(
2095 importChecked(Err, Operand.getResultType())));
2096 break;
2097 default:
2098 llvm_unreachable("Invalid SpirvOperand kind");
2099 }
2100
2101 if (Err)
2102 return std::move(Err);
2103 }
2104
2105 return Importer.getToContext().getHLSLInlineSpirvType(
2106 ToOpcode, ToSize, ToAlignment, ToOperands);
2107}
2108
2109ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2110 const clang::ConstantMatrixType *T) {
2111 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2112 if (!ToElementTypeOrErr)
2113 return ToElementTypeOrErr.takeError();
2114
2115 return Importer.getToContext().getConstantMatrixType(
2116 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns(), T->getLayout());
2117}
2118
2119ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2120 const clang::DependentAddressSpaceType *T) {
2121 Error Err = Error::success();
2122 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2123 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2124 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2125 if (Err)
2126 return std::move(Err);
2127
2128 return Importer.getToContext().getDependentAddressSpaceType(
2129 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2130}
2131
2132ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2133 const clang::DependentBitIntType *T) {
2134 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2135 if (!ToNumBitsExprOrErr)
2136 return ToNumBitsExprOrErr.takeError();
2137 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2138 *ToNumBitsExprOrErr);
2139}
2140
2141ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2142 const clang::PredefinedSugarType *T) {
2143 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2144}
2145
2146ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2147 const clang::DependentSizedMatrixType *T) {
2148 Error Err = Error::success();
2149 QualType ToElementType = importChecked(Err, T->getElementType());
2150 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2151 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2152 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2153 if (Err)
2154 return std::move(Err);
2155
2156 return Importer.getToContext().getDependentSizedMatrixType(
2157 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2158}
2159
2160ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2161 const clang::DependentVectorType *T) {
2162 Error Err = Error::success();
2163 QualType ToElementType = importChecked(Err, T->getElementType());
2164 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2165 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2166 if (Err)
2167 return std::move(Err);
2168
2169 return Importer.getToContext().getDependentVectorType(
2170 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2171}
2172
2173ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2174 const clang::ObjCTypeParamType *T) {
2175 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2176 if (!ToDeclOrErr)
2177 return ToDeclOrErr.takeError();
2178
2179 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2180 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2181 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2182 if (!ToProtocolOrErr)
2183 return ToProtocolOrErr.takeError();
2184 ToProtocols.push_back(*ToProtocolOrErr);
2185 }
2186
2187 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2188 ToProtocols);
2189}
2190
2191ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2192 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2193 if (!ToElementTypeOrErr)
2194 return ToElementTypeOrErr.takeError();
2195
2196 ASTContext &ToCtx = Importer.getToContext();
2197 if (T->isReadOnly())
2198 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2199 else
2200 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2201}
2202
2203//----------------------------------------------------------------------------
2204// Import Declarations
2205//----------------------------------------------------------------------------
2207 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2208 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2209 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2210 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2211 // FIXME: We could support these constructs by importing a different type of
2212 // this parameter and by importing the original type of the parameter only
2213 // after the FunctionDecl is created. See
2214 // VisitFunctionDecl::UsedDifferentProtoType.
2215 DeclContext *OrigDC = D->getDeclContext();
2216 FunctionDecl *FunDecl;
2217 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2218 FunDecl->hasBody()) {
2219 auto getLeafPointeeType = [](const Type *T) {
2220 while (T->isPointerType() || T->isArrayType()) {
2221 T = T->getPointeeOrArrayElementType();
2222 }
2223 return T;
2224 };
2225 for (const ParmVarDecl *P : FunDecl->parameters()) {
2226 const Type *LeafT =
2227 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2228 auto *RT = dyn_cast<RecordType>(LeafT);
2229 if (RT && RT->getDecl() == D) {
2230 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2231 << D->getDeclKindName();
2232 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2233 }
2234 }
2235 }
2236
2237 // Import the context of this declaration.
2238 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2239 return Err;
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 NamedDecl *&ToD, SourceLocation &Loc) {
2259
2260 // Import the name of this declaration.
2261 if (Error Err = importInto(Name, D->getDeclName()))
2262 return Err;
2263
2264 // Import the location of this declaration.
2265 if (Error Err = importInto(Loc, D->getLocation()))
2266 return Err;
2267
2268 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2269 if (ToD)
2270 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2271 return Err;
2272
2273 return Error::success();
2274}
2275
2277 if (!FromD)
2278 return Error::success();
2279
2280 if (!ToD)
2281 if (Error Err = importInto(ToD, FromD))
2282 return Err;
2283
2284 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2285 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2286 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2287 !ToRecord->getDefinition()) {
2288 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2289 return Err;
2290 }
2291 }
2292 return Error::success();
2293 }
2294
2295 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2296 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2297 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2298 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2299 return Err;
2300 }
2301 }
2302 return Error::success();
2303 }
2304
2305 return Error::success();
2306}
2307
2308Error
2310 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2311 // NOTE: To.Name and To.Loc are already imported.
2312 // We only have to import To.LocInfo.
2313 switch (To.getName().getNameKind()) {
2320 return Error::success();
2321
2323 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2324 To.setCXXOperatorNameRange(*ToRangeOrErr);
2325 else
2326 return ToRangeOrErr.takeError();
2327 return Error::success();
2328 }
2330 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2331 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2332 else
2333 return LocOrErr.takeError();
2334 return Error::success();
2335 }
2339 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2340 To.setNamedTypeInfo(*ToTInfoOrErr);
2341 else
2342 return ToTInfoOrErr.takeError();
2343 return Error::success();
2344 }
2345 }
2346 llvm_unreachable("Unknown name kind.");
2347}
2348
2349Error
2351 if (Importer.isMinimalImport() && !ForceImport) {
2352 auto ToDCOrErr = Importer.ImportContext(FromDC);
2353 return ToDCOrErr.takeError();
2354 }
2355
2356 // We use strict error handling in case of records and enums, but not
2357 // with e.g. namespaces.
2358 //
2359 // FIXME Clients of the ASTImporter should be able to choose an
2360 // appropriate error handling strategy for their needs. For instance,
2361 // they may not want to mark an entire namespace as erroneous merely
2362 // because there is an ODR error with two typedefs. As another example,
2363 // the client may allow EnumConstantDecls with same names but with
2364 // different values in two distinct translation units.
2365 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2366
2367 auto MightNeedReordering = [](const Decl *D) {
2369 };
2370
2371 // Import everything that might need reordering first.
2372 Error ChildErrors = Error::success();
2373 for (auto *From : FromDC->decls()) {
2374 if (!MightNeedReordering(From))
2375 continue;
2376
2377 ExpectedDecl ImportedOrErr = import(From);
2378
2379 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2380 // want to make sure that we are also completing each FieldDecl. There
2381 // are currently cases where this does not happen and this is correctness
2382 // fix since operations such as code generation will expect this to be so.
2383 if (!ImportedOrErr) {
2384 HandleChildErrors.handleChildImportResult(ChildErrors,
2385 ImportedOrErr.takeError());
2386 continue;
2387 }
2388 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2389 Decl *ImportedDecl = *ImportedOrErr;
2390 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2391 if (FieldFrom && FieldTo) {
2392 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2393 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2394 }
2395 }
2396
2397 // We reorder declarations in RecordDecls because they may have another order
2398 // in the "to" context than they have in the "from" context. This may happen
2399 // e.g when we import a class like this:
2400 // struct declToImport {
2401 // int a = c + b;
2402 // int b = 1;
2403 // int c = 2;
2404 // };
2405 // During the import of `a` we import first the dependencies in sequence,
2406 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2407 // first removing the already imported members and then adding them in the
2408 // order as they appear in the "from" context.
2409 //
2410 // Keeping field order is vital because it determines structure layout.
2411 //
2412 // Here and below, we cannot call field_begin() method and its callers on
2413 // ToDC if it has an external storage. Calling field_begin() will
2414 // automatically load all the fields by calling
2415 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2416 // call ASTImporter::Import(). This is because the ExternalASTSource
2417 // interface in LLDB is implemented by the means of the ASTImporter. However,
2418 // calling an import at this point would result in an uncontrolled import, we
2419 // must avoid that.
2420
2421 auto ToDCOrErr = Importer.ImportContext(FromDC);
2422 if (!ToDCOrErr) {
2423 consumeError(std::move(ChildErrors));
2424 return ToDCOrErr.takeError();
2425 }
2426
2427 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2428 DeclContext *ToDC = *ToDCOrErr;
2429 // Remove all declarations, which may be in wrong order in the
2430 // lexical DeclContext and then add them in the proper order.
2431 for (auto *D : FromRD->decls()) {
2432 if (!MightNeedReordering(D))
2433 continue;
2434
2435 assert(D && "DC contains a null decl");
2436 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2437 // Remove only the decls which we successfully imported.
2438 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2439 // Remove the decl from its wrong place in the linked list.
2440 ToDC->removeDecl(ToD);
2441 // Add the decl to the end of the linked list.
2442 // This time it will be at the proper place because the enclosing for
2443 // loop iterates in the original (good) order of the decls.
2444 ToDC->addDeclInternal(ToD);
2445 }
2446 }
2447 }
2448
2449 // Import everything else.
2450 for (auto *From : FromDC->decls()) {
2451 if (MightNeedReordering(From))
2452 continue;
2453
2454 ExpectedDecl ImportedOrErr = import(From);
2455 if (!ImportedOrErr)
2456 HandleChildErrors.handleChildImportResult(ChildErrors,
2457 ImportedOrErr.takeError());
2458 }
2459
2460 return ChildErrors;
2461}
2462
2464 const FieldDecl *To) {
2465 RecordDecl *FromRecordDecl = nullptr;
2466 RecordDecl *ToRecordDecl = nullptr;
2467 // If we have a field that is an ArrayType we need to check if the array
2468 // element is a RecordDecl and if so we need to import the definition.
2469 QualType FromType = From->getType();
2470 QualType ToType = To->getType();
2471 if (FromType->isArrayType()) {
2472 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2473 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2474 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2475 }
2476
2477 if (!FromRecordDecl || !ToRecordDecl) {
2478 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2479 const RecordType *RecordTo = ToType->getAs<RecordType>();
2480
2481 if (RecordFrom && RecordTo) {
2482 FromRecordDecl = RecordFrom->getDecl();
2483 ToRecordDecl = RecordTo->getDecl();
2484 }
2485 }
2486
2487 if (FromRecordDecl && ToRecordDecl) {
2488 if (FromRecordDecl->isCompleteDefinition() &&
2489 !ToRecordDecl->isCompleteDefinition())
2490 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2491 }
2492
2493 return Error::success();
2494}
2495
2497 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2498 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2499 if (!ToDCOrErr)
2500 return ToDCOrErr.takeError();
2501 ToDC = *ToDCOrErr;
2502
2503 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2504 auto ToLexicalDCOrErr = Importer.ImportContext(
2505 FromD->getLexicalDeclContext());
2506 if (!ToLexicalDCOrErr)
2507 return ToLexicalDCOrErr.takeError();
2508 ToLexicalDC = *ToLexicalDCOrErr;
2509 } else
2510 ToLexicalDC = ToDC;
2511
2512 return Error::success();
2513}
2514
2516 const CXXRecordDecl *From, CXXRecordDecl *To) {
2517 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2518 "Import implicit methods to or from non-definition");
2519
2520 for (CXXMethodDecl *FromM : From->methods())
2521 if (FromM->isImplicit()) {
2522 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2523 if (!ToMOrErr)
2524 return ToMOrErr.takeError();
2525 }
2526
2527 return Error::success();
2528}
2529
2531 ASTImporter &Importer) {
2532 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2533 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2535 else
2536 return ToTypedefOrErr.takeError();
2537 }
2538 return Error::success();
2539}
2540
2542 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2543 auto DefinitionCompleter = [To]() {
2544 // There are cases in LLDB when we first import a class without its
2545 // members. The class will have DefinitionData, but no members. Then,
2546 // importDefinition is called from LLDB, which tries to get the members, so
2547 // when we get here, the class already has the DefinitionData set, so we
2548 // must unset the CompleteDefinition here to be able to complete again the
2549 // definition.
2550 To->setCompleteDefinition(false);
2551 To->completeDefinition();
2552 };
2553
2554 if (To->getDefinition() || To->isBeingDefined()) {
2555 if (Kind == IDK_Everything ||
2556 // In case of lambdas, the class already has a definition ptr set, but
2557 // the contained decls are not imported yet. Also, isBeingDefined was
2558 // set in CXXRecordDecl::CreateLambda. We must import the contained
2559 // decls here and finish the definition.
2560 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2561 if (To->isLambda()) {
2562 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2564 ToCaptures.reserve(FromCXXRD->capture_size());
2565 for (const auto &FromCapture : FromCXXRD->captures()) {
2566 if (auto ToCaptureOrErr = import(FromCapture))
2567 ToCaptures.push_back(*ToCaptureOrErr);
2568 else
2569 return ToCaptureOrErr.takeError();
2570 }
2571 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2572 ToCaptures);
2573 }
2574
2575 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2576 // Finish the definition of the lambda, set isBeingDefined to false.
2577 if (To->isLambda())
2578 DefinitionCompleter();
2579 return Result;
2580 }
2581
2582 return Error::success();
2583 }
2584
2585 To->startDefinition();
2586 // Set the definition to complete even if it is really not complete during
2587 // import. Some AST constructs (expressions) require the record layout
2588 // to be calculated (see 'clang::computeDependence') at the time they are
2589 // constructed. Import of such AST node is possible during import of the
2590 // same record, there is no way to have a completely defined record (all
2591 // fields imported) at that time without multiple AST import passes.
2592 if (!Importer.isMinimalImport())
2593 To->setCompleteDefinition(true);
2594 // Complete the definition even if error is returned.
2595 // The RecordDecl may be already part of the AST so it is better to
2596 // have it in complete state even if something is wrong with it.
2597 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2598
2599 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2600 return Err;
2601
2602 // Add base classes.
2603 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2604 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2605 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2606
2607 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2608 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2609
2610 #define FIELD(Name, Width, Merge) \
2611 ToData.Name = FromData.Name;
2612 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2613
2614 // Copy over the data stored in RecordDeclBits
2615 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2616
2618 for (const auto &Base1 : FromCXX->bases()) {
2619 ExpectedType TyOrErr = import(Base1.getType());
2620 if (!TyOrErr)
2621 return TyOrErr.takeError();
2622
2623 SourceLocation EllipsisLoc;
2624 if (Base1.isPackExpansion()) {
2625 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2626 EllipsisLoc = *LocOrErr;
2627 else
2628 return LocOrErr.takeError();
2629 }
2630
2631 // Ensure that we have a definition for the base.
2632 if (Error Err =
2633 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2634 return Err;
2635
2636 auto RangeOrErr = import(Base1.getSourceRange());
2637 if (!RangeOrErr)
2638 return RangeOrErr.takeError();
2639
2640 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2641 if (!TSIOrErr)
2642 return TSIOrErr.takeError();
2643
2644 Bases.push_back(
2645 new (Importer.getToContext()) CXXBaseSpecifier(
2646 *RangeOrErr,
2647 Base1.isVirtual(),
2648 Base1.isBaseOfClass(),
2649 Base1.getAccessSpecifierAsWritten(),
2650 *TSIOrErr,
2651 EllipsisLoc));
2652 }
2653 if (!Bases.empty())
2654 ToCXX->setBases(Bases.data(), Bases.size());
2655 }
2656
2657 if (shouldForceImportDeclContext(Kind)) {
2658 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2659 return Err;
2660 }
2661
2662 return Error::success();
2663}
2664
2666 if (To->getAnyInitializer())
2667 return Error::success();
2668
2669 Expr *FromInit = From->getInit();
2670 if (!FromInit)
2671 return Error::success();
2672
2673 ExpectedExpr ToInitOrErr = import(FromInit);
2674 if (!ToInitOrErr)
2675 return ToInitOrErr.takeError();
2676
2677 To->setInit(*ToInitOrErr);
2678 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2679 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2680 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2681 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2682 // FIXME: Also import the initializer value.
2683 }
2684
2685 // FIXME: Other bits to merge?
2686 return Error::success();
2687}
2688
2690 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2691 if (To->getDefinition() || To->isBeingDefined()) {
2692 if (Kind == IDK_Everything)
2693 return ImportDeclContext(From, /*ForceImport=*/true);
2694 return Error::success();
2695 }
2696
2697 To->startDefinition();
2698
2699 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2700 return Err;
2701
2702 ExpectedType ToTypeOrErr =
2703 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2704 if (!ToTypeOrErr)
2705 return ToTypeOrErr.takeError();
2706
2707 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2708 if (!ToPromotionTypeOrErr)
2709 return ToPromotionTypeOrErr.takeError();
2710
2712 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2713 return Err;
2714
2715 // FIXME: we might need to merge the number of positive or negative bits
2716 // if the enumerator lists don't match.
2717 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2718 From->getNumPositiveBits(),
2719 From->getNumNegativeBits());
2720 return Error::success();
2721}
2722
2726 for (const auto &Arg : FromArgs) {
2727 if (auto ToOrErr = import(Arg))
2728 ToArgs.push_back(*ToOrErr);
2729 else
2730 return ToOrErr.takeError();
2731 }
2732
2733 return Error::success();
2734}
2735
2736// FIXME: Do not forget to remove this and use only 'import'.
2739 return import(From);
2740}
2741
2742template <typename InContainerTy>
2744 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2745 for (const auto &FromLoc : Container) {
2746 if (auto ToLocOrErr = import(FromLoc))
2747 ToTAInfo.addArgument(*ToLocOrErr);
2748 else
2749 return ToLocOrErr.takeError();
2750 }
2751 return Error::success();
2752}
2753
2759
2760bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2761 bool IgnoreTemplateParmDepth) {
2762 // Eliminate a potential failure point where we attempt to re-import
2763 // something we're trying to import while completing ToRecord.
2764 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2765 if (ToOrigin) {
2766 To = ToOrigin;
2767 }
2768
2770 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2771 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2773 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2774 IgnoreTemplateParmDepth);
2775 return Ctx.IsEquivalent(From, To);
2776}
2777
2779 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2780 << D->getDeclKindName();
2781 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2782}
2783
2785 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2786 << D->getDeclKindName();
2787 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2788}
2789
2791 // Import the context of this declaration.
2792 DeclContext *DC, *LexicalDC;
2793 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2794 return std::move(Err);
2795
2796 // Import the location of this declaration.
2797 ExpectedSLoc LocOrErr = import(D->getLocation());
2798 if (!LocOrErr)
2799 return LocOrErr.takeError();
2800
2801 EmptyDecl *ToD;
2802 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2803 return ToD;
2804
2805 ToD->setLexicalDeclContext(LexicalDC);
2806 LexicalDC->addDeclInternal(ToD);
2807 return ToD;
2808}
2809
2811 TranslationUnitDecl *ToD =
2812 Importer.getToContext().getTranslationUnitDecl();
2813
2814 Importer.MapImported(D, ToD);
2815
2816 return ToD;
2817}
2818
2820 Error Err = Error::success();
2821 Expr *ToAsmString = importChecked(Err, D->getAsmStringExpr());
2822 SourceLocation ToAsmLoc = importChecked(Err, D->getAsmLoc());
2823 SourceLocation ToRParenLoc = importChecked(Err, D->getRParenLoc());
2824 if (Err)
2825 return std::move(Err);
2826
2827 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2828 if (!DCOrErr)
2829 return DCOrErr.takeError();
2830 DeclContext *DC = *DCOrErr;
2831
2832 FileScopeAsmDecl *ToD;
2833 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToAsmString,
2834 ToAsmLoc, ToRParenLoc))
2835 return ToD;
2836
2837 ToD->setLexicalDeclContext(DC);
2838 DC->addDeclInternal(ToD);
2839
2840 return ToD;
2841}
2842
2844 DeclContext *DC, *LexicalDC;
2845 DeclarationName Name;
2846 SourceLocation Loc;
2847 NamedDecl *ToND;
2848 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2849 return std::move(Err);
2850 if (ToND)
2851 return ToND;
2852
2853 BindingDecl *ToD;
2854 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2855 Name.getAsIdentifierInfo(), D->getType()))
2856 return ToD;
2857
2858 Error Err = Error::success();
2859 QualType ToType = importChecked(Err, D->getType());
2860 Expr *ToBinding = importChecked(Err, D->getBinding());
2861 DecompositionDecl *ToDecomposedDecl =
2863 if (Err)
2864 return std::move(Err);
2865
2866 ToD->setBinding(ToType, ToBinding);
2867 ToD->setDecomposedDecl(ToDecomposedDecl);
2868 addDeclToContexts(D, ToD);
2869
2870 return ToD;
2871}
2872
2874 ExpectedSLoc LocOrErr = import(D->getLocation());
2875 if (!LocOrErr)
2876 return LocOrErr.takeError();
2877 auto ColonLocOrErr = import(D->getColonLoc());
2878 if (!ColonLocOrErr)
2879 return ColonLocOrErr.takeError();
2880
2881 // Import the context of this declaration.
2882 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2883 if (!DCOrErr)
2884 return DCOrErr.takeError();
2885 DeclContext *DC = *DCOrErr;
2886
2887 AccessSpecDecl *ToD;
2888 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2889 DC, *LocOrErr, *ColonLocOrErr))
2890 return ToD;
2891
2892 // Lexical DeclContext and Semantic DeclContext
2893 // is always the same for the accessSpec.
2894 ToD->setLexicalDeclContext(DC);
2895 DC->addDeclInternal(ToD);
2896
2897 return ToD;
2898}
2899
2901 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2902 if (!DCOrErr)
2903 return DCOrErr.takeError();
2904 DeclContext *DC = *DCOrErr;
2905 DeclContext *LexicalDC = DC;
2906
2907 Error Err = Error::success();
2908 auto ToLocation = importChecked(Err, D->getLocation());
2909 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2910 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2911 auto ToMessage = importChecked(Err, D->getMessage());
2912 if (Err)
2913 return std::move(Err);
2914
2915 StaticAssertDecl *ToD;
2916 if (GetImportedOrCreateDecl(
2917 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2918 ToRParenLoc, D->isFailed()))
2919 return ToD;
2920
2921 ToD->setLexicalDeclContext(LexicalDC);
2922 LexicalDC->addDeclInternal(ToD);
2923 return ToD;
2924}
2925
2928 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2929 if (!DCOrErr)
2930 return DCOrErr.takeError();
2931 DeclContext *DC = *DCOrErr;
2932 DeclContext *LexicalDC = DC;
2933
2934 Error Err = Error::success();
2935 auto ToLocation = importChecked(Err, D->getLocation());
2936 auto ToExpansion = importChecked(Err, D->getExpansionPattern());
2937 auto ToIndex = importChecked(Err, D->getIndexTemplateParm());
2938 auto ToInstantiations = importChecked(Err, D->getInstantiations());
2939 if (Err)
2940 return std::move(Err);
2941
2943 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToLocation,
2944 ToIndex))
2945 return ToD;
2946
2947 ToD->setExpansionPattern(ToExpansion);
2948 ToD->setInstantiations(ToInstantiations);
2949 ToD->setLexicalDeclContext(LexicalDC);
2950 LexicalDC->addDeclInternal(ToD);
2951 return ToD;
2952}
2953
2955 // Import the major distinguishing characteristics of this namespace.
2956 DeclContext *DC, *LexicalDC;
2957 DeclarationName Name;
2958 SourceLocation Loc;
2959 NamedDecl *ToD;
2960 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2961 return std::move(Err);
2962 if (ToD)
2963 return ToD;
2964
2965 NamespaceDecl *MergeWithNamespace = nullptr;
2966 if (!Name) {
2967 // This is an anonymous namespace. Adopt an existing anonymous
2968 // namespace if we can.
2969 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2970 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2971 MergeWithNamespace = TU->getAnonymousNamespace();
2972 else
2973 MergeWithNamespace =
2974 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2975 } else {
2976 SmallVector<NamedDecl *, 4> ConflictingDecls;
2977 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2978 for (auto *FoundDecl : FoundDecls) {
2979 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2980 continue;
2981
2982 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2983 MergeWithNamespace = FoundNS;
2984 ConflictingDecls.clear();
2985 break;
2986 }
2987
2988 ConflictingDecls.push_back(FoundDecl);
2989 }
2990
2991 if (!ConflictingDecls.empty()) {
2992 ExpectedName NameOrErr = Importer.HandleNameConflict(
2993 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2994 ConflictingDecls.size());
2995 if (NameOrErr)
2996 Name = NameOrErr.get();
2997 else
2998 return NameOrErr.takeError();
2999 }
3000 }
3001
3002 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3003 if (!BeginLocOrErr)
3004 return BeginLocOrErr.takeError();
3005 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
3006 if (!RBraceLocOrErr)
3007 return RBraceLocOrErr.takeError();
3008
3009 // Create the "to" namespace, if needed.
3010 NamespaceDecl *ToNamespace = MergeWithNamespace;
3011 if (!ToNamespace) {
3012 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
3013 D->isInline(), *BeginLocOrErr, Loc,
3014 Name.getAsIdentifierInfo(),
3015 /*PrevDecl=*/nullptr, D->isNested()))
3016 return ToNamespace;
3017 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
3018 ToNamespace->setLexicalDeclContext(LexicalDC);
3019 LexicalDC->addDeclInternal(ToNamespace);
3020
3021 // If this is an anonymous namespace, register it as the anonymous
3022 // namespace within its context.
3023 if (!Name) {
3024 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3025 TU->setAnonymousNamespace(ToNamespace);
3026 else
3027 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
3028 }
3029 }
3030 Importer.MapImported(D, ToNamespace);
3031
3032 if (Error Err = ImportDeclContext(D))
3033 return std::move(Err);
3034
3035 return ToNamespace;
3036}
3037
3039 // Import the major distinguishing characteristics of this namespace.
3040 DeclContext *DC, *LexicalDC;
3041 DeclarationName Name;
3042 SourceLocation Loc;
3043 NamedDecl *LookupD;
3044 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
3045 return std::move(Err);
3046 if (LookupD)
3047 return LookupD;
3048
3049 // NOTE: No conflict resolution is done for namespace aliases now.
3050
3051 Error Err = Error::success();
3052 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
3053 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
3054 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3055 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
3056 auto ToNamespace = importChecked(Err, D->getNamespace());
3057 if (Err)
3058 return std::move(Err);
3059
3060 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
3061
3062 NamespaceAliasDecl *ToD;
3063 if (GetImportedOrCreateDecl(
3064 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
3065 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
3066 return ToD;
3067
3068 ToD->setLexicalDeclContext(LexicalDC);
3069 LexicalDC->addDeclInternal(ToD);
3070
3071 return ToD;
3072}
3073
3076 // Import the major distinguishing characteristics of this typedef.
3077 DeclarationName Name;
3078 SourceLocation Loc;
3079 NamedDecl *ToD;
3080 // Do not import the DeclContext, we will import it once the TypedefNameDecl
3081 // is created.
3082 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
3083 return std::move(Err);
3084 if (ToD)
3085 return ToD;
3086
3087 DeclContext *DC = cast_or_null<DeclContext>(
3088 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
3089 DeclContext *LexicalDC =
3090 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
3092
3093 // If this typedef is not in block scope, determine whether we've
3094 // seen a typedef with the same name (that we can merge with) or any
3095 // other entity by that name (which name lookup could conflict with).
3096 // Note: Repeated typedefs are not valid in C99:
3097 // 'typedef int T; typedef int T;' is invalid
3098 // We do not care about this now.
3099 if (DC && !DC->isFunctionOrMethod()) {
3100 SmallVector<NamedDecl *, 4> ConflictingDecls;
3101 unsigned IDNS = Decl::IDNS_Ordinary;
3102 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3103 for (auto *FoundDecl : FoundDecls) {
3104 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3105 continue;
3106 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3107 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3108 continue;
3109
3110 QualType FromUT = D->getUnderlyingType();
3111 QualType FoundUT = FoundTypedef->getUnderlyingType();
3112 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3113 // If the underlying declarations are unnamed records these can be
3114 // imported as different types. We should create a distinct typedef
3115 // node in this case.
3116 // If we found an existing underlying type with a record in a
3117 // different context (than the imported), this is already reason for
3118 // having distinct typedef nodes for these.
3119 // Again this can create situation like
3120 // 'typedef int T; typedef int T;' but this is hard to avoid without
3121 // a rename strategy at import.
3122 if (!FromUT.isNull() && !FoundUT.isNull()) {
3123 RecordDecl *FromR = FromUT->getAsRecordDecl();
3124 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3125 if (FromR && FoundR &&
3126 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3127 continue;
3128 }
3129 // If the "From" context has a complete underlying type but we
3130 // already have a complete underlying type then return with that.
3131 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3132 return Importer.MapImported(D, FoundTypedef);
3133 // FIXME Handle redecl chain. When you do that make consistent changes
3134 // in ASTImporterLookupTable too.
3135 } else {
3136 ConflictingDecls.push_back(FoundDecl);
3137 }
3138 }
3139 }
3140
3141 if (!ConflictingDecls.empty()) {
3142 ExpectedName NameOrErr = Importer.HandleNameConflict(
3143 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3144 if (NameOrErr)
3145 Name = NameOrErr.get();
3146 else
3147 return NameOrErr.takeError();
3148 }
3149 }
3150
3151 Error Err = Error::success();
3153 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3154 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3155 if (Err)
3156 return std::move(Err);
3157
3158 // Create the new typedef node.
3159 // FIXME: ToUnderlyingType is not used.
3160 (void)ToUnderlyingType;
3161 TypedefNameDecl *ToTypedef;
3162 if (IsAlias) {
3163 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3164 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3165 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3166 return ToTypedef;
3167 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3168 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3169 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3170 return ToTypedef;
3171
3172 // Import the DeclContext and set it to the Typedef.
3173 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3174 return std::move(Err);
3175 ToTypedef->setDeclContext(DC);
3176 ToTypedef->setLexicalDeclContext(LexicalDC);
3177 // Add to the lookupTable because we could not do that in MapImported.
3178 Importer.AddToLookupTable(ToTypedef);
3179
3180 ToTypedef->setAccess(D->getAccess());
3181
3182 // Templated declarations should not appear in DeclContext.
3183 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3184 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3185 LexicalDC->addDeclInternal(ToTypedef);
3186
3187 return ToTypedef;
3188}
3189
3193
3197
3200 // Import the major distinguishing characteristics of this typedef.
3201 DeclContext *DC, *LexicalDC;
3202 DeclarationName Name;
3203 SourceLocation Loc;
3204 NamedDecl *FoundD;
3205 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3206 return std::move(Err);
3207 if (FoundD)
3208 return FoundD;
3209
3210 // If this typedef is not in block scope, determine whether we've
3211 // seen a typedef with the same name (that we can merge with) or any
3212 // other entity by that name (which name lookup could conflict with).
3213 if (!DC->isFunctionOrMethod()) {
3214 SmallVector<NamedDecl *, 4> ConflictingDecls;
3215 unsigned IDNS = Decl::IDNS_Ordinary;
3216 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3217 for (auto *FoundDecl : FoundDecls) {
3218 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3219 continue;
3220 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3221 if (IsStructuralMatch(D, FoundAlias))
3222 return Importer.MapImported(D, FoundAlias);
3223 ConflictingDecls.push_back(FoundDecl);
3224 }
3225 }
3226
3227 if (!ConflictingDecls.empty()) {
3228 ExpectedName NameOrErr = Importer.HandleNameConflict(
3229 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3230 if (NameOrErr)
3231 Name = NameOrErr.get();
3232 else
3233 return NameOrErr.takeError();
3234 }
3235 }
3236
3237 Error Err = Error::success();
3238 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3239 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3240 if (Err)
3241 return std::move(Err);
3242
3243 TypeAliasTemplateDecl *ToAlias;
3244 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3245 Name, ToTemplateParameters, ToTemplatedDecl))
3246 return ToAlias;
3247
3248 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3249
3250 ToAlias->setAccess(D->getAccess());
3251 ToAlias->setLexicalDeclContext(LexicalDC);
3252 LexicalDC->addDeclInternal(ToAlias);
3253 if (DC != Importer.getToContext().getTranslationUnitDecl())
3254 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3255 return ToAlias;
3256}
3257
3259 // Import the major distinguishing characteristics of this label.
3260 DeclContext *DC, *LexicalDC;
3261 DeclarationName Name;
3262 SourceLocation Loc;
3263 NamedDecl *ToD;
3264 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3265 return std::move(Err);
3266 if (ToD)
3267 return ToD;
3268
3269 assert(LexicalDC->isFunctionOrMethod());
3270
3271 LabelDecl *ToLabel;
3272 if (D->isGnuLocal()) {
3273 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3274 if (!BeginLocOrErr)
3275 return BeginLocOrErr.takeError();
3276 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3277 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3278 return ToLabel;
3279
3280 } else {
3281 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3282 Name.getAsIdentifierInfo()))
3283 return ToLabel;
3284
3285 }
3286
3287 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3288 if (!ToStmtOrErr)
3289 return ToStmtOrErr.takeError();
3290
3291 ToLabel->setStmt(*ToStmtOrErr);
3292 ToLabel->setLexicalDeclContext(LexicalDC);
3293 LexicalDC->addDeclInternal(ToLabel);
3294 return ToLabel;
3295}
3296
3298 // Import the major distinguishing characteristics of this enum.
3299 DeclContext *DC, *LexicalDC;
3300 DeclarationName Name;
3301 SourceLocation Loc;
3302 NamedDecl *ToD;
3303 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3304 return std::move(Err);
3305 if (ToD)
3306 return ToD;
3307
3308 // Figure out what enum name we're looking for.
3309 unsigned IDNS = Decl::IDNS_Tag;
3310 DeclarationName SearchName = Name;
3311 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3312 if (Error Err = importInto(
3313 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3314 return std::move(Err);
3315 IDNS = Decl::IDNS_Ordinary;
3316 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3317 IDNS |= Decl::IDNS_Ordinary;
3318
3319 // We may already have an enum of the same name; try to find and match it.
3320 EnumDecl *PrevDecl = nullptr;
3321 if (!DC->isFunctionOrMethod()) {
3322 SmallVector<NamedDecl *, 4> ConflictingDecls;
3323 auto FoundDecls =
3324 Importer.findDeclsInToCtx(DC, SearchName);
3325 for (auto *FoundDecl : FoundDecls) {
3326 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3327 continue;
3328
3329 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3330 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3331 FoundDecl = Tag->getDecl();
3332 }
3333
3334 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3335 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3336 continue;
3337 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3338 EnumDecl *FoundDef = FoundEnum->getDefinition();
3339 if (D->isThisDeclarationADefinition() && FoundDef)
3340 return Importer.MapImported(D, FoundDef);
3341 PrevDecl = FoundEnum->getMostRecentDecl();
3342 break;
3343 }
3344 ConflictingDecls.push_back(FoundDecl);
3345 }
3346 }
3347
3348 // In case of unnamed enums, we try to find an existing similar one, if none
3349 // was found, perform the import always.
3350 // Structural in-equivalence is not detected in this way here, but it may
3351 // be found when the parent decl is imported (if the enum is part of a
3352 // class). To make this totally exact a more difficult solution is needed.
3353 if (SearchName && !ConflictingDecls.empty()) {
3354 ExpectedName NameOrErr = Importer.HandleNameConflict(
3355 SearchName, DC, IDNS, ConflictingDecls.data(),
3356 ConflictingDecls.size());
3357 if (NameOrErr)
3358 Name = NameOrErr.get();
3359 else
3360 return NameOrErr.takeError();
3361 }
3362 }
3363
3364 Error Err = Error::success();
3365 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3366 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3367 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3368 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3369 if (Err)
3370 return std::move(Err);
3371
3372 // Create the enum declaration.
3373 EnumDecl *D2;
3374 if (GetImportedOrCreateDecl(
3375 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3376 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3377 D->isScopedUsingClassTag(), D->isFixed()))
3378 return D2;
3379
3380 D2->setQualifierInfo(ToQualifierLoc);
3381 D2->setIntegerType(ToIntegerType);
3382 D2->setBraceRange(ToBraceRange);
3383 D2->setAccess(D->getAccess());
3384 D2->setLexicalDeclContext(LexicalDC);
3385 addDeclToContexts(D, D2);
3386
3388 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3389 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3390 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3391 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3392 else
3393 return ToInstOrErr.takeError();
3394 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3396 else
3397 return POIOrErr.takeError();
3398 }
3399
3400 // Import the definition
3401 if (D->isCompleteDefinition())
3402 if (Error Err = ImportDefinition(D, D2))
3403 return std::move(Err);
3404
3405 return D2;
3406}
3407
3409 bool IsFriendTemplate = false;
3410 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3411 IsFriendTemplate =
3412 DCXX->getDescribedClassTemplate() &&
3413 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3415 }
3416
3417 // Import the major distinguishing characteristics of this record.
3418 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3419 DeclarationName Name;
3420 SourceLocation Loc;
3421 NamedDecl *ToD = nullptr;
3422 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3423 return std::move(Err);
3424 if (ToD)
3425 return ToD;
3426
3427 // Figure out what structure name we're looking for.
3428 unsigned IDNS = Decl::IDNS_Tag;
3429 DeclarationName SearchName = Name;
3430 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3431 if (Error Err = importInto(
3432 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3433 return std::move(Err);
3434 IDNS = Decl::IDNS_Ordinary;
3435 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3437
3438 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3439 : DC->isDependentContext();
3440 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3441
3442 // We may already have a record of the same name; try to find and match it.
3443 RecordDecl *PrevDecl = nullptr;
3444 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3445 SmallVector<NamedDecl *, 4> ConflictingDecls;
3446 auto FoundDecls =
3447 Importer.findDeclsInToCtx(DC, SearchName);
3448 if (!FoundDecls.empty()) {
3449 // We're going to have to compare D against potentially conflicting Decls,
3450 // so complete it.
3453 }
3454
3455 for (auto *FoundDecl : FoundDecls) {
3456 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3457 continue;
3458
3459 Decl *Found = FoundDecl;
3460 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3461 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3462 Found = Tag->getDecl();
3463 }
3464
3465 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3466 // Do not emit false positive diagnostic in case of unnamed
3467 // struct/union and in case of anonymous structs. Would be false
3468 // because there may be several anonymous/unnamed structs in a class.
3469 // E.g. these are both valid:
3470 // struct A { // unnamed structs
3471 // struct { struct A *next; } entry0;
3472 // struct { struct A *next; } entry1;
3473 // };
3474 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3475 if (!SearchName)
3476 if (!IsStructuralMatch(D, FoundRecord, false))
3477 continue;
3478
3479 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3480 continue;
3481
3482 if (IsStructuralMatch(D, FoundRecord)) {
3483 RecordDecl *FoundDef = FoundRecord->getDefinition();
3484 if (D->isThisDeclarationADefinition() && FoundDef) {
3485 // FIXME: Structural equivalence check should check for same
3486 // user-defined methods.
3487 Importer.MapImported(D, FoundDef);
3488 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3489 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3490 assert(FoundCXX && "Record type mismatch");
3491
3492 if (!Importer.isMinimalImport())
3493 // FoundDef may not have every implicit method that D has
3494 // because implicit methods are created only if they are used.
3495 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3496 return std::move(Err);
3497 }
3498 // FIXME: We can return FoundDef here.
3499 }
3500 PrevDecl = FoundRecord->getMostRecentDecl();
3501 break;
3502 }
3503 ConflictingDecls.push_back(FoundDecl);
3504 } // kind is RecordDecl
3505 } // for
3506
3507 if (!ConflictingDecls.empty() && SearchName) {
3508 ExpectedName NameOrErr = Importer.HandleNameConflict(
3509 SearchName, DC, IDNS, ConflictingDecls.data(),
3510 ConflictingDecls.size());
3511 if (NameOrErr)
3512 Name = NameOrErr.get();
3513 else
3514 return NameOrErr.takeError();
3515 }
3516 }
3517
3518 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3519 if (!BeginLocOrErr)
3520 return BeginLocOrErr.takeError();
3521
3522 // Create the record declaration.
3523 RecordDecl *D2 = nullptr;
3524 CXXRecordDecl *D2CXX = nullptr;
3525 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3526 if (DCXX->isLambda()) {
3527 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3528 if (!TInfoOrErr)
3529 return TInfoOrErr.takeError();
3530 if (GetImportedOrCreateSpecialDecl(
3531 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3532 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3533 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3534 return D2CXX;
3535 Decl *ContextDecl = DCXX->getLambdaContextDecl();
3536 ExpectedDecl CDeclOrErr = import(ContextDecl);
3537 if (!CDeclOrErr)
3538 return CDeclOrErr.takeError();
3539 if (ContextDecl != nullptr) {
3540 D2CXX->setLambdaContextDecl(*CDeclOrErr);
3541 }
3542 D2CXX->setLambdaNumbering(DCXX->getLambdaNumbering());
3543 } else {
3544 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3545 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3546 Name.getAsIdentifierInfo(),
3547 cast_or_null<CXXRecordDecl>(PrevDecl)))
3548 return D2CXX;
3549 }
3550
3551 D2 = D2CXX;
3552 D2->setAccess(D->getAccess());
3553 D2->setLexicalDeclContext(LexicalDC);
3554 addDeclToContexts(D, D2);
3555
3556 if (ClassTemplateDecl *FromDescribed =
3557 DCXX->getDescribedClassTemplate()) {
3558 ClassTemplateDecl *ToDescribed;
3559 if (Error Err = importInto(ToDescribed, FromDescribed))
3560 return std::move(Err);
3561 D2CXX->setDescribedClassTemplate(ToDescribed);
3562 } else if (MemberSpecializationInfo *MemberInfo =
3563 DCXX->getMemberSpecializationInfo()) {
3565 MemberInfo->getTemplateSpecializationKind();
3567
3568 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3569 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3570 else
3571 return ToInstOrErr.takeError();
3572
3573 if (ExpectedSLoc POIOrErr =
3574 import(MemberInfo->getPointOfInstantiation()))
3576 *POIOrErr);
3577 else
3578 return POIOrErr.takeError();
3579 }
3580
3581 } else {
3582 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3583 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3584 Name.getAsIdentifierInfo(), PrevDecl))
3585 return D2;
3586 D2->setLexicalDeclContext(LexicalDC);
3587 addDeclToContexts(D, D2);
3588 }
3589
3590 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3591 D2->setBraceRange(*BraceRangeOrErr);
3592 else
3593 return BraceRangeOrErr.takeError();
3594 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3595 D2->setQualifierInfo(*QualifierLocOrErr);
3596 else
3597 return QualifierLocOrErr.takeError();
3598
3599 if (D->isAnonymousStructOrUnion())
3600 D2->setAnonymousStructOrUnion(true);
3601
3602 if (D->isCompleteDefinition())
3603 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3604 return std::move(Err);
3605
3606 return D2;
3607}
3608
3610 // Import the major distinguishing characteristics of this enumerator.
3611 DeclContext *DC, *LexicalDC;
3612 DeclarationName Name;
3613 SourceLocation Loc;
3614 NamedDecl *ToD;
3615 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3616 return std::move(Err);
3617 if (ToD)
3618 return ToD;
3619
3620 // Determine whether there are any other declarations with the same name and
3621 // in the same context.
3622 if (!LexicalDC->isFunctionOrMethod()) {
3623 SmallVector<NamedDecl *, 4> ConflictingDecls;
3624 unsigned IDNS = Decl::IDNS_Ordinary;
3625 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3626 for (auto *FoundDecl : FoundDecls) {
3627 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3628 continue;
3629
3630 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3631 if (IsStructuralMatch(D, FoundEnumConstant))
3632 return Importer.MapImported(D, FoundEnumConstant);
3633 ConflictingDecls.push_back(FoundDecl);
3634 }
3635 }
3636
3637 if (!ConflictingDecls.empty()) {
3638 ExpectedName NameOrErr = Importer.HandleNameConflict(
3639 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3640 if (NameOrErr)
3641 Name = NameOrErr.get();
3642 else
3643 return NameOrErr.takeError();
3644 }
3645 }
3646
3647 ExpectedType TypeOrErr = import(D->getType());
3648 if (!TypeOrErr)
3649 return TypeOrErr.takeError();
3650
3651 ExpectedExpr InitOrErr = import(D->getInitExpr());
3652 if (!InitOrErr)
3653 return InitOrErr.takeError();
3654
3655 EnumConstantDecl *ToEnumerator;
3656 if (GetImportedOrCreateDecl(
3657 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3658 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3659 return ToEnumerator;
3660
3661 ToEnumerator->setAccess(D->getAccess());
3662 ToEnumerator->setLexicalDeclContext(LexicalDC);
3663 LexicalDC->addDeclInternal(ToEnumerator);
3664 return ToEnumerator;
3665}
3666
3667template <typename DeclTy>
3669 DeclTy *ToD) {
3671 FromD->getTemplateParameterLists();
3672 if (FromTPLs.empty())
3673 return Error::success();
3674 SmallVector<TemplateParameterList *, 2> ToTPLists(FromTPLs.size());
3675 for (unsigned int I = 0; I < FromTPLs.size(); ++I)
3676 if (Expected<TemplateParameterList *> ToTPListOrErr = import(FromTPLs[I]))
3677 ToTPLists[I] = *ToTPListOrErr;
3678 else
3679 return ToTPListOrErr.takeError();
3680 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3681 return Error::success();
3682}
3683
3685 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3686 switch (FromFD->getTemplatedKind()) {
3689 return Error::success();
3690
3692 if (Expected<FunctionDecl *> InstFDOrErr =
3693 import(FromFD->getInstantiatedFromDecl()))
3694 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3695 return Error::success();
3698
3699 if (Expected<FunctionDecl *> InstFDOrErr =
3700 import(FromFD->getInstantiatedFromMemberFunction()))
3701 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3702 else
3703 return InstFDOrErr.takeError();
3704
3705 if (ExpectedSLoc POIOrErr = import(
3708 else
3709 return POIOrErr.takeError();
3710
3711 return Error::success();
3712 }
3713
3715 auto FunctionAndArgsOrErr =
3717 if (!FunctionAndArgsOrErr)
3718 return FunctionAndArgsOrErr.takeError();
3719
3721 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3722
3723 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3724 TemplateArgumentListInfo ToTAInfo;
3725 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3726 if (FromTAArgsAsWritten)
3728 *FromTAArgsAsWritten, ToTAInfo))
3729 return Err;
3730
3731 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3732 if (!POIOrErr)
3733 return POIOrErr.takeError();
3734
3735 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3736 return Err;
3737
3738 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3739 ToFD->setFunctionTemplateSpecialization(
3740 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /*InsertToken=*/{}, TSK,
3741 FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3742 return Error::success();
3743 }
3744
3746 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3747 UnresolvedSet<8> Candidates;
3748 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3749 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3750 Candidates.addDecl(*ToFTDOrErr);
3751 else
3752 return ToFTDOrErr.takeError();
3753 }
3754
3755 // Import TemplateArgumentListInfo.
3756 TemplateArgumentListInfo ToTAInfo;
3757 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3758 if (FromTAArgsAsWritten)
3759 if (Error Err =
3760 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3761 return Err;
3762
3764 Importer.getToContext(), Candidates,
3765 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3766 return Error::success();
3767 }
3768 }
3769 llvm_unreachable("All cases should be covered!");
3770}
3771
3774 auto FunctionAndArgsOrErr =
3776 if (!FunctionAndArgsOrErr)
3777 return FunctionAndArgsOrErr.takeError();
3778
3780 TemplateArgsTy ToTemplArgs;
3781 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3782 llvm::FoldingSetInsertToken InsertToken;
3783 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertToken);
3784 return FoundSpec;
3785}
3786
3788 FunctionDecl *ToFD) {
3789 if (Stmt *FromBody = FromFD->getBody()) {
3790 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3791 ToFD->setBody(*ToBodyOrErr);
3792 else
3793 return ToBodyOrErr.takeError();
3794 }
3795 return Error::success();
3796}
3797
3799ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3800 Expr *ExplicitExpr = ESpec.getExpr();
3801 if (ExplicitExpr)
3802 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3803 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3804}
3805
3807
3809 auto RedeclIt = Redecls.begin();
3810 // Import the first part of the decl chain. I.e. import all previous
3811 // declarations starting from the canonical decl.
3812 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3813 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3814 if (!ToRedeclOrErr)
3815 return ToRedeclOrErr.takeError();
3816 }
3817 assert(*RedeclIt == D);
3818
3819 // Import the major distinguishing characteristics of this function.
3820 DeclContext *DC, *LexicalDC;
3821 DeclarationName Name;
3822 SourceLocation Loc;
3823 NamedDecl *ToD;
3824 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3825 return std::move(Err);
3826 if (ToD)
3827 return ToD;
3828
3829 FunctionDecl *FoundByLookup = nullptr;
3831
3832 // If this is a function template specialization, then try to find the same
3833 // existing specialization in the "to" context. The lookup below will not
3834 // find any specialization, but would find the primary template; thus, we
3835 // have to skip normal lookup in case of specializations.
3836 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3837 if (D->getTemplatedKind() ==
3839 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3840 if (!FoundFunctionOrErr)
3841 return FoundFunctionOrErr.takeError();
3842 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3843 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3844 return Def;
3845 FoundByLookup = FoundFunction;
3846 }
3847 }
3848 // Try to find a function in our own ("to") context with the same name, same
3849 // type, and in the same context as the function we're importing.
3850 else if (!LexicalDC->isFunctionOrMethod()) {
3851 SmallVector<NamedDecl *, 4> ConflictingDecls;
3853 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3854 for (auto *FoundDecl : FoundDecls) {
3855 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3856 continue;
3857
3858 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3859 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3860 continue;
3861
3862 if (IsStructuralMatch(D, FoundFunction)) {
3863 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3864 return Def;
3865 FoundByLookup = FoundFunction;
3866 break;
3867 }
3868 // FIXME: Check for overloading more carefully, e.g., by boosting
3869 // Sema::IsOverload out to the AST library.
3870
3871 // Function overloading is okay in C++.
3872 if (Importer.getToContext().getLangOpts().CPlusPlus)
3873 continue;
3874
3875 // Complain about inconsistent function types.
3876 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3877 << Name << D->getType() << FoundFunction->getType();
3878 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3879 << FoundFunction->getType();
3880 ConflictingDecls.push_back(FoundDecl);
3881 }
3882 }
3883
3884 if (!ConflictingDecls.empty()) {
3885 ExpectedName NameOrErr = Importer.HandleNameConflict(
3886 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3887 if (NameOrErr)
3888 Name = NameOrErr.get();
3889 else
3890 return NameOrErr.takeError();
3891 }
3892 }
3893
3894 // We do not allow more than one in-class declaration of a function. This is
3895 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3896 // assumes there is only one in-class declaration. Building a redecl
3897 // chain would result in more than one in-class declaration for
3898 // overrides (even if they are part of the same redecl chain inside the
3899 // derived class.)
3900 if (FoundByLookup) {
3901 if (isa<CXXMethodDecl>(FoundByLookup)) {
3902 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3903 if (!D->doesThisDeclarationHaveABody()) {
3904 if (FunctionTemplateDecl *DescribedD =
3906 // Handle a "templated" function together with its described
3907 // template. This avoids need for a similar check at import of the
3908 // described template.
3909 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3910 "Templated function mapped to non-templated?");
3911 Importer.MapImported(DescribedD,
3912 FoundByLookup->getDescribedFunctionTemplate());
3913 }
3914 return Importer.MapImported(D, FoundByLookup);
3915 } else {
3916 // Let's continue and build up the redecl chain in this case.
3917 // FIXME Merge the functions into one decl.
3918 }
3919 }
3920 }
3921 }
3922
3923 DeclarationNameInfo NameInfo(Name, Loc);
3924 // Import additional name location/type info.
3925 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3926 return std::move(Err);
3927
3928 QualType FromTy = D->getType();
3929 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3930 // Set to true if we do not import the type of the function as is. There are
3931 // cases when the original type would result in an infinite recursion during
3932 // the import. To avoid an infinite recursion when importing, we create the
3933 // FunctionDecl with a simplified function type and update it only after the
3934 // relevant AST nodes are already imported.
3935 // The type is related to TypeSourceInfo (it references the type), so we must
3936 // do the same with TypeSourceInfo.
3937 bool UsedDifferentProtoType = false;
3938 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3939 QualType FromReturnTy = FromFPT->getReturnType();
3940 // Functions with auto return type may define a struct inside their body
3941 // and the return type could refer to that struct.
3942 // E.g.: auto foo() { struct X{}; return X(); }
3943 // There are many more cases when types inside the function declaration
3944 // can appear in the return type, like types declared as typenames from
3945 // template params.
3946 // All such cases are tracked in FindFunctionDeclImportCycle.
3947 if (Importer.FindFunctionDeclImportCycle.isCycle(D)) {
3948 FromReturnTy = Importer.getFromContext().VoidTy;
3949 UsedDifferentProtoType = true;
3950 }
3951 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3952 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3953 // FunctionDecl that we are importing the FunctionProtoType for.
3954 // To avoid an infinite recursion when importing, create the FunctionDecl
3955 // with a simplified function type.
3956 if (FromEPI.ExceptionSpec.SourceDecl ||
3957 FromEPI.ExceptionSpec.SourceTemplate ||
3958 FromEPI.ExceptionSpec.NoexceptExpr) {
3960 FromEPI = DefaultEPI;
3961 UsedDifferentProtoType = true;
3962 }
3963 FromTy = Importer.getFromContext().getFunctionType(
3964 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3965 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3966 FromTy, D->getBeginLoc());
3967 }
3968
3969 Error Err = Error::success();
3970 auto ScopedReturnTypeDeclCycleDetector =
3971 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
3972 auto T = importChecked(Err, FromTy);
3973 auto TInfo = importChecked(Err, FromTSI);
3974 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3975 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3976 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3977 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3978 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
3979 TrailingRequiresClause.ConstraintExpr =
3980 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
3981 if (Err)
3982 return std::move(Err);
3983
3984 // Import the function parameters.
3986 for (auto *P : D->parameters()) {
3987 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3988 Parameters.push_back(*ToPOrErr);
3989 else
3990 return ToPOrErr.takeError();
3991 }
3992
3993 // Create the imported function.
3994 FunctionDecl *ToFunction = nullptr;
3995 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3996 ExplicitSpecifier ESpec =
3997 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3998 if (Err)
3999 return std::move(Err);
4000 auto ToInheritedConstructor = InheritedConstructor();
4001 if (FromConstructor->isInheritingConstructor()) {
4002 Expected<InheritedConstructor> ImportedInheritedCtor =
4003 import(FromConstructor->getInheritedConstructor());
4004 if (!ImportedInheritedCtor)
4005 return ImportedInheritedCtor.takeError();
4006 ToInheritedConstructor = *ImportedInheritedCtor;
4007 }
4008 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4009 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4010 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4012 ToInheritedConstructor, TrailingRequiresClause))
4013 return ToFunction;
4014 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4015
4016 Error Err = Error::success();
4017 auto ToOperatorDelete = importChecked(
4018 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4019 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4020 if (Err)
4021 return std::move(Err);
4022
4023 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4024 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4025 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4027 TrailingRequiresClause))
4028 return ToFunction;
4029
4030 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4031
4032 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4033 } else if (CXXConversionDecl *FromConversion =
4034 dyn_cast<CXXConversionDecl>(D)) {
4035 ExplicitSpecifier ESpec =
4036 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4037 if (Err)
4038 return std::move(Err);
4039 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4040 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4041 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4042 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4043 SourceLocation(), TrailingRequiresClause))
4044 return ToFunction;
4045 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4046 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4047 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4048 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4049 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4050 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4051 return ToFunction;
4052 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4053 ExplicitSpecifier ESpec =
4054 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4055 CXXConstructorDecl *Ctor =
4056 importChecked(Err, Guide->getCorrespondingConstructor());
4057 const CXXDeductionGuideDecl *SourceDG =
4058 importChecked(Err, Guide->getSourceDeductionGuide());
4059 if (Err)
4060 return std::move(Err);
4061 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4062 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4063 NameInfo, T, TInfo, ToEndLoc, Ctor,
4064 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4065 SourceDG, Guide->getSourceDeductionGuideKind()))
4066 return ToFunction;
4067 } else {
4068 if (GetImportedOrCreateDecl(
4069 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4070 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4072 D->getConstexprKind(), TrailingRequiresClause))
4073 return ToFunction;
4074 }
4075
4076 // Connect the redecl chain.
4077 if (FoundByLookup) {
4078 auto *Recent = const_cast<FunctionDecl *>(
4079 FoundByLookup->getMostRecentDecl());
4080 ToFunction->setPreviousDecl(Recent);
4081 // FIXME Probably we should merge exception specifications. E.g. In the
4082 // "To" context the existing function may have exception specification with
4083 // noexcept-unevaluated, while the newly imported function may have an
4084 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4085 // decl and its redeclarations may be required.
4086 }
4087
4088 // We will import DefaultedOrDeletedInfo later.
4089
4090 ToFunction->setQualifierInfo(ToQualifierLoc);
4091 ToFunction->setAccess(D->getAccess());
4092 ToFunction->setLexicalDeclContext(LexicalDC);
4093 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4094 ToFunction->setTrivial(D->isTrivial());
4095 ToFunction->setIsPureVirtual(D->isPureVirtual());
4096 ToFunction->setDefaulted(D->isDefaulted());
4098 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4104 ToFunction->setRangeEnd(ToEndLoc);
4105 ToFunction->setDefaultLoc(ToDefaultLoc);
4106
4107 if (auto *Info = D->getDefaultedOrDeletedInfo()) {
4108 StringLiteral *Msg = nullptr;
4109 if (StringLiteral *M = Info->getDeletedMessage()) {
4110 auto Imported = import(M);
4111 if (!Imported)
4112 return Imported.takeError();
4113 Msg = *Imported;
4114 }
4115
4117 for (DeclAccessPair P : Info->getUnqualifiedLookups()) {
4118 auto Imported = import(P.getDecl());
4119 if (!Imported)
4120 return Imported.takeError();
4121 Lookups.push_back(
4123 }
4124
4125 ToFunction->setDefaultedOrDeletedInfo(
4127 Importer.getToContext(), Lookups, Info->getFPFeatures(), Msg));
4128 }
4129
4130 // Set the parameters.
4131 for (auto *Param : Parameters) {
4132 Param->setOwningFunction(ToFunction);
4133 ToFunction->addDeclInternal(Param);
4134 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4135 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4136 }
4137 ToFunction->setParams(Parameters);
4138
4139 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4140 // params it refers to.
4141 if (TInfo) {
4142 if (auto ProtoLoc =
4143 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4144 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4145 ProtoLoc.setParam(I, Parameters[I]);
4146 }
4147 }
4148
4149 // Import the describing template function, if any.
4150 if (FromFT) {
4151 auto ToFTOrErr = import(FromFT);
4152 if (!ToFTOrErr)
4153 return ToFTOrErr.takeError();
4154 }
4155
4156 // Import Ctor initializers.
4157 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4158 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4159 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4160 // Import first, then allocate memory and copy if there was no error.
4161 if (Error Err = ImportContainerChecked(
4162 FromConstructor->inits(), CtorInitializers))
4163 return std::move(Err);
4164 auto **Memory =
4165 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4166 llvm::copy(CtorInitializers, Memory);
4167 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4168 ToCtor->setCtorInitializers(Memory);
4169 ToCtor->setNumCtorInitializers(NumInitializers);
4170 }
4171 }
4172
4173 // If it is a template, import all related things.
4174 if (Error Err = ImportTemplateInformation(D, ToFunction))
4175 return std::move(Err);
4176
4177 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4179 FromCXXMethod))
4180 return std::move(Err);
4181
4183 Error Err = ImportFunctionDeclBody(D, ToFunction);
4184
4185 if (Err)
4186 return std::move(Err);
4187 }
4188
4189 // Import and set the original type in case we used another type.
4190 if (UsedDifferentProtoType) {
4191 if (ExpectedType TyOrErr = import(D->getType()))
4192 ToFunction->setType(*TyOrErr);
4193 else
4194 return TyOrErr.takeError();
4195 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4196 ToFunction->setTypeSourceInfo(*TSIOrErr);
4197 else
4198 return TSIOrErr.takeError();
4199 }
4200
4201 // FIXME: Other bits to merge?
4202
4203 addDeclToContexts(D, ToFunction);
4204
4205 // Import the rest of the chain. I.e. import all subsequent declarations.
4206 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4207 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4208 if (!ToRedeclOrErr)
4209 return ToRedeclOrErr.takeError();
4210 }
4211
4212 return ToFunction;
4213}
4214
4218
4222
4226
4230
4235
4237 // Import the major distinguishing characteristics of a variable.
4238 DeclContext *DC, *LexicalDC;
4239 DeclarationName Name;
4240 SourceLocation Loc;
4241 NamedDecl *ToD;
4242 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4243 return std::move(Err);
4244 if (ToD)
4245 return ToD;
4246
4247 // Determine whether we've already imported this field.
4248 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4249 for (auto *FoundDecl : FoundDecls) {
4250 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4251 // For anonymous fields, match up by index.
4252 if (!Name &&
4254 ASTImporter::getFieldIndex(FoundField))
4255 continue;
4256
4257 if (Importer.IsStructurallyEquivalent(D->getType(),
4258 FoundField->getType())) {
4259 Importer.MapImported(D, FoundField);
4260 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4261 // initializer of a FieldDecl might not had been instantiated in the
4262 // "To" context. However, the "From" context might instantiated that,
4263 // thus we have to merge that.
4264 // Note: `hasInClassInitializer()` is not the same as non-null
4265 // `getInClassInitializer()` value.
4266 if (Expr *FromInitializer = D->getInClassInitializer()) {
4267 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4268 // Import of the FromInitializer may result in the setting of
4269 // InClassInitializer. If not, set it here.
4270 assert(FoundField->hasInClassInitializer() &&
4271 "Field should have an in-class initializer if it has an "
4272 "expression for it.");
4273 if (!FoundField->getInClassInitializer())
4274 FoundField->setInClassInitializer(*ToInitializerOrErr);
4275 } else {
4276 return ToInitializerOrErr.takeError();
4277 }
4278 }
4279 return FoundField;
4280 }
4281
4282 // FIXME: Why is this case not handled with calling HandleNameConflict?
4283 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4284 << Name << D->getType() << FoundField->getType();
4285 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4286 << FoundField->getType();
4287
4288 return make_error<ASTImportError>(ASTImportError::NameConflict);
4289 }
4290 }
4291
4292 Error Err = Error::success();
4293 auto ToType = importChecked(Err, D->getType());
4294 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4295 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4296 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4297 if (Err)
4298 return std::move(Err);
4299 const Type *ToCapturedVLAType = nullptr;
4300 if (Error Err = Importer.importInto(
4301 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4302 return std::move(Err);
4303
4304 FieldDecl *ToField;
4305 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4306 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4307 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4308 D->getInClassInitStyle()))
4309 return ToField;
4310
4311 ToField->setAccess(D->getAccess());
4312 ToField->setLexicalDeclContext(LexicalDC);
4313 ToField->setImplicit(D->isImplicit());
4314 if (ToCapturedVLAType)
4315 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4316 LexicalDC->addDeclInternal(ToField);
4317 // Import initializer only after the field was created, it may have recursive
4318 // reference to the field.
4319 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4320 if (Err)
4321 return std::move(Err);
4322 if (ToInitializer) {
4323 auto *AlreadyImported = ToField->getInClassInitializer();
4324 if (AlreadyImported)
4325 assert(ToInitializer == AlreadyImported &&
4326 "Duplicate import of in-class initializer.");
4327 else
4328 ToField->setInClassInitializer(ToInitializer);
4329 }
4330
4331 return ToField;
4332}
4333
4335 // Import the major distinguishing characteristics of a variable.
4336 DeclContext *DC, *LexicalDC;
4337 DeclarationName Name;
4338 SourceLocation Loc;
4339 NamedDecl *ToD;
4340 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4341 return std::move(Err);
4342 if (ToD)
4343 return ToD;
4344
4345 // Determine whether we've already imported this field.
4346 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4347 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4348 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4349 // For anonymous indirect fields, match up by index.
4350 if (!Name &&
4352 ASTImporter::getFieldIndex(FoundField))
4353 continue;
4354
4355 if (Importer.IsStructurallyEquivalent(D->getType(),
4356 FoundField->getType(),
4357 !Name.isEmpty())) {
4358 Importer.MapImported(D, FoundField);
4359 return FoundField;
4360 }
4361
4362 // If there are more anonymous fields to check, continue.
4363 if (!Name && I < N-1)
4364 continue;
4365
4366 // FIXME: Why is this case not handled with calling HandleNameConflict?
4367 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4368 << Name << D->getType() << FoundField->getType();
4369 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4370 << FoundField->getType();
4371
4372 return make_error<ASTImportError>(ASTImportError::NameConflict);
4373 }
4374 }
4375
4376 // Import the type.
4377 auto TypeOrErr = import(D->getType());
4378 if (!TypeOrErr)
4379 return TypeOrErr.takeError();
4380
4381 auto **NamedChain =
4382 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4383
4384 unsigned i = 0;
4385 for (auto *PI : D->chain())
4386 if (Expected<NamedDecl *> ToD = import(PI))
4387 NamedChain[i++] = *ToD;
4388 else
4389 return ToD.takeError();
4390
4391 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4392 IndirectFieldDecl *ToIndirectField;
4393 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4394 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4395 // FIXME here we leak `NamedChain` which is allocated before
4396 return ToIndirectField;
4397
4398 ToIndirectField->setAccess(D->getAccess());
4399 ToIndirectField->setLexicalDeclContext(LexicalDC);
4400 LexicalDC->addDeclInternal(ToIndirectField);
4401 return ToIndirectField;
4402}
4403
4404/// Used as return type of getFriendCountAndPosition.
4406 /// Number of similar looking friends.
4407 unsigned int TotalCount;
4408 /// Index of the specific FriendDecl.
4409 unsigned int IndexOfDecl;
4410};
4411
4412static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4413 FriendDecl *FD2) {
4414 if (FD1->getKind() != FD2->getKind())
4415 return false;
4416
4417 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4419 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4420 FD2->getASTContext(), NonEquivalentDecls,
4422 /*StrictTypeSpelling=*/false, /*Complain=*/false);
4423 return Ctx.IsEquivalent(FD1, FD2);
4424}
4425
4427 FriendDecl *FD) {
4428 unsigned int FriendCount = 0;
4429 UnsignedOrNone FriendPosition = std::nullopt;
4430 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4431
4432 for (FriendDecl *FoundFriend : RD->friends()) {
4433 if (FoundFriend == FD) {
4434 FriendPosition = FriendCount;
4435 ++FriendCount;
4436 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4437 ++FriendCount;
4438 }
4439 }
4440
4441 assert(FriendPosition && "Friend decl not found in own parent.");
4442 return {FriendCount, *FriendPosition};
4443}
4444
4445Expected<FriendDecl::FriendUnion>
4446ASTNodeImporter::importFriendUnion(FriendDecl *D) {
4447 if (NamedDecl *FriendD = D->getFriendDecl()) {
4448 NamedDecl *ToFriendD;
4449 if (Error Err = importInto(ToFriendD, FriendD))
4450 return std::move(Err);
4451
4452 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4453 !FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))
4454 ToFriendD->setObjectOfFriendDecl(false);
4455
4456 return ToFriendD;
4457 }
4458
4459 // The friend is a type, not a decl.
4460 auto TSIOrErr = import(D->getFriendType());
4461 if (TSIOrErr)
4462 return *TSIOrErr;
4463 return TSIOrErr.takeError();
4464}
4465
4467 // Import the major distinguishing characteristics of a declaration.
4468 DeclContext *DC, *LexicalDC;
4469 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4470 return std::move(Err);
4471
4472 // Determine whether we've already imported this decl.
4473 // FriendDecl is not a NamedDecl so we cannot use lookup.
4474 // We try to maintain order and count of redundant friend declarations.
4475 const auto *RD = cast<CXXRecordDecl>(DC);
4476 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4477 for (FriendDecl *ImportedFriend : RD->friends())
4478 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4479 ImportedEquivalentFriends.push_back(ImportedFriend);
4480
4481 FriendCountAndPosition CountAndPosition =
4482 getFriendCountAndPosition(Importer, D);
4483
4484 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4485 "Class with non-matching friends is imported, ODR check wrong?");
4486 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4487 return Importer.MapImported(
4488 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4489
4490 // Not found. Create it.
4491 // The declarations will be put into order later by ImportDeclContext.
4492 auto ToFUOrErr = importFriendUnion(D);
4493 if (!ToFUOrErr)
4494 return ToFUOrErr.takeError();
4495 FriendDecl::FriendUnion ToFU = *ToFUOrErr;
4496
4497 auto LocationOrErr = import(D->getLocation());
4498 if (!LocationOrErr)
4499 return LocationOrErr.takeError();
4500 auto FriendLocOrErr = import(D->getFriendLoc());
4501 if (!FriendLocOrErr)
4502 return FriendLocOrErr.takeError();
4503 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4504 if (!EllipsisLocOrErr)
4505 return EllipsisLocOrErr.takeError();
4506
4507 FriendDecl *FrD;
4508 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4509 *LocationOrErr, ToFU, *FriendLocOrErr,
4510 *EllipsisLocOrErr))
4511 return FrD;
4512
4513 FrD->setAccess(D->getAccess());
4514 FrD->setLexicalDeclContext(LexicalDC);
4515 LexicalDC->addDeclInternal(FrD);
4516 return FrD;
4517}
4518
4520 DeclContext *DC, *LexicalDC;
4521 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4522 return std::move(Err);
4523
4524 const auto *RD = cast<CXXRecordDecl>(DC);
4525 SmallVector<FriendTemplateDecl *, 2> ImportedEquivalentFriends;
4526 for (FriendDecl *ImportedFriend : RD->friends()) {
4527 auto *ImportedFriendTemplate = dyn_cast<FriendTemplateDecl>(ImportedFriend);
4528 if (ImportedFriendTemplate &&
4529 IsEquivalentFriend(Importer, D, ImportedFriendTemplate))
4530 ImportedEquivalentFriends.push_back(ImportedFriendTemplate);
4531 }
4532
4533 FriendCountAndPosition CountAndPosition =
4534 getFriendCountAndPosition(Importer, D);
4535 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4536 "Class with non-matching friends is imported, ODR check wrong?");
4537
4538 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4539 return Importer.MapImported(
4540 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4541
4543 if (D->getFriendKind() !=
4545 auto ToFUOrErr = importFriendUnion(D);
4546 if (!ToFUOrErr)
4547 return ToFUOrErr.takeError();
4548 ToFU = *ToFUOrErr;
4549 }
4550
4551 TemplateName ToTemplate;
4552 const TemplateName FromTemplate = D->getFriendTemplateName();
4553 if (!FromTemplate.isNull()) {
4554 if (Error Err = importInto(ToTemplate, FromTemplate))
4555 return std::move(Err);
4556 }
4557
4559 SmallVector<TemplateParameterList *, 1> ToTPLs(FromTPLs.size());
4560 if (Error Err = ImportContainerChecked(FromTPLs, ToTPLs))
4561 return std::move(Err);
4562
4563 auto LocationOrErr = import(D->getLocation());
4564 if (!LocationOrErr)
4565 return LocationOrErr.takeError();
4566
4567 auto FriendLocOrErr = import(D->getFriendLoc());
4568 if (!FriendLocOrErr)
4569 return FriendLocOrErr.takeError();
4570
4571 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4572 if (!EllipsisLocOrErr)
4573 return EllipsisLocOrErr.takeError();
4574
4575 FriendTemplateDecl *FTD;
4576 if (GetImportedOrCreateDecl(FTD, D, Importer.getToContext(), DC,
4577 *LocationOrErr, ToFU, *FriendLocOrErr, ToTPLs,
4578 *EllipsisLocOrErr, ToTemplate))
4579 return FTD;
4580
4581 FTD->setAccess(D->getAccess());
4582 FTD->setLexicalDeclContext(LexicalDC);
4583 LexicalDC->addDeclInternal(FTD);
4584 return FTD;
4585}
4586
4588 // Import the major distinguishing characteristics of an ivar.
4589 DeclContext *DC, *LexicalDC;
4590 DeclarationName Name;
4591 SourceLocation Loc;
4592 NamedDecl *ToD;
4593 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4594 return std::move(Err);
4595 if (ToD)
4596 return ToD;
4597
4598 // Determine whether we've already imported this ivar
4599 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4600 for (auto *FoundDecl : FoundDecls) {
4601 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4602 if (Importer.IsStructurallyEquivalent(D->getType(),
4603 FoundIvar->getType())) {
4604 Importer.MapImported(D, FoundIvar);
4605 return FoundIvar;
4606 }
4607
4608 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4609 << Name << D->getType() << FoundIvar->getType();
4610 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4611 << FoundIvar->getType();
4612
4613 return make_error<ASTImportError>(ASTImportError::NameConflict);
4614 }
4615 }
4616
4617 Error Err = Error::success();
4618 auto ToType = importChecked(Err, D->getType());
4619 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4620 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4621 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4622 if (Err)
4623 return std::move(Err);
4624
4625 ObjCIvarDecl *ToIvar;
4626 if (GetImportedOrCreateDecl(
4627 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4628 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4629 ToType, ToTypeSourceInfo,
4630 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4631 return ToIvar;
4632
4633 ToIvar->setLexicalDeclContext(LexicalDC);
4634 LexicalDC->addDeclInternal(ToIvar);
4635 return ToIvar;
4636}
4637
4639
4641 auto RedeclIt = Redecls.begin();
4642 // Import the first part of the decl chain. I.e. import all previous
4643 // declarations starting from the canonical decl.
4644 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4645 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4646 if (!RedeclOrErr)
4647 return RedeclOrErr.takeError();
4648 }
4649 assert(*RedeclIt == D);
4650
4651 // Import the major distinguishing characteristics of a variable.
4652 DeclContext *DC, *LexicalDC;
4653 DeclarationName Name;
4654 SourceLocation Loc;
4655 NamedDecl *ToD;
4656 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4657 return std::move(Err);
4658 if (ToD)
4659 return ToD;
4660
4661 // Try to find a variable in our own ("to") context with the same name and
4662 // in the same context as the variable we're importing.
4663 VarDecl *FoundByLookup = nullptr;
4664 if (D->isFileVarDecl()) {
4665 SmallVector<NamedDecl *, 4> ConflictingDecls;
4666 unsigned IDNS = Decl::IDNS_Ordinary;
4667 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4668 for (auto *FoundDecl : FoundDecls) {
4669 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4670 continue;
4671
4672 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4673 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4674 continue;
4675 if (Importer.IsStructurallyEquivalent(D->getType(),
4676 FoundVar->getType())) {
4677
4678 // The VarDecl in the "From" context has a definition, but in the
4679 // "To" context we already have a definition.
4680 VarDecl *FoundDef = FoundVar->getDefinition();
4681 if (D->isThisDeclarationADefinition() && FoundDef)
4682 // FIXME Check for ODR error if the two definitions have
4683 // different initializers?
4684 return Importer.MapImported(D, FoundDef);
4685
4686 // The VarDecl in the "From" context has an initializer, but in the
4687 // "To" context we already have an initializer.
4688 const VarDecl *FoundDInit = nullptr;
4689 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4690 // FIXME Diagnose ODR error if the two initializers are different?
4691 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4692
4693 FoundByLookup = FoundVar;
4694 break;
4695 }
4696
4697 const ArrayType *FoundArray
4698 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4699 const ArrayType *TArray
4700 = Importer.getToContext().getAsArrayType(D->getType());
4701 if (FoundArray && TArray) {
4702 if (isa<IncompleteArrayType>(FoundArray) &&
4703 isa<ConstantArrayType>(TArray)) {
4704 // Import the type.
4705 if (auto TyOrErr = import(D->getType()))
4706 FoundVar->setType(*TyOrErr);
4707 else
4708 return TyOrErr.takeError();
4709
4710 FoundByLookup = FoundVar;
4711 break;
4712 } else if (isa<IncompleteArrayType>(TArray) &&
4713 isa<ConstantArrayType>(FoundArray)) {
4714 FoundByLookup = FoundVar;
4715 break;
4716 }
4717 }
4718
4719 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4720 << Name << D->getType() << FoundVar->getType();
4721 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4722 << FoundVar->getType();
4723 ConflictingDecls.push_back(FoundDecl);
4724 }
4725 }
4726
4727 if (!ConflictingDecls.empty()) {
4728 ExpectedName NameOrErr = Importer.HandleNameConflict(
4729 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4730 if (NameOrErr)
4731 Name = NameOrErr.get();
4732 else
4733 return NameOrErr.takeError();
4734 }
4735 }
4736
4737 Error Err = Error::success();
4738 auto ToType = importChecked(Err, D->getType());
4739 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4740 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4741 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4742 if (Err)
4743 return std::move(Err);
4744
4745 VarDecl *ToVar;
4746 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4747 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4748 if (Error Err =
4749 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4750 return std::move(Err);
4751 DecompositionDecl *ToDecomp;
4752 if (GetImportedOrCreateDecl(
4753 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4754 Loc, FromDecomp->getRSquareLoc(), ToType, ToTypeSourceInfo,
4756 return ToDecomp;
4757 ToVar = ToDecomp;
4758 } else {
4759 // Create the imported variable.
4760 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4761 ToInnerLocStart, Loc,
4762 Name.getAsIdentifierInfo(), ToType,
4763 ToTypeSourceInfo, D->getStorageClass()))
4764 return ToVar;
4765 }
4766
4767 ToVar->setTSCSpec(D->getTSCSpec());
4768 ToVar->setQualifierInfo(ToQualifierLoc);
4769 ToVar->setAccess(D->getAccess());
4770 ToVar->setLexicalDeclContext(LexicalDC);
4771 if (D->isInlineSpecified())
4772 ToVar->setInlineSpecified();
4773 if (D->isInline())
4774 ToVar->setImplicitlyInline();
4775
4776 if (FoundByLookup) {
4777 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4778 ToVar->setPreviousDecl(Recent);
4779 }
4780
4781 // Import the described template, if any.
4782 if (D->getDescribedVarTemplate()) {
4783 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4784 if (!ToVTOrErr)
4785 return ToVTOrErr.takeError();
4787 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4789 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4790 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4791 else
4792 return ToInstOrErr.takeError();
4793 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4795 else
4796 return POIOrErr.takeError();
4797 }
4798
4799 if (Error Err = ImportInitializer(D, ToVar))
4800 return std::move(Err);
4801
4802 if (D->isConstexpr())
4803 ToVar->setConstexpr(true);
4804
4805 addDeclToContexts(D, ToVar);
4806
4807 // Import the rest of the chain. I.e. import all subsequent declarations.
4808 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4809 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4810 if (!RedeclOrErr)
4811 return RedeclOrErr.takeError();
4812 }
4813
4814 return ToVar;
4815}
4816
4818 // Parameters are created in the translation unit's context, then moved
4819 // into the function declaration's context afterward.
4820 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4821
4822 Error Err = Error::success();
4823 auto ToDeclName = importChecked(Err, D->getDeclName());
4824 auto ToLocation = importChecked(Err, D->getLocation());
4825 auto ToType = importChecked(Err, D->getType());
4826 if (Err)
4827 return std::move(Err);
4828
4829 // Create the imported parameter.
4830 ImplicitParamDecl *ToParm = nullptr;
4831 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4832 ToLocation, ToDeclName.getAsIdentifierInfo(),
4833 ToType, D->getParameterKind()))
4834 return ToParm;
4835 return ToParm;
4836}
4837
4839 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4840
4841 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4842 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4843 else
4844 return LocOrErr.takeError();
4845
4847 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4848
4849 if (FromParam->hasUninstantiatedDefaultArg()) {
4850 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4851 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4852 else
4853 return ToDefArgOrErr.takeError();
4854 } else if (FromParam->hasUnparsedDefaultArg()) {
4855 ToParam->setUnparsedDefaultArg();
4856 } else if (FromParam->hasDefaultArg()) {
4857 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4858 ToParam->setDefaultArg(*ToDefArgOrErr);
4859 else
4860 return ToDefArgOrErr.takeError();
4861 }
4862
4863 return Error::success();
4864}
4865
4868 Error Err = Error::success();
4869 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4870 ConstructorUsingShadowDecl *ToShadow =
4871 importChecked(Err, From.getShadowDecl());
4872 if (Err)
4873 return std::move(Err);
4874 return InheritedConstructor(ToShadow, ToBaseCtor);
4875}
4876
4878 // Parameters are created in the translation unit's context, then moved
4879 // into the function declaration's context afterward.
4880 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4881
4882 Error Err = Error::success();
4883 auto ToDeclName = importChecked(Err, D->getDeclName());
4884 auto ToLocation = importChecked(Err, D->getLocation());
4885 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4886 auto ToType = importChecked(Err, D->getType());
4887 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4888 if (Err)
4889 return std::move(Err);
4890
4891 ParmVarDecl *ToParm;
4892 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4893 ToInnerLocStart, ToLocation,
4894 ToDeclName.getAsIdentifierInfo(), ToType,
4895 ToTypeSourceInfo, D->getStorageClass(),
4896 /*DefaultArg*/ nullptr))
4897 return ToParm;
4898
4899 // Set the default argument. It should be no problem if it was already done.
4900 // Do not import the default expression before GetImportedOrCreateDecl call
4901 // to avoid possible infinite import loop because circular dependency.
4902 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4903 return std::move(Err);
4904
4905 if (D->isObjCMethodParameter()) {
4908 } else {
4911 }
4912
4913 return ToParm;
4914}
4915
4917 // Import the major distinguishing characteristics of a method.
4918 DeclContext *DC, *LexicalDC;
4919 DeclarationName Name;
4920 SourceLocation Loc;
4921 NamedDecl *ToD;
4922 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4923 return std::move(Err);
4924 if (ToD)
4925 return ToD;
4926
4927 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4928 for (auto *FoundDecl : FoundDecls) {
4929 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4930 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4931 continue;
4932
4933 // Check return types.
4934 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4935 FoundMethod->getReturnType())) {
4936 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4937 << D->isInstanceMethod() << Name << D->getReturnType()
4938 << FoundMethod->getReturnType();
4939 Importer.ToDiag(FoundMethod->getLocation(),
4940 diag::note_odr_objc_method_here)
4941 << D->isInstanceMethod() << Name;
4942
4943 return make_error<ASTImportError>(ASTImportError::NameConflict);
4944 }
4945
4946 // Check the number of parameters.
4947 if (D->param_size() != FoundMethod->param_size()) {
4948 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4949 << D->isInstanceMethod() << Name
4950 << D->param_size() << FoundMethod->param_size();
4951 Importer.ToDiag(FoundMethod->getLocation(),
4952 diag::note_odr_objc_method_here)
4953 << D->isInstanceMethod() << Name;
4954
4955 return make_error<ASTImportError>(ASTImportError::NameConflict);
4956 }
4957
4958 // Check parameter types.
4960 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4961 P != PEnd; ++P, ++FoundP) {
4962 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4963 (*FoundP)->getType())) {
4964 Importer.FromDiag((*P)->getLocation(),
4965 diag::warn_odr_objc_method_param_type_inconsistent)
4966 << D->isInstanceMethod() << Name
4967 << (*P)->getType() << (*FoundP)->getType();
4968 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4969 << (*FoundP)->getType();
4970
4971 return make_error<ASTImportError>(ASTImportError::NameConflict);
4972 }
4973 }
4974
4975 // Check variadic/non-variadic.
4976 // Check the number of parameters.
4977 if (D->isVariadic() != FoundMethod->isVariadic()) {
4978 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4979 << D->isInstanceMethod() << Name;
4980 Importer.ToDiag(FoundMethod->getLocation(),
4981 diag::note_odr_objc_method_here)
4982 << D->isInstanceMethod() << Name;
4983
4984 return make_error<ASTImportError>(ASTImportError::NameConflict);
4985 }
4986
4987 // FIXME: Any other bits we need to merge?
4988 return Importer.MapImported(D, FoundMethod);
4989 }
4990 }
4991
4992 Error Err = Error::success();
4993 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4994 auto ToReturnType = importChecked(Err, D->getReturnType());
4995 auto ToReturnTypeSourceInfo =
4997 if (Err)
4998 return std::move(Err);
4999
5000 ObjCMethodDecl *ToMethod;
5001 if (GetImportedOrCreateDecl(
5002 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5003 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5007 return ToMethod;
5008
5009 // FIXME: When we decide to merge method definitions, we'll need to
5010 // deal with implicit parameters.
5011
5012 // Import the parameters
5014 for (auto *FromP : D->parameters()) {
5015 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5016 ToParams.push_back(*ToPOrErr);
5017 else
5018 return ToPOrErr.takeError();
5019 }
5020
5021 // Set the parameters.
5022 for (auto *ToParam : ToParams) {
5023 ToParam->setOwningFunction(ToMethod);
5024 ToMethod->addDeclInternal(ToParam);
5025 }
5026
5028 D->getSelectorLocs(FromSelLocs);
5029 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5030 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5031 return std::move(Err);
5032
5033 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5034
5035 ToMethod->setLexicalDeclContext(LexicalDC);
5036 LexicalDC->addDeclInternal(ToMethod);
5037
5038 // Implicit params are declared when Sema encounters the definition but this
5039 // never happens when the method is imported. Manually declare the implicit
5040 // params now that the MethodDecl knows its class interface.
5041 if (D->getSelfDecl())
5042 ToMethod->createImplicitParams(Importer.getToContext(),
5043 ToMethod->getClassInterface());
5044
5045 return ToMethod;
5046}
5047
5049 // Import the major distinguishing characteristics of a category.
5050 DeclContext *DC, *LexicalDC;
5051 DeclarationName Name;
5052 SourceLocation Loc;
5053 NamedDecl *ToD;
5054 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5055 return std::move(Err);
5056 if (ToD)
5057 return ToD;
5058
5059 Error Err = Error::success();
5060 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5061 auto ToLocation = importChecked(Err, D->getLocation());
5062 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5063 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5064 if (Err)
5065 return std::move(Err);
5066
5068 if (GetImportedOrCreateDecl(
5069 Result, D, Importer.getToContext(), DC, D->getVariance(),
5070 ToVarianceLoc, D->getIndex(),
5071 ToLocation, Name.getAsIdentifierInfo(),
5072 ToColonLoc, ToTypeSourceInfo))
5073 return Result;
5074
5075 // Only import 'ObjCTypeParamType' after the decl is created.
5076 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5077 if (Err)
5078 return std::move(Err);
5079 Result->setTypeForDecl(ToTypeForDecl);
5080 Result->setLexicalDeclContext(LexicalDC);
5081 return Result;
5082}
5083
5085 // Import the major distinguishing characteristics of a category.
5086 DeclContext *DC, *LexicalDC;
5087 DeclarationName Name;
5088 SourceLocation Loc;
5089 NamedDecl *ToD;
5090 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5091 return std::move(Err);
5092 if (ToD)
5093 return ToD;
5094
5095 ObjCInterfaceDecl *ToInterface;
5096 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5097 return std::move(Err);
5098
5099 // Determine if we've already encountered this category.
5100 ObjCCategoryDecl *MergeWithCategory
5101 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5102 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5103 if (!ToCategory) {
5104
5105 Error Err = Error::success();
5106 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5107 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5108 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5109 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5110 if (Err)
5111 return std::move(Err);
5112
5113 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5114 ToAtStartLoc, Loc,
5115 ToCategoryNameLoc,
5116 Name.getAsIdentifierInfo(), ToInterface,
5117 /*TypeParamList=*/nullptr,
5118 ToIvarLBraceLoc,
5119 ToIvarRBraceLoc))
5120 return ToCategory;
5121
5122 ToCategory->setLexicalDeclContext(LexicalDC);
5123 LexicalDC->addDeclInternal(ToCategory);
5124 // Import the type parameter list after MapImported, to avoid
5125 // loops when bringing in their DeclContext.
5126 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5127 ToCategory->setTypeParamList(*PListOrErr);
5128 else
5129 return PListOrErr.takeError();
5130
5131 // Import protocols
5133 SmallVector<SourceLocation, 4> ProtocolLocs;
5135 = D->protocol_loc_begin();
5137 FromProtoEnd = D->protocol_end();
5138 FromProto != FromProtoEnd;
5139 ++FromProto, ++FromProtoLoc) {
5140 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5141 Protocols.push_back(*ToProtoOrErr);
5142 else
5143 return ToProtoOrErr.takeError();
5144
5145 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5146 ProtocolLocs.push_back(*ToProtoLocOrErr);
5147 else
5148 return ToProtoLocOrErr.takeError();
5149 }
5150
5151 // FIXME: If we're merging, make sure that the protocol list is the same.
5152 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5153 ProtocolLocs.data(), Importer.getToContext());
5154
5155 } else {
5156 Importer.MapImported(D, ToCategory);
5157 }
5158
5159 // Import all of the members of this category.
5160 if (Error Err = ImportDeclContext(D))
5161 return std::move(Err);
5162
5163 // If we have an implementation, import it as well.
5164 if (D->getImplementation()) {
5165 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5166 import(D->getImplementation()))
5167 ToCategory->setImplementation(*ToImplOrErr);
5168 else
5169 return ToImplOrErr.takeError();
5170 }
5171
5172 return ToCategory;
5173}
5174
5177 if (To->getDefinition()) {
5179 if (Error Err = ImportDeclContext(From))
5180 return Err;
5181 return Error::success();
5182 }
5183
5184 // Start the protocol definition
5185 To->startDefinition();
5186
5187 // Import protocols
5189 SmallVector<SourceLocation, 4> ProtocolLocs;
5191 From->protocol_loc_begin();
5192 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5193 FromProtoEnd = From->protocol_end();
5194 FromProto != FromProtoEnd;
5195 ++FromProto, ++FromProtoLoc) {
5196 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5197 Protocols.push_back(*ToProtoOrErr);
5198 else
5199 return ToProtoOrErr.takeError();
5200
5201 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5202 ProtocolLocs.push_back(*ToProtoLocOrErr);
5203 else
5204 return ToProtoLocOrErr.takeError();
5205
5206 }
5207
5208 // FIXME: If we're merging, make sure that the protocol list is the same.
5209 To->setProtocolList(Protocols.data(), Protocols.size(),
5210 ProtocolLocs.data(), Importer.getToContext());
5211
5212 if (shouldForceImportDeclContext(Kind)) {
5213 // Import all of the members of this protocol.
5214 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5215 return Err;
5216 }
5217 return Error::success();
5218}
5219
5221 // If this protocol has a definition in the translation unit we're coming
5222 // from, but this particular declaration is not that definition, import the
5223 // definition and map to that.
5225 if (Definition && Definition != D) {
5226 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5227 return Importer.MapImported(D, *ImportedDefOrErr);
5228 else
5229 return ImportedDefOrErr.takeError();
5230 }
5231
5232 // Import the major distinguishing characteristics of a protocol.
5233 DeclContext *DC, *LexicalDC;
5234 DeclarationName Name;
5235 SourceLocation Loc;
5236 NamedDecl *ToD;
5237 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5238 return std::move(Err);
5239 if (ToD)
5240 return ToD;
5241
5242 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5243 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5244 for (auto *FoundDecl : FoundDecls) {
5245 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5246 continue;
5247
5248 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5249 break;
5250 }
5251
5252 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5253 if (!ToProto) {
5254 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5255 if (!ToAtBeginLocOrErr)
5256 return ToAtBeginLocOrErr.takeError();
5257
5258 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5259 Name.getAsIdentifierInfo(), Loc,
5260 *ToAtBeginLocOrErr,
5261 /*PrevDecl=*/nullptr))
5262 return ToProto;
5263 ToProto->setLexicalDeclContext(LexicalDC);
5264 LexicalDC->addDeclInternal(ToProto);
5265 }
5266
5267 Importer.MapImported(D, ToProto);
5268
5270 if (Error Err = ImportDefinition(D, ToProto))
5271 return std::move(Err);
5272
5273 return ToProto;
5274}
5275
5277 DeclContext *DC, *LexicalDC;
5278 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5279 return std::move(Err);
5280
5281 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5282 if (!ExternLocOrErr)
5283 return ExternLocOrErr.takeError();
5284
5285 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5286 if (!LangLocOrErr)
5287 return LangLocOrErr.takeError();
5288
5289 bool HasBraces = D->hasBraces();
5290
5291 LinkageSpecDecl *ToLinkageSpec;
5292 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5293 *ExternLocOrErr, *LangLocOrErr,
5294 D->getLanguage(), HasBraces))
5295 return ToLinkageSpec;
5296
5297 if (HasBraces) {
5298 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5299 if (!RBraceLocOrErr)
5300 return RBraceLocOrErr.takeError();
5301 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5302 }
5303
5304 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5305 LexicalDC->addDeclInternal(ToLinkageSpec);
5306
5307 return ToLinkageSpec;
5308}
5309
5311 BaseUsingDecl *ToSI) {
5312 for (UsingShadowDecl *FromShadow : D->shadows()) {
5313 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5314 ToSI->addShadowDecl(*ToShadowOrErr);
5315 else
5316 // FIXME: We return error here but the definition is already created
5317 // and available with lookups. How to fix this?..
5318 return ToShadowOrErr.takeError();
5319 }
5320 return ToSI;
5321}
5322
5324 DeclContext *DC, *LexicalDC;
5325 DeclarationName Name;
5326 SourceLocation Loc;
5327 NamedDecl *ToD = nullptr;
5328 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5329 return std::move(Err);
5330 if (ToD)
5331 return ToD;
5332
5333 Error Err = Error::success();
5334 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5335 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5336 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5337 if (Err)
5338 return std::move(Err);
5339
5340 DeclarationNameInfo NameInfo(Name, ToLoc);
5341 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5342 return std::move(Err);
5343
5344 UsingDecl *ToUsing;
5345 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5346 ToUsingLoc, ToQualifierLoc, NameInfo,
5347 D->hasTypename()))
5348 return ToUsing;
5349
5350 ToUsing->setLexicalDeclContext(LexicalDC);
5351 LexicalDC->addDeclInternal(ToUsing);
5352
5353 if (NamedDecl *FromPattern =
5354 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5355 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5356 Importer.getToContext().setInstantiatedFromUsingDecl(
5357 ToUsing, *ToPatternOrErr);
5358 else
5359 return ToPatternOrErr.takeError();
5360 }
5361
5362 return ImportUsingShadowDecls(D, ToUsing);
5363}
5364
5366 DeclContext *DC, *LexicalDC;
5367 DeclarationName Name;
5368 SourceLocation Loc;
5369 NamedDecl *ToD = nullptr;
5370 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5371 return std::move(Err);
5372 if (ToD)
5373 return ToD;
5374
5375 Error Err = Error::success();
5376 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5377 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5378 auto ToNameLoc = importChecked(Err, D->getLocation());
5379 auto *ToEnumType = importChecked(Err, D->getEnumType());
5380 if (Err)
5381 return std::move(Err);
5382
5383 UsingEnumDecl *ToUsingEnum;
5384 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5385 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5386 return ToUsingEnum;
5387
5388 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5389 LexicalDC->addDeclInternal(ToUsingEnum);
5390
5391 if (UsingEnumDecl *FromPattern =
5392 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5393 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5394 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5395 *ToPatternOrErr);
5396 else
5397 return ToPatternOrErr.takeError();
5398 }
5399
5400 return ImportUsingShadowDecls(D, ToUsingEnum);
5401}
5402
5404 DeclContext *DC, *LexicalDC;
5405 DeclarationName Name;
5406 SourceLocation Loc;
5407 NamedDecl *ToD = nullptr;
5408 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5409 return std::move(Err);
5410 if (ToD)
5411 return ToD;
5412
5413 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5414 if (!ToIntroducerOrErr)
5415 return ToIntroducerOrErr.takeError();
5416
5417 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5418 if (!ToTargetOrErr)
5419 return ToTargetOrErr.takeError();
5420
5421 UsingShadowDecl *ToShadow;
5422 if (auto *FromConstructorUsingShadow =
5423 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5424 Error Err = Error::success();
5426 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5427 if (Err)
5428 return std::move(Err);
5429 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5430 // is really the "NominatedBaseClassShadowDecl" value if it exists
5431 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5432 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5433 // get the correct values.
5434 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5435 ToShadow, D, Importer.getToContext(), DC, Loc,
5436 cast<UsingDecl>(*ToIntroducerOrErr),
5437 Nominated ? Nominated : *ToTargetOrErr,
5438 FromConstructorUsingShadow->constructsVirtualBase()))
5439 return ToShadow;
5440 } else {
5441 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5442 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5443 return ToShadow;
5444 }
5445
5446 ToShadow->setLexicalDeclContext(LexicalDC);
5447 ToShadow->setAccess(D->getAccess());
5448
5449 if (UsingShadowDecl *FromPattern =
5450 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5451 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5452 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5453 ToShadow, *ToPatternOrErr);
5454 else
5455 // FIXME: We return error here but the definition is already created
5456 // and available with lookups. How to fix this?..
5457 return ToPatternOrErr.takeError();
5458 }
5459
5460 LexicalDC->addDeclInternal(ToShadow);
5461
5462 return ToShadow;
5463}
5464
5466 DeclContext *DC, *LexicalDC;
5467 DeclarationName Name;
5468 SourceLocation Loc;
5469 NamedDecl *ToD = nullptr;
5470 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5471 return std::move(Err);
5472 if (ToD)
5473 return ToD;
5474
5475 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5476 if (!ToComAncestorOrErr)
5477 return ToComAncestorOrErr.takeError();
5478
5479 Error Err = Error::success();
5480 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5481 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5482 auto ToNamespaceKeyLocation =
5484 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5485 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5486 if (Err)
5487 return std::move(Err);
5488
5489 UsingDirectiveDecl *ToUsingDir;
5490 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5491 ToUsingLoc,
5492 ToNamespaceKeyLocation,
5493 ToQualifierLoc,
5494 ToIdentLocation,
5495 ToNominatedNamespace, *ToComAncestorOrErr))
5496 return ToUsingDir;
5497
5498 ToUsingDir->setLexicalDeclContext(LexicalDC);
5499 LexicalDC->addDeclInternal(ToUsingDir);
5500
5501 return ToUsingDir;
5502}
5503
5505 DeclContext *DC, *LexicalDC;
5506 DeclarationName Name;
5507 SourceLocation Loc;
5508 NamedDecl *ToD = nullptr;
5509 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5510 return std::move(Err);
5511 if (ToD)
5512 return ToD;
5513
5514 auto ToInstantiatedFromUsingOrErr =
5515 Importer.Import(D->getInstantiatedFromUsingDecl());
5516 if (!ToInstantiatedFromUsingOrErr)
5517 return ToInstantiatedFromUsingOrErr.takeError();
5518 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5519 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5520 return std::move(Err);
5521
5522 UsingPackDecl *ToUsingPack;
5523 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5524 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5525 Expansions))
5526 return ToUsingPack;
5527
5528 addDeclToContexts(D, ToUsingPack);
5529
5530 return ToUsingPack;
5531}
5532
5535 DeclContext *DC, *LexicalDC;
5536 DeclarationName Name;
5537 SourceLocation Loc;
5538 NamedDecl *ToD = nullptr;
5539 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5540 return std::move(Err);
5541 if (ToD)
5542 return ToD;
5543
5544 Error Err = Error::success();
5545 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5546 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5547 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5548 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5549 if (Err)
5550 return std::move(Err);
5551
5552 DeclarationNameInfo NameInfo(Name, ToLoc);
5553 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5554 return std::move(Err);
5555
5556 UnresolvedUsingValueDecl *ToUsingValue;
5557 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5558 ToUsingLoc, ToQualifierLoc, NameInfo,
5559 ToEllipsisLoc))
5560 return ToUsingValue;
5561
5562 ToUsingValue->setAccess(D->getAccess());
5563 ToUsingValue->setLexicalDeclContext(LexicalDC);
5564 LexicalDC->addDeclInternal(ToUsingValue);
5565
5566 return ToUsingValue;
5567}
5568
5571 DeclContext *DC, *LexicalDC;
5572 DeclarationName Name;
5573 SourceLocation Loc;
5574 NamedDecl *ToD = nullptr;
5575 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5576 return std::move(Err);
5577 if (ToD)
5578 return ToD;
5579
5580 Error Err = Error::success();
5581 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5582 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5583 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5584 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5585 if (Err)
5586 return std::move(Err);
5587
5589 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5590 ToUsingLoc, ToTypenameLoc,
5591 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5592 return ToUsing;
5593
5594 ToUsing->setAccess(D->getAccess());
5595 ToUsing->setLexicalDeclContext(LexicalDC);
5596 LexicalDC->addDeclInternal(ToUsing);
5597
5598 return ToUsing;
5599}
5600
5602 Decl* ToD = nullptr;
5603 switch (D->getBuiltinTemplateKind()) {
5604#define BuiltinTemplate(BTName) \
5605 case BuiltinTemplateKind::BTK##BTName: \
5606 ToD = Importer.getToContext().get##BTName##Decl(); \
5607 break;
5608#include "clang/Basic/BuiltinTemplates.inc"
5609 }
5610 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5611 Importer.MapImported(D, ToD);
5612 return ToD;
5613}
5614
5617 if (To->getDefinition()) {
5618 // Check consistency of superclass.
5619 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5620 if (FromSuper) {
5621 if (auto FromSuperOrErr = import(FromSuper))
5622 FromSuper = *FromSuperOrErr;
5623 else
5624 return FromSuperOrErr.takeError();
5625 }
5626
5627 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5628 if ((bool)FromSuper != (bool)ToSuper ||
5629 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5630 Importer.ToDiag(To->getLocation(),
5631 diag::warn_odr_objc_superclass_inconsistent)
5632 << To->getDeclName();
5633 if (ToSuper)
5634 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5635 << To->getSuperClass()->getDeclName();
5636 else
5637 Importer.ToDiag(To->getLocation(),
5638 diag::note_odr_objc_missing_superclass);
5639 if (From->getSuperClass())
5640 Importer.FromDiag(From->getSuperClassLoc(),
5641 diag::note_odr_objc_superclass)
5642 << From->getSuperClass()->getDeclName();
5643 else
5644 Importer.FromDiag(From->getLocation(),
5645 diag::note_odr_objc_missing_superclass);
5646 }
5647
5649 if (Error Err = ImportDeclContext(From))
5650 return Err;
5651 return Error::success();
5652 }
5653
5654 // Start the definition.
5655 To->startDefinition();
5656
5657 // If this class has a superclass, import it.
5658 if (From->getSuperClass()) {
5659 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5660 To->setSuperClass(*SuperTInfoOrErr);
5661 else
5662 return SuperTInfoOrErr.takeError();
5663 }
5664
5665 // Import protocols
5667 SmallVector<SourceLocation, 4> ProtocolLocs;
5669 From->protocol_loc_begin();
5670
5672 FromProtoEnd = From->protocol_end();
5673 FromProto != FromProtoEnd;
5674 ++FromProto, ++FromProtoLoc) {
5675 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5676 Protocols.push_back(*ToProtoOrErr);
5677 else
5678 return ToProtoOrErr.takeError();
5679
5680 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5681 ProtocolLocs.push_back(*ToProtoLocOrErr);
5682 else
5683 return ToProtoLocOrErr.takeError();
5684
5685 }
5686
5687 // FIXME: If we're merging, make sure that the protocol list is the same.
5688 To->setProtocolList(Protocols.data(), Protocols.size(),
5689 ProtocolLocs.data(), Importer.getToContext());
5690
5691 // Import categories. When the categories themselves are imported, they'll
5692 // hook themselves into this interface.
5693 for (auto *Cat : From->known_categories()) {
5694 auto ToCatOrErr = import(Cat);
5695 if (!ToCatOrErr)
5696 return ToCatOrErr.takeError();
5697 }
5698
5699 // If we have an @implementation, import it as well.
5700 if (From->getImplementation()) {
5701 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5702 import(From->getImplementation()))
5703 To->setImplementation(*ToImplOrErr);
5704 else
5705 return ToImplOrErr.takeError();
5706 }
5707
5708 // Import all of the members of this class.
5709 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5710 return Err;
5711
5712 return Error::success();
5713}
5714
5717 if (!list)
5718 return nullptr;
5719
5721 for (auto *fromTypeParam : *list) {
5722 if (auto toTypeParamOrErr = import(fromTypeParam))
5723 toTypeParams.push_back(*toTypeParamOrErr);
5724 else
5725 return toTypeParamOrErr.takeError();
5726 }
5727
5728 auto LAngleLocOrErr = import(list->getLAngleLoc());
5729 if (!LAngleLocOrErr)
5730 return LAngleLocOrErr.takeError();
5731
5732 auto RAngleLocOrErr = import(list->getRAngleLoc());
5733 if (!RAngleLocOrErr)
5734 return RAngleLocOrErr.takeError();
5735
5736 return ObjCTypeParamList::create(Importer.getToContext(),
5737 *LAngleLocOrErr,
5738 toTypeParams,
5739 *RAngleLocOrErr);
5740}
5741
5743 // If this class has a definition in the translation unit we're coming from,
5744 // but this particular declaration is not that definition, import the
5745 // definition and map to that.
5747 if (Definition && Definition != D) {
5748 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5749 return Importer.MapImported(D, *ImportedDefOrErr);
5750 else
5751 return ImportedDefOrErr.takeError();
5752 }
5753
5754 // Import the major distinguishing characteristics of an @interface.
5755 DeclContext *DC, *LexicalDC;
5756 DeclarationName Name;
5757 SourceLocation Loc;
5758 NamedDecl *ToD;
5759 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5760 return std::move(Err);
5761 if (ToD)
5762 return ToD;
5763
5764 // Look for an existing interface with the same name.
5765 ObjCInterfaceDecl *MergeWithIface = nullptr;
5766 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5767 for (auto *FoundDecl : FoundDecls) {
5768 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5769 continue;
5770
5771 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5772 break;
5773 }
5774
5775 // Create an interface declaration, if one does not already exist.
5776 ObjCInterfaceDecl *ToIface = MergeWithIface;
5777 if (!ToIface) {
5778 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5779 if (!AtBeginLocOrErr)
5780 return AtBeginLocOrErr.takeError();
5781
5782 if (GetImportedOrCreateDecl(
5783 ToIface, D, Importer.getToContext(), DC,
5784 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5785 /*TypeParamList=*/nullptr,
5786 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5787 return ToIface;
5788 ToIface->setLexicalDeclContext(LexicalDC);
5789 LexicalDC->addDeclInternal(ToIface);
5790 }
5791 Importer.MapImported(D, ToIface);
5792 // Import the type parameter list after MapImported, to avoid
5793 // loops when bringing in their DeclContext.
5794 if (auto ToPListOrErr =
5796 ToIface->setTypeParamList(*ToPListOrErr);
5797 else
5798 return ToPListOrErr.takeError();
5799
5801 if (Error Err = ImportDefinition(D, ToIface))
5802 return std::move(Err);
5803
5804 return ToIface;
5805}
5806
5809 ObjCCategoryDecl *Category;
5810 if (Error Err = importInto(Category, D->getCategoryDecl()))
5811 return std::move(Err);
5812
5813 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5814 if (!ToImpl) {
5815 DeclContext *DC, *LexicalDC;
5816 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5817 return std::move(Err);
5818
5819 Error Err = Error::success();
5820 auto ToLocation = importChecked(Err, D->getLocation());
5821 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5822 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5823 if (Err)
5824 return std::move(Err);
5825
5826 if (GetImportedOrCreateDecl(
5827 ToImpl, D, Importer.getToContext(), DC,
5828 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5829 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5830 return ToImpl;
5831
5832 ToImpl->setLexicalDeclContext(LexicalDC);
5833 LexicalDC->addDeclInternal(ToImpl);
5834 Category->setImplementation(ToImpl);
5835 }
5836
5837 Importer.MapImported(D, ToImpl);
5838 if (Error Err = ImportDeclContext(D))
5839 return std::move(Err);
5840
5841 return ToImpl;
5842}
5843
5846 // Find the corresponding interface.
5847 ObjCInterfaceDecl *Iface;
5848 if (Error Err = importInto(Iface, D->getClassInterface()))
5849 return std::move(Err);
5850
5851 // Import the superclass, if any.
5852 ObjCInterfaceDecl *Super;
5853 if (Error Err = importInto(Super, D->getSuperClass()))
5854 return std::move(Err);
5855
5857 if (!Impl) {
5858 // We haven't imported an implementation yet. Create a new @implementation
5859 // now.
5860 DeclContext *DC, *LexicalDC;
5861 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5862 return std::move(Err);
5863
5864 Error Err = Error::success();
5865 auto ToLocation = importChecked(Err, D->getLocation());
5866 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5867 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5868 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5869 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5870 if (Err)
5871 return std::move(Err);
5872
5873 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5874 DC, Iface, Super,
5875 ToLocation,
5876 ToAtStartLoc,
5877 ToSuperClassLoc,
5878 ToIvarLBraceLoc,
5879 ToIvarRBraceLoc))
5880 return Impl;
5881
5882 Impl->setLexicalDeclContext(LexicalDC);
5883
5884 // Associate the implementation with the class it implements.
5885 Iface->setImplementation(Impl);
5886 Importer.MapImported(D, Iface->getImplementation());
5887 } else {
5888 Importer.MapImported(D, Iface->getImplementation());
5889
5890 // Verify that the existing @implementation has the same superclass.
5891 if ((Super && !Impl->getSuperClass()) ||
5892 (!Super && Impl->getSuperClass()) ||
5893 (Super && Impl->getSuperClass() &&
5895 Impl->getSuperClass()))) {
5896 Importer.ToDiag(Impl->getLocation(),
5897 diag::warn_odr_objc_superclass_inconsistent)
5898 << Iface->getDeclName();
5899 // FIXME: It would be nice to have the location of the superclass
5900 // below.
5901 if (Impl->getSuperClass())
5902 Importer.ToDiag(Impl->getLocation(),
5903 diag::note_odr_objc_superclass)
5904 << Impl->getSuperClass()->getDeclName();
5905 else
5906 Importer.ToDiag(Impl->getLocation(),
5907 diag::note_odr_objc_missing_superclass);
5908 if (D->getSuperClass())
5909 Importer.FromDiag(D->getLocation(),
5910 diag::note_odr_objc_superclass)
5911 << D->getSuperClass()->getDeclName();
5912 else
5913 Importer.FromDiag(D->getLocation(),
5914 diag::note_odr_objc_missing_superclass);
5915
5916 return make_error<ASTImportError>(ASTImportError::NameConflict);
5917 }
5918 }
5919
5920 // Import all of the members of this @implementation.
5921 if (Error Err = ImportDeclContext(D))
5922 return std::move(Err);
5923
5924 return Impl;
5925}
5926
5928 // Import the major distinguishing characteristics of an @property.
5929 DeclContext *DC, *LexicalDC;
5930 DeclarationName Name;
5931 SourceLocation Loc;
5932 NamedDecl *ToD;
5933 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5934 return std::move(Err);
5935 if (ToD)
5936 return ToD;
5937
5938 // Check whether we have already imported this property.
5939 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5940 for (auto *FoundDecl : FoundDecls) {
5941 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5942 // Instance and class properties can share the same name but are different
5943 // declarations.
5944 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5945 continue;
5946
5947 // Check property types.
5948 if (!Importer.IsStructurallyEquivalent(D->getType(),
5949 FoundProp->getType())) {
5950 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5951 << Name << D->getType() << FoundProp->getType();
5952 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5953 << FoundProp->getType();
5954
5955 return make_error<ASTImportError>(ASTImportError::NameConflict);
5956 }
5957
5958 // FIXME: Check property attributes, getters, setters, etc.?
5959
5960 // Consider these properties to be equivalent.
5961 Importer.MapImported(D, FoundProp);
5962 return FoundProp;
5963 }
5964 }
5965
5966 Error Err = Error::success();
5967 auto ToType = importChecked(Err, D->getType());
5968 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5969 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5970 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5971 if (Err)
5972 return std::move(Err);
5973
5974 // Create the new property.
5975 ObjCPropertyDecl *ToProperty;
5976 if (GetImportedOrCreateDecl(
5977 ToProperty, D, Importer.getToContext(), DC, Loc,
5978 Name.getAsIdentifierInfo(), ToAtLoc,
5979 ToLParenLoc, ToType,
5980 ToTypeSourceInfo, D->getPropertyImplementation()))
5981 return ToProperty;
5982
5983 auto ToGetterName = importChecked(Err, D->getGetterName());
5984 auto ToSetterName = importChecked(Err, D->getSetterName());
5985 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5986 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5987 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5988 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5989 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5990 if (Err)
5991 return std::move(Err);
5992
5993 ToProperty->setLexicalDeclContext(LexicalDC);
5994 LexicalDC->addDeclInternal(ToProperty);
5995
5999 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6000 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6001 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6002 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6003 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6004 return ToProperty;
6005}
6006
6010 if (Error Err = importInto(Property, D->getPropertyDecl()))
6011 return std::move(Err);
6012
6013 DeclContext *DC, *LexicalDC;
6014 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6015 return std::move(Err);
6016
6017 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6018
6019 // Import the ivar (for an @synthesize).
6020 ObjCIvarDecl *Ivar = nullptr;
6021 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6022 return std::move(Err);
6023
6024 ObjCPropertyImplDecl *ToImpl
6025 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6026 Property->getQueryKind());
6027 if (!ToImpl) {
6028
6029 Error Err = Error::success();
6030 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6031 auto ToLocation = importChecked(Err, D->getLocation());
6032 auto ToPropertyIvarDeclLoc =
6034 if (Err)
6035 return std::move(Err);
6036
6037 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6038 ToBeginLoc,
6039 ToLocation, Property,
6040 D->getPropertyImplementation(), Ivar,
6041 ToPropertyIvarDeclLoc))
6042 return ToImpl;
6043
6044 ToImpl->setLexicalDeclContext(LexicalDC);
6045 LexicalDC->addDeclInternal(ToImpl);
6046 } else {
6047 // Check that we have the same kind of property implementation (@synthesize
6048 // vs. @dynamic).
6050 Importer.ToDiag(ToImpl->getLocation(),
6051 diag::warn_odr_objc_property_impl_kind_inconsistent)
6052 << Property->getDeclName()
6053 << (ToImpl->getPropertyImplementation()
6055 Importer.FromDiag(D->getLocation(),
6056 diag::note_odr_objc_property_impl_kind)
6057 << D->getPropertyDecl()->getDeclName()
6059
6060 return make_error<ASTImportError>(ASTImportError::NameConflict);
6061 }
6062
6063 // For @synthesize, check that we have the same
6065 Ivar != ToImpl->getPropertyIvarDecl()) {
6066 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6067 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6068 << Property->getDeclName()
6069 << ToImpl->getPropertyIvarDecl()->getDeclName()
6070 << Ivar->getDeclName();
6071 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6072 diag::note_odr_objc_synthesize_ivar_here)
6074
6075 return make_error<ASTImportError>(ASTImportError::NameConflict);
6076 }
6077
6078 // Merge the existing implementation with the new implementation.
6079 Importer.MapImported(D, ToImpl);
6080 }
6081
6082 return ToImpl;
6083}
6084
6087 Error Err = Error::success();
6088 auto ToType = importChecked(Err, D->getType());
6089 auto ToValue = importChecked(Err, D->getValue());
6090 if (Err)
6091 return std::move(Err);
6092
6094 auto Create = [this](QualType T, const APValue &V) {
6095 return Importer.ToContext.getTemplateParamObjectDecl(T, V);
6096 };
6097 (void)GetImportedOrCreateSpecialDecl(ToD, Create, D, ToType, ToValue);
6098 return ToD;
6099}
6100
6103 // For template arguments, we adopt the translation unit as our declaration
6104 // context. This context will be fixed when (during) the actual template
6105 // declaration is created.
6106
6107 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6108 if (!BeginLocOrErr)
6109 return BeginLocOrErr.takeError();
6110
6111 ExpectedSLoc LocationOrErr = import(D->getLocation());
6112 if (!LocationOrErr)
6113 return LocationOrErr.takeError();
6114
6115 TemplateTypeParmDecl *ToD = nullptr;
6116 if (GetImportedOrCreateDecl(
6117 ToD, D, Importer.getToContext(),
6118 Importer.getToContext().getTranslationUnitDecl(),
6119 *BeginLocOrErr, *LocationOrErr,
6120 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6122 D->hasTypeConstraint()))
6123 return ToD;
6124
6125 // Import the type-constraint
6126 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6127
6128 Error Err = Error::success();
6129 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6130 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6131 if (Err)
6132 return std::move(Err);
6133
6134 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6135 }
6136
6137 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6138 return Err;
6139
6140 return ToD;
6141}
6142
6145
6146 Error Err = Error::success();
6147 auto ToDeclName = importChecked(Err, D->getDeclName());
6148 auto ToLocation = importChecked(Err, D->getLocation());
6149 auto ToType = importChecked(Err, D->getType());
6150 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6151 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6152 if (Err)
6153 return std::move(Err);
6154
6155 NonTypeTemplateParmDecl *ToD = nullptr;
6156 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6157 Importer.getToContext().getTranslationUnitDecl(),
6158 ToInnerLocStart, ToLocation, D->getDepth(),
6159 D->getPosition(),
6160 ToDeclName.getAsIdentifierInfo(), ToType,
6161 D->isParameterPack(), ToTypeSourceInfo))
6162 return ToD;
6163
6164 Err = importTemplateParameterDefaultArgument(D, ToD);
6165 if (Err)
6166 return Err;
6167
6168 return ToD;
6169}
6170
6173 bool IsCanonical = false;
6174 if (auto *CanonD = Importer.getFromContext()
6175 .findCanonicalTemplateTemplateParmDeclInternal(D);
6176 CanonD == D)
6177 IsCanonical = true;
6178
6179 // Import the name of this declaration.
6180 auto NameOrErr = import(D->getDeclName());
6181 if (!NameOrErr)
6182 return NameOrErr.takeError();
6183
6184 // Import the location of this declaration.
6185 ExpectedSLoc LocationOrErr = import(D->getLocation());
6186 if (!LocationOrErr)
6187 return LocationOrErr.takeError();
6188
6189 // Import template parameters.
6190 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6191 if (!TemplateParamsOrErr)
6192 return TemplateParamsOrErr.takeError();
6193
6194 TemplateTemplateParmDecl *ToD = nullptr;
6195 if (GetImportedOrCreateDecl(
6196 ToD, D, Importer.getToContext(),
6197 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6198 D->getDepth(), D->getPosition(), D->isParameterPack(),
6199 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6200 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6201 return ToD;
6202
6203 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6204 return Err;
6205
6206 if (IsCanonical)
6207 return Importer.getToContext()
6208 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6209
6210 return ToD;
6211}
6212
6213// Returns the definition for a (forward) declaration of a TemplateDecl, if
6214// it has any definition in the redecl chain.
6215template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6216 assert(D->getTemplatedDecl() && "Should be called on templates only");
6217 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6218 if (!ToTemplatedDef)
6219 return nullptr;
6220 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6221 return cast_or_null<T>(TemplateWithDef);
6222}
6223
6225
6226 // Import the major distinguishing characteristics of this class template.
6227 DeclContext *DC, *LexicalDC;
6228 DeclarationName Name;
6229 SourceLocation Loc;
6230 NamedDecl *ToD;
6231 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6232 return std::move(Err);
6233 if (ToD)
6234 return ToD;
6235
6236 // Should check if a declaration is friend in a dependent context.
6237 // Such templates are not linked together in a declaration chain.
6238 // The ASTImporter strategy is to map existing forward declarations to
6239 // imported ones only if strictly necessary, otherwise import these as new
6240 // forward declarations. In case of the "dependent friend" declarations, new
6241 // declarations are created, but not linked in a declaration chain.
6242 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6243 return TD->getFriendObjectKind() != Decl::FOK_None &&
6244 TD->getLexicalDeclContext()->isDependentContext();
6245 };
6246 bool DependentFriend = IsDependentFriend(D);
6247
6248 ClassTemplateDecl *FoundByLookup = nullptr;
6249
6250 // We may already have a template of the same name; try to find and match it.
6251 if (!DC->isFunctionOrMethod()) {
6252 SmallVector<NamedDecl *, 4> ConflictingDecls;
6253 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6254 for (auto *FoundDecl : FoundDecls) {
6255 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6257 continue;
6258
6259 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6260 if (FoundTemplate) {
6261 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6262 continue;
6263
6264 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6265 bool IgnoreTemplateParmDepth =
6266 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6268 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6269 IgnoreTemplateParmDepth)) {
6270 if (DependentFriend || IsDependentFriend(FoundTemplate))
6271 continue;
6272
6273 ClassTemplateDecl *TemplateWithDef =
6274 getTemplateDefinition(FoundTemplate);
6275 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6276 return Importer.MapImported(D, TemplateWithDef);
6277 if (!FoundByLookup)
6278 FoundByLookup = FoundTemplate;
6279 // Search in all matches because there may be multiple decl chains,
6280 // see ASTTests test ImportExistingFriendClassTemplateDef.
6281 continue;
6282 }
6283 // When importing a friend, it is possible that multiple declarations
6284 // with same name can co-exist in specific cases (if a template contains
6285 // a friend template and has a specialization). For this case the
6286 // declarations should match, except that the "template depth" is
6287 // different. No linking of previous declaration is needed in this case.
6288 // FIXME: This condition may need refinement.
6289 if (D->getFriendObjectKind() != Decl::FOK_None &&
6290 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6291 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6292 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6293 /*IgnoreTemplateParmDepth=*/true))
6294 continue;
6295
6296 ConflictingDecls.push_back(FoundDecl);
6297 }
6298 }
6299
6300 if (!ConflictingDecls.empty()) {
6301 ExpectedName NameOrErr = Importer.HandleNameConflict(
6302 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6303 ConflictingDecls.size());
6304 if (NameOrErr)
6305 Name = NameOrErr.get();
6306 else
6307 return NameOrErr.takeError();
6308 }
6309 }
6310
6311 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6312
6313 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6314 if (!TemplateParamsOrErr)
6315 return TemplateParamsOrErr.takeError();
6316
6317 // Create the declaration that is being templated.
6318 CXXRecordDecl *ToTemplated;
6319 if (Error Err = importInto(ToTemplated, FromTemplated))
6320 return std::move(Err);
6321
6322 // Create the class template declaration itself.
6324 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6325 *TemplateParamsOrErr, ToTemplated))
6326 return D2;
6327
6328 ToTemplated->setDescribedClassTemplate(D2);
6329
6330 D2->setAccess(D->getAccess());
6331 D2->setLexicalDeclContext(LexicalDC);
6332
6333 addDeclToContexts(D, D2);
6334 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6335
6336 if (FoundByLookup) {
6337 auto *Recent =
6338 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6339
6340 // It is possible that during the import of the class template definition
6341 // we start the import of a fwd friend decl of the very same class template
6342 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6343 // had been created earlier and by that time the lookup could not find
6344 // anything existing, so it has no previous decl. Later, (still during the
6345 // import of the fwd friend decl) we start to import the definition again
6346 // and this time the lookup finds the previous fwd friend class template.
6347 // In this case we must set up the previous decl for the templated decl.
6348 if (!ToTemplated->getPreviousDecl()) {
6349 assert(FoundByLookup->getTemplatedDecl() &&
6350 "Found decl must have its templated decl set");
6351 CXXRecordDecl *PrevTemplated =
6352 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6353 if (ToTemplated != PrevTemplated)
6354 ToTemplated->setPreviousDecl(PrevTemplated);
6355 }
6356
6357 D2->setPreviousDecl(Recent);
6358 }
6359
6360 return D2;
6361}
6362
6365 ClassTemplateDecl *ClassTemplate;
6366 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6367 return std::move(Err);
6368
6369 // Import the context of this declaration.
6370 DeclContext *DC, *LexicalDC;
6371 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6372 return std::move(Err);
6373
6374 // Import template arguments.
6376 if (Error Err =
6377 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6378 return std::move(Err);
6379 // Try to find an existing specialization with these template arguments and
6380 // template parameter list.
6381 llvm::FoldingSetInsertToken InsertToken;
6382 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6384 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6385
6386 // Import template parameters.
6387 TemplateParameterList *ToTPList = nullptr;
6388
6389 if (PartialSpec) {
6390 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6391 if (!ToTPListOrErr)
6392 return ToTPListOrErr.takeError();
6393 ToTPList = *ToTPListOrErr;
6394 PrevDecl = ClassTemplate->findPartialSpecialization(
6395 TemplateArgs, *ToTPListOrErr, InsertToken);
6396 } else
6397 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertToken);
6398
6399 if (PrevDecl) {
6400 if (IsStructuralMatch(D, PrevDecl)) {
6401 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6402 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6403 Importer.MapImported(D, PrevDefinition);
6404 // Import those default field initializers which have been
6405 // instantiated in the "From" context, but not in the "To" context.
6406 for (auto *FromField : D->fields()) {
6407 auto ToOrErr = import(FromField);
6408 if (!ToOrErr)
6409 return ToOrErr.takeError();
6410 }
6411
6412 // Import those methods which have been instantiated in the
6413 // "From" context, but not in the "To" context.
6414 for (CXXMethodDecl *FromM : D->methods()) {
6415 auto ToOrErr = import(FromM);
6416 if (!ToOrErr)
6417 return ToOrErr.takeError();
6418 }
6419
6420 // TODO Import instantiated default arguments.
6421 // TODO Import instantiated exception specifications.
6422 //
6423 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6424 // what else could be fused during an AST merge.
6425 return PrevDefinition;
6426 }
6427 } else { // ODR violation.
6428 // FIXME HandleNameConflict
6429 return make_error<ASTImportError>(ASTImportError::NameConflict);
6430 }
6431 }
6432
6433 // Import the location of this declaration.
6434 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6435 if (!BeginLocOrErr)
6436 return BeginLocOrErr.takeError();
6437 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6438 if (!IdLocOrErr)
6439 return IdLocOrErr.takeError();
6440
6441 // Import TemplateArgumentListInfo.
6442 TemplateArgumentListInfo ToTAInfo;
6443 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6444 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6445 return std::move(Err);
6446 }
6447
6448 // Create the specialization.
6449 ClassTemplateSpecializationDecl *D2 = nullptr;
6450 if (PartialSpec) {
6451 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6452 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6453 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6454 /*CanonInjectedTST=*/CanQualType(),
6455 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6456 return D2;
6457
6458 // Update InsertToken, because preceding import calls may have invalidated
6459 // it by adding new specializations.
6461 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6462 InsertToken))
6463 // Add this partial specialization to the class template.
6464 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertToken);
6466 import(PartialSpec->getInstantiatedFromMember()))
6467 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6468 else
6469 return ToInstOrErr.takeError();
6470
6471 updateLookupTableForTemplateParameters(*ToTPList);
6472 } else { // Not a partial specialization.
6473 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6474 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6475 TemplateArgs, D->hasStrictPackMatch(),
6476 PrevDecl))
6477 return D2;
6478
6479 // Update InsertToken, because preceding import calls may have invalidated
6480 // it by adding new specializations.
6481 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertToken))
6482 // Add this specialization to the class template.
6483 ClassTemplate->AddSpecialization(D2, InsertToken);
6484 }
6485
6487
6488 // Set the context of this specialization/instantiation.
6489 D2->setLexicalDeclContext(LexicalDC);
6490
6491 // Add to the DC only if it was an explicit specialization/instantiation.
6493 LexicalDC->addDeclInternal(D2);
6494 }
6495
6496 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6497 D2->setBraceRange(*BraceRangeOrErr);
6498 else
6499 return BraceRangeOrErr.takeError();
6500
6501 if (Error Err = ImportTemplateParameterLists(D, D2))
6502 return std::move(Err);
6503
6504 // Import the qualifier, if any.
6505 if (auto LocOrErr = import(D->getQualifierLoc()))
6506 D2->setQualifierInfo(*LocOrErr);
6507 else
6508 return LocOrErr.takeError();
6509
6510 if (D->getTemplateArgsAsWritten())
6511 D2->setTemplateArgsAsWritten(ToTAInfo);
6512
6513 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6514 D2->setTemplateKeywordLoc(*LocOrErr);
6515 else
6516 return LocOrErr.takeError();
6517
6518 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6519 D2->setExternKeywordLoc(*LocOrErr);
6520 else
6521 return LocOrErr.takeError();
6522
6523 if (D->getPointOfInstantiation().isValid()) {
6524 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6525 D2->setPointOfInstantiation(*POIOrErr);
6526 else
6527 return POIOrErr.takeError();
6528 }
6529
6531
6532 if (auto P = D->getInstantiatedFrom()) {
6533 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6534 if (auto CTDorErr = import(CTD))
6535 D2->setInstantiationOf(*CTDorErr);
6536 } else {
6538 auto CTPSDOrErr = import(CTPSD);
6539 if (!CTPSDOrErr)
6540 return CTPSDOrErr.takeError();
6542 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6543 for (unsigned I = 0; I < DArgs.size(); ++I) {
6544 const TemplateArgument &DArg = DArgs[I];
6545 if (auto ArgOrErr = import(DArg))
6546 D2ArgsVec[I] = *ArgOrErr;
6547 else
6548 return ArgOrErr.takeError();
6549 }
6551 *CTPSDOrErr,
6552 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6553 }
6554 }
6555
6556 if (D->isCompleteDefinition())
6557 if (Error Err = ImportDefinition(D, D2))
6558 return std::move(Err);
6559
6560 return D2;
6561}
6562
6564 // Import the major distinguishing characteristics of this variable template.
6565 DeclContext *DC, *LexicalDC;
6566 DeclarationName Name;
6567 SourceLocation Loc;
6568 NamedDecl *ToD;
6569 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6570 return std::move(Err);
6571 if (ToD)
6572 return ToD;
6573
6574 // We may already have a template of the same name; try to find and match it.
6575 assert(!DC->isFunctionOrMethod() &&
6576 "Variable templates cannot be declared at function scope");
6577
6578 SmallVector<NamedDecl *, 4> ConflictingDecls;
6579 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6580 VarTemplateDecl *FoundByLookup = nullptr;
6581 for (auto *FoundDecl : FoundDecls) {
6582 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6583 continue;
6584
6585 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6586 // Use the templated decl, some linkage flags are set only there.
6587 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6588 D->getTemplatedDecl()))
6589 continue;
6590 if (IsStructuralMatch(D, FoundTemplate)) {
6591 // FIXME Check for ODR error if the two definitions have
6592 // different initializers?
6593 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6594 if (D->getDeclContext()->isRecord()) {
6595 assert(FoundTemplate->getDeclContext()->isRecord() &&
6596 "Member variable template imported as non-member, "
6597 "inconsistent imported AST?");
6598 if (FoundDef)
6599 return Importer.MapImported(D, FoundDef);
6601 return Importer.MapImported(D, FoundTemplate);
6602 } else {
6603 if (FoundDef && D->isThisDeclarationADefinition())
6604 return Importer.MapImported(D, FoundDef);
6605 }
6606 FoundByLookup = FoundTemplate;
6607 break;
6608 }
6609 ConflictingDecls.push_back(FoundDecl);
6610 }
6611 }
6612
6613 if (!ConflictingDecls.empty()) {
6614 ExpectedName NameOrErr = Importer.HandleNameConflict(
6615 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6616 ConflictingDecls.size());
6617 if (NameOrErr)
6618 Name = NameOrErr.get();
6619 else
6620 return NameOrErr.takeError();
6621 }
6622
6623 VarDecl *DTemplated = D->getTemplatedDecl();
6624
6625 // Import the type.
6626 // FIXME: Value not used?
6627 ExpectedType TypeOrErr = import(DTemplated->getType());
6628 if (!TypeOrErr)
6629 return TypeOrErr.takeError();
6630
6631 // Create the declaration that is being templated.
6632 VarDecl *ToTemplated;
6633 if (Error Err = importInto(ToTemplated, DTemplated))
6634 return std::move(Err);
6635
6636 // Create the variable template declaration itself.
6637 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6638 if (!TemplateParamsOrErr)
6639 return TemplateParamsOrErr.takeError();
6640
6641 VarTemplateDecl *ToVarTD;
6642 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6643 Name, *TemplateParamsOrErr, ToTemplated))
6644 return ToVarTD;
6645
6646 ToTemplated->setDescribedVarTemplate(ToVarTD);
6647
6648 ToVarTD->setAccess(D->getAccess());
6649 ToVarTD->setLexicalDeclContext(LexicalDC);
6650 LexicalDC->addDeclInternal(ToVarTD);
6651 if (DC != Importer.getToContext().getTranslationUnitDecl())
6652 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6653
6654 if (FoundByLookup) {
6655 auto *Recent =
6656 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6657 if (!ToTemplated->getPreviousDecl()) {
6658 auto *PrevTemplated =
6659 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6660 if (ToTemplated != PrevTemplated)
6661 ToTemplated->setPreviousDecl(PrevTemplated);
6662 }
6663 ToVarTD->setPreviousDecl(Recent);
6664 }
6665
6666 return ToVarTD;
6667}
6668
6671 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6672 // in an analog way (but specialized for this case).
6673
6675 auto RedeclIt = Redecls.begin();
6676 // Import the first part of the decl chain. I.e. import all previous
6677 // declarations starting from the canonical decl.
6678 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6679 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6680 if (!RedeclOrErr)
6681 return RedeclOrErr.takeError();
6682 }
6683 assert(*RedeclIt == D);
6684
6685 VarTemplateDecl *VarTemplate = nullptr;
6687 return std::move(Err);
6688
6689 // Import the context of this declaration.
6690 DeclContext *DC, *LexicalDC;
6691 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6692 return std::move(Err);
6693
6694 // Import the location of this declaration.
6695 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6696 if (!BeginLocOrErr)
6697 return BeginLocOrErr.takeError();
6698
6699 auto IdLocOrErr = import(D->getLocation());
6700 if (!IdLocOrErr)
6701 return IdLocOrErr.takeError();
6702
6703 // Import template arguments.
6705 if (Error Err =
6706 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6707 return std::move(Err);
6708
6709 // Try to find an existing specialization with these template arguments.
6710 llvm::FoldingSetInsertToken InsertToken;
6711 VarTemplateSpecializationDecl *FoundSpecialization =
6712 VarTemplate->findSpecialization(TemplateArgs, InsertToken);
6713 if (FoundSpecialization) {
6714 if (IsStructuralMatch(D, FoundSpecialization)) {
6715 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6716 if (D->getDeclContext()->isRecord()) {
6717 // In a record, it is allowed only to have one optional declaration and
6718 // one definition of the (static or constexpr) variable template.
6719 assert(
6720 FoundSpecialization->getDeclContext()->isRecord() &&
6721 "Member variable template specialization imported as non-member, "
6722 "inconsistent imported AST?");
6723 if (FoundDef)
6724 return Importer.MapImported(D, FoundDef);
6726 return Importer.MapImported(D, FoundSpecialization);
6727 } else {
6728 // If definition is imported and there is already one, map to it.
6729 // Otherwise create a new variable and link it to the existing.
6730 if (FoundDef && D->isThisDeclarationADefinition())
6731 return Importer.MapImported(D, FoundDef);
6732 }
6733 } else {
6734 return make_error<ASTImportError>(ASTImportError::NameConflict);
6735 }
6736 }
6737
6738 VarTemplateSpecializationDecl *D2 = nullptr;
6739
6740 TemplateArgumentListInfo ToTAInfo;
6741 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6742 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6743 return std::move(Err);
6744 }
6745
6746 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6747 // Create a new specialization.
6748 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6749 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6750 if (!ToTPListOrErr)
6751 return ToTPListOrErr.takeError();
6752
6753 PartVarSpecDecl *ToPartial;
6754 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6755 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6756 VarTemplate, QualType(), nullptr,
6757 D->getStorageClass(), TemplateArgs))
6758 return ToPartial;
6759
6760 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6761 import(FromPartial->getInstantiatedFromMember()))
6762 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6763 else
6764 return ToInstOrErr.takeError();
6765
6766 if (FromPartial->isMemberSpecialization())
6767 ToPartial->setMemberSpecialization();
6768
6769 D2 = ToPartial;
6770
6771 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6772 // to adopt template parameters.
6773 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6774 } else { // Full specialization
6775 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6776 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6777 QualType(), nullptr, D->getStorageClass(),
6778 TemplateArgs))
6779 return D2;
6780 }
6781
6782 // Update InsertToken, because preceding import calls may have invalidated
6783 // it by adding new specializations.
6784 if (!VarTemplate->findSpecialization(TemplateArgs, InsertToken))
6785 VarTemplate->AddSpecialization(D2, InsertToken);
6786
6787 QualType T;
6788 if (Error Err = importInto(T, D->getType()))
6789 return std::move(Err);
6790 D2->setType(T);
6791
6792 auto TInfoOrErr = import(D->getTypeSourceInfo());
6793 if (!TInfoOrErr)
6794 return TInfoOrErr.takeError();
6795 D2->setTypeSourceInfo(*TInfoOrErr);
6796
6797 if (D->getPointOfInstantiation().isValid()) {
6798 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6799 D2->setPointOfInstantiation(*POIOrErr);
6800 else
6801 return POIOrErr.takeError();
6802 }
6803
6805
6806 if (D->getTemplateArgsAsWritten())
6807 D2->setTemplateArgsAsWritten(ToTAInfo);
6808
6809 if (auto LocOrErr = import(D->getQualifierLoc()))
6810 D2->setQualifierInfo(*LocOrErr);
6811 else
6812 return LocOrErr.takeError();
6813
6814 if (D->isConstexpr())
6815 D2->setConstexpr(true);
6816
6817 D2->setAccess(D->getAccess());
6818
6819 if (Error Err = ImportInitializer(D, D2))
6820 return std::move(Err);
6821
6822 if (FoundSpecialization)
6823 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6824
6825 addDeclToContexts(D, D2);
6826
6827 // Import the rest of the chain. I.e. import all subsequent declarations.
6828 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6829 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6830 if (!RedeclOrErr)
6831 return RedeclOrErr.takeError();
6832 }
6833
6834 return D2;
6835}
6836
6839 DeclContext *DC, *LexicalDC;
6840 DeclarationName Name;
6841 SourceLocation Loc;
6842 NamedDecl *ToD;
6843
6844 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6845 return std::move(Err);
6846
6847 if (ToD)
6848 return ToD;
6849
6850 const FunctionTemplateDecl *FoundByLookup = nullptr;
6851
6852 // Try to find a function in our own ("to") context with the same name, same
6853 // type, and in the same context as the function we're importing.
6854 // FIXME Split this into a separate function.
6855 if (!LexicalDC->isFunctionOrMethod()) {
6857 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6858 for (auto *FoundDecl : FoundDecls) {
6859 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6860 continue;
6861
6862 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6863 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6864 continue;
6865 if (IsStructuralMatch(D, FoundTemplate)) {
6866 FunctionTemplateDecl *TemplateWithDef =
6867 getTemplateDefinition(FoundTemplate);
6868 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6869 return Importer.MapImported(D, TemplateWithDef);
6870
6871 FoundByLookup = FoundTemplate;
6872 break;
6873 // TODO: handle conflicting names
6874 }
6875 }
6876 }
6877 }
6878
6879 auto ParamsOrErr = import(D->getTemplateParameters());
6880 if (!ParamsOrErr)
6881 return ParamsOrErr.takeError();
6882 TemplateParameterList *Params = *ParamsOrErr;
6883
6884 FunctionDecl *TemplatedFD;
6885 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6886 return std::move(Err);
6887
6888 // At creation of the template the template parameters are "adopted"
6889 // (DeclContext is changed). After this possible change the lookup table
6890 // must be updated.
6891 // At deduction guides the DeclContext of the template parameters may be
6892 // different from what we would expect, it may be the class template, or a
6893 // probably different CXXDeductionGuideDecl. This may come from the fact that
6894 // the template parameter objects may be shared between deduction guides or
6895 // the class template, and at creation of multiple FunctionTemplateDecl
6896 // objects (for deduction guides) the same parameters are re-used. The
6897 // "adoption" happens multiple times with different parent, even recursively
6898 // for TemplateTemplateParmDecl. The same happens at import when the
6899 // FunctionTemplateDecl objects are created, but in different order.
6900 // In this way the DeclContext of these template parameters is not necessarily
6901 // the same as in the "from" context.
6903 OldParamDC.reserve(Params->size());
6904 llvm::transform(*Params, std::back_inserter(OldParamDC),
6905 [](NamedDecl *ND) { return ND->getDeclContext(); });
6906
6907 FunctionTemplateDecl *ToFunc;
6908 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6909 Params, TemplatedFD))
6910 return ToFunc;
6911
6912 // Fail if TemplatedFD is already part of a template.
6913 // The template should have been found by structural equivalence check before,
6914 // or ToFunc should be already imported.
6915 // If not, there is AST incompatibility that can be caused by previous import
6916 // errors. (NameConflict is not exact here.)
6917 if (TemplatedFD->getDescribedTemplate())
6918 return make_error<ASTImportError>(ASTImportError::NameConflict);
6919
6920 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6921
6922 ToFunc->setAccess(D->getAccess());
6923 ToFunc->setLexicalDeclContext(LexicalDC);
6924 addDeclToContexts(D, ToFunc);
6925
6926 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6927 if (LT && !OldParamDC.empty()) {
6928 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6929 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6930 }
6931
6932 if (FoundByLookup) {
6933 auto *Recent =
6934 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6935 if (!TemplatedFD->getPreviousDecl()) {
6936 assert(FoundByLookup->getTemplatedDecl() &&
6937 "Found decl must have its templated decl set");
6938 auto *PrevTemplated =
6939 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6940 if (TemplatedFD != PrevTemplated)
6941 TemplatedFD->setPreviousDecl(PrevTemplated);
6942 }
6943 ToFunc->setPreviousDecl(Recent);
6944 }
6945
6946 return ToFunc;
6947}
6948
6950 DeclContext *DC, *LexicalDC;
6951 Error Err = ImportDeclContext(D, DC, LexicalDC);
6952 auto LocationOrErr = importChecked(Err, D->getLocation());
6953 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6954 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6955 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6956 if (Err)
6957 return std::move(Err);
6958
6959 ConceptDecl *To;
6960 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6961 NameDeclOrErr, ToTemplateParameters,
6962 ConstraintExpr))
6963 return To;
6964 To->setLexicalDeclContext(LexicalDC);
6965 LexicalDC->addDeclInternal(To);
6966 return To;
6967}
6968
6971 DeclContext *DC, *LexicalDC;
6972 Error Err = ImportDeclContext(D, DC, LexicalDC);
6973 auto RequiresLoc = importChecked(Err, D->getLocation());
6974 if (Err)
6975 return std::move(Err);
6976
6978 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
6979 return To;
6980 To->setLexicalDeclContext(LexicalDC);
6981 LexicalDC->addDeclInternal(To);
6982 return To;
6983}
6984
6987 DeclContext *DC, *LexicalDC;
6988 Error Err = ImportDeclContext(D, DC, LexicalDC);
6989 auto ToSL = importChecked(Err, D->getLocation());
6990 if (Err)
6991 return std::move(Err);
6992
6994 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
6995 return std::move(Err);
6996
6998 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
6999 return To;
7000 To->setLexicalDeclContext(LexicalDC);
7001 LexicalDC->addDeclInternal(To);
7002 return To;
7003}
7004
7005//----------------------------------------------------------------------------
7006// Import Statements
7007//----------------------------------------------------------------------------
7008
7010 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7011 << S->getStmtClassName();
7012 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7013}
7014
7015
7017 if (Importer.returnWithErrorInTest())
7018 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7020 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7021 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7022 // ToII is nullptr when no symbolic name is given for output operand
7023 // see ParseStmtAsm::ParseAsmOperandsOpt
7024 Names.push_back(ToII);
7025 }
7026
7027 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7028 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7029 // ToII is nullptr when no symbolic name is given for input operand
7030 // see ParseStmtAsm::ParseAsmOperandsOpt
7031 Names.push_back(ToII);
7032 }
7033
7034 SmallVector<Expr *, 4> Clobbers;
7035 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7036 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7037 Clobbers.push_back(*ClobberOrErr);
7038 else
7039 return ClobberOrErr.takeError();
7040
7041 }
7042
7043 SmallVector<Expr *, 4> Constraints;
7044 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7045 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7046 Constraints.push_back(*OutputOrErr);
7047 else
7048 return OutputOrErr.takeError();
7049 }
7050
7051 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7052 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7053 Constraints.push_back(*InputOrErr);
7054 else
7055 return InputOrErr.takeError();
7056 }
7057
7059 S->getNumLabels());
7060 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7061 return std::move(Err);
7062
7063 if (Error Err =
7064 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7065 return std::move(Err);
7066
7067 if (Error Err = ImportArrayChecked(
7068 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7069 return std::move(Err);
7070
7071 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7072 if (!AsmLocOrErr)
7073 return AsmLocOrErr.takeError();
7074 auto AsmStrOrErr = import(S->getAsmStringExpr());
7075 if (!AsmStrOrErr)
7076 return AsmStrOrErr.takeError();
7077 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7078 if (!RParenLocOrErr)
7079 return RParenLocOrErr.takeError();
7080
7081 return new (Importer.getToContext()) GCCAsmStmt(
7082 Importer.getToContext(),
7083 *AsmLocOrErr,
7084 S->isSimple(),
7085 S->isVolatile(),
7086 S->getNumOutputs(),
7087 S->getNumInputs(),
7088 Names.data(),
7089 Constraints.data(),
7090 Exprs.data(),
7091 *AsmStrOrErr,
7092 S->getNumClobbers(),
7093 Clobbers.data(),
7094 S->getNumLabels(),
7095 *RParenLocOrErr);
7096}
7097
7099
7100 Error Err = Error::success();
7101 auto ToDG = importChecked(Err, S->getDeclGroup());
7102 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7103 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7104 if (Err)
7105 return std::move(Err);
7106 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7107}
7108
7110 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7111 if (!ToSemiLocOrErr)
7112 return ToSemiLocOrErr.takeError();
7113 return new (Importer.getToContext()) NullStmt(
7114 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7115}
7116
7118 SmallVector<Stmt *, 8> ToStmts(S->size());
7119
7120 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7121 return std::move(Err);
7122
7123 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7124 if (!ToLBracLocOrErr)
7125 return ToLBracLocOrErr.takeError();
7126
7127 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7128 if (!ToRBracLocOrErr)
7129 return ToRBracLocOrErr.takeError();
7130
7131 FPOptionsOverride FPO =
7133 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7134 *ToLBracLocOrErr, *ToRBracLocOrErr);
7135}
7136
7138
7139 Error Err = Error::success();
7140 auto ToLHS = importChecked(Err, S->getLHS());
7141 auto ToRHS = importChecked(Err, S->getRHS());
7142 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7143 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7144 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7145 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7146 if (Err)
7147 return std::move(Err);
7148
7149 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7150 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7151 ToStmt->setSubStmt(ToSubStmt);
7152
7153 return ToStmt;
7154}
7155
7157
7158 Error Err = Error::success();
7159 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7160 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7161 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7162 if (Err)
7163 return std::move(Err);
7164
7165 return new (Importer.getToContext()) DefaultStmt(
7166 ToDefaultLoc, ToColonLoc, ToSubStmt);
7167}
7168
7170
7171 Error Err = Error::success();
7172 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7173 auto ToLabelDecl = importChecked(Err, S->getDecl());
7174 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7175 if (Err)
7176 return std::move(Err);
7177
7178 return new (Importer.getToContext()) LabelStmt(
7179 ToIdentLoc, ToLabelDecl, ToSubStmt);
7180}
7181
7183 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7184 if (!ToAttrLocOrErr)
7185 return ToAttrLocOrErr.takeError();
7186 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7187 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7188 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7189 return std::move(Err);
7190 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7191 if (!ToSubStmtOrErr)
7192 return ToSubStmtOrErr.takeError();
7193
7195 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7196}
7197
7199
7200 Error Err = Error::success();
7201 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7202 auto ToInit = importChecked(Err, S->getInit());
7203 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7204 auto ToCond = importChecked(Err, S->getCond());
7205 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7206 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7207 auto ToThen = importChecked(Err, S->getThen());
7208 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7209 auto ToElse = importChecked(Err, S->getElse());
7210 if (Err)
7211 return std::move(Err);
7212
7213 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7214 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7215 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7216}
7217
7219
7220 Error Err = Error::success();
7221 auto ToInit = importChecked(Err, S->getInit());
7222 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7223 auto ToCond = importChecked(Err, S->getCond());
7224 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7225 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7226 auto ToBody = importChecked(Err, S->getBody());
7227 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7228 if (Err)
7229 return std::move(Err);
7230
7231 auto *ToStmt =
7232 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7233 ToCond, ToLParenLoc, ToRParenLoc);
7234 ToStmt->setBody(ToBody);
7235 ToStmt->setSwitchLoc(ToSwitchLoc);
7236
7237 // Now we have to re-chain the cases.
7238 SwitchCase *LastChainedSwitchCase = nullptr;
7239 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7240 SC = SC->getNextSwitchCase()) {
7241 Expected<SwitchCase *> ToSCOrErr = import(SC);
7242 if (!ToSCOrErr)
7243 return ToSCOrErr.takeError();
7244 if (LastChainedSwitchCase)
7245 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7246 else
7247 ToStmt->setSwitchCaseList(*ToSCOrErr);
7248 LastChainedSwitchCase = *ToSCOrErr;
7249 }
7250
7251 return ToStmt;
7252}
7253
7255
7256 Error Err = Error::success();
7257 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7258 auto ToCond = importChecked(Err, S->getCond());
7259 auto ToBody = importChecked(Err, S->getBody());
7260 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7261 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7262 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7263 if (Err)
7264 return std::move(Err);
7265
7266 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7267 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7268}
7269
7271
7272 Error Err = Error::success();
7273 auto ToBody = importChecked(Err, S->getBody());
7274 auto ToCond = importChecked(Err, S->getCond());
7275 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7276 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7277 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7278 if (Err)
7279 return std::move(Err);
7280
7281 return new (Importer.getToContext()) DoStmt(
7282 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7283}
7284
7286
7287 Error Err = Error::success();
7288 auto ToInit = importChecked(Err, S->getInit());
7289 auto ToCond = importChecked(Err, S->getCond());
7290 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7291 auto ToInc = importChecked(Err, S->getInc());
7292 auto ToBody = importChecked(Err, S->getBody());
7293 auto ToForLoc = importChecked(Err, S->getForLoc());
7294 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7295 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7296 if (Err)
7297 return std::move(Err);
7298
7299 return new (Importer.getToContext()) ForStmt(
7300 Importer.getToContext(),
7301 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7302 ToRParenLoc);
7303}
7304
7306
7307 Error Err = Error::success();
7308 auto ToLabel = importChecked(Err, S->getLabel());
7309 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7310 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7311 if (Err)
7312 return std::move(Err);
7313
7314 return new (Importer.getToContext()) GotoStmt(
7315 ToLabel, ToGotoLoc, ToLabelLoc);
7316}
7317
7319
7320 Error Err = Error::success();
7321 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7322 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7323 auto ToTarget = importChecked(Err, S->getTarget());
7324 if (Err)
7325 return std::move(Err);
7326
7327 return new (Importer.getToContext()) IndirectGotoStmt(
7328 ToGotoLoc, ToStarLoc, ToTarget);
7329}
7330
7331template <typename StmtClass>
7333 ASTImporter &Importer, StmtClass *S) {
7334 Error Err = Error::success();
7335 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7336 auto ToLabelLoc = S->hasLabelTarget()
7337 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7338 : SourceLocation();
7339 auto ToDecl = S->hasLabelTarget()
7340 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7341 : nullptr;
7342 if (Err)
7343 return std::move(Err);
7344 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7345}
7346
7350
7354
7356
7357 Error Err = Error::success();
7358 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7359 auto ToRetValue = importChecked(Err, S->getRetValue());
7360 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7361 if (Err)
7362 return std::move(Err);
7363
7364 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7365 ToNRVOCandidate);
7366}
7367
7369
7370 Error Err = Error::success();
7371 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7372 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7373 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7374 if (Err)
7375 return std::move(Err);
7376
7377 return new (Importer.getToContext()) CXXCatchStmt (
7378 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7379}
7380
7382 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7383 if (!ToTryLocOrErr)
7384 return ToTryLocOrErr.takeError();
7385
7386 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7387 if (!ToTryBlockOrErr)
7388 return ToTryBlockOrErr.takeError();
7389
7390 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7391 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7392 CXXCatchStmt *FromHandler = S->getHandler(HI);
7393 if (auto ToHandlerOrErr = import(FromHandler))
7394 ToHandlers[HI] = *ToHandlerOrErr;
7395 else
7396 return ToHandlerOrErr.takeError();
7397 }
7398
7399 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7400 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7401}
7402
7404
7405 Error Err = Error::success();
7406 auto ToInit = importChecked(Err, S->getInit());
7407 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7408 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7409 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7410 auto ToCond = importChecked(Err, S->getCond());
7411 auto ToInc = importChecked(Err, S->getInc());
7412 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7413 auto ToBody = importChecked(Err, S->getBody());
7414 auto ToForLoc = importChecked(Err, S->getForLoc());
7415 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7416 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7417 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7418 if (Err)
7419 return std::move(Err);
7420
7421 return new (Importer.getToContext()) CXXForRangeStmt(
7422 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7423 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7424}
7425
7428 Error Err = Error::success();
7429 auto ToESD = importChecked(Err, S->getDecl());
7430 auto ToInit = importChecked(Err, S->getInit());
7431 auto ToExpansionVar = importChecked(Err, S->getExpansionVarStmt());
7432 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7433 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7434 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7435 if (Err)
7436 return std::move(Err);
7437
7438 switch (S->getKind()) {
7441 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToLParenLoc,
7442 ToColonLoc, ToRParenLoc);
7443
7445 auto ToRange = importChecked(Err, S->getRangeVarStmt());
7446 auto ToBegin = importChecked(Err, S->getBeginVarStmt());
7447 auto ToIter = importChecked(Err, S->getIterVarStmt());
7448 if (Err)
7449 return std::move(Err);
7450
7452 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToRange,
7453 ToBegin, ToIter, ToLParenLoc, ToColonLoc, ToRParenLoc);
7454 }
7455
7457 auto ToDecompositionDeclStmt =
7459 if (Err)
7460 return std::move(Err);
7461
7463 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7464 ToDecompositionDeclStmt, ToLParenLoc, ToColonLoc, ToRParenLoc);
7465 }
7466
7468 auto ToExpansionInitializer =
7470 if (Err)
7471 return std::move(Err);
7473 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7474 ToExpansionInitializer, ToLParenLoc, ToColonLoc, ToRParenLoc);
7475 }
7476 }
7477
7478 llvm_unreachable("invalid pattern kind");
7479}
7480
7483 Error Err = Error::success();
7484 SmallVector<Stmt *> ToInstantiations;
7485 SmallVector<Stmt *> ToSharedStmts;
7486 auto ToParent = importChecked(Err, S->getParent());
7487 for (Stmt *FromInst : S->getInstantiations())
7488 ToInstantiations.push_back(importChecked(Err, FromInst));
7489 for (Stmt *FromShared : S->getPreambleStmts())
7490 ToSharedStmts.push_back(importChecked(Err, FromShared));
7491
7492 if (Err)
7493 return std::move(Err);
7494
7496 Importer.getToContext(), ToParent, ToInstantiations, ToSharedStmts,
7498}
7499
7502 Error Err = Error::success();
7503 auto ToElement = importChecked(Err, S->getElement());
7504 auto ToCollection = importChecked(Err, S->getCollection());
7505 auto ToBody = importChecked(Err, S->getBody());
7506 auto ToForLoc = importChecked(Err, S->getForLoc());
7507 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7508 if (Err)
7509 return std::move(Err);
7510
7511 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7512 ToCollection,
7513 ToBody,
7514 ToForLoc,
7515 ToRParenLoc);
7516}
7517
7519
7520 Error Err = Error::success();
7521 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7522 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7523 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7524 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7525 if (Err)
7526 return std::move(Err);
7527
7528 return new (Importer.getToContext()) ObjCAtCatchStmt (
7529 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7530}
7531
7533 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7534 if (!ToAtFinallyLocOrErr)
7535 return ToAtFinallyLocOrErr.takeError();
7536 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7537 if (!ToAtFinallyStmtOrErr)
7538 return ToAtFinallyStmtOrErr.takeError();
7539 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7540 *ToAtFinallyStmtOrErr);
7541}
7542
7544
7545 Error Err = Error::success();
7546 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7547 auto ToTryBody = importChecked(Err, S->getTryBody());
7548 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7549 if (Err)
7550 return std::move(Err);
7551
7552 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7553 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7554 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7555 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7556 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7557 else
7558 return ToCatchStmtOrErr.takeError();
7559 }
7560
7561 return ObjCAtTryStmt::Create(Importer.getToContext(),
7562 ToAtTryLoc, ToTryBody,
7563 ToCatchStmts.begin(), ToCatchStmts.size(),
7564 ToFinallyStmt);
7565}
7566
7569
7570 Error Err = Error::success();
7571 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7572 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7573 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7574 if (Err)
7575 return std::move(Err);
7576
7577 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7578 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7579}
7580
7582 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7583 if (!ToThrowLocOrErr)
7584 return ToThrowLocOrErr.takeError();
7585 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7586 if (!ToThrowExprOrErr)
7587 return ToThrowExprOrErr.takeError();
7588 return new (Importer.getToContext()) ObjCAtThrowStmt(
7589 *ToThrowLocOrErr, *ToThrowExprOrErr);
7590}
7591
7594 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7595 if (!ToAtLocOrErr)
7596 return ToAtLocOrErr.takeError();
7597 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7598 if (!ToSubStmtOrErr)
7599 return ToSubStmtOrErr.takeError();
7600 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7601 *ToSubStmtOrErr);
7602}
7603
7604//----------------------------------------------------------------------------
7605// Import Expressions
7606//----------------------------------------------------------------------------
7608 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7609 << E->getStmtClassName();
7610 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7611}
7612
7614 Error Err = Error::success();
7615 auto ToType = importChecked(Err, E->getType());
7616 auto BLoc = importChecked(Err, E->getBeginLoc());
7617 auto RParenLoc = importChecked(Err, E->getEndLoc());
7618 if (Err)
7619 return std::move(Err);
7620 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7621 if (!ParentContextOrErr)
7622 return ParentContextOrErr.takeError();
7623
7624 return new (Importer.getToContext())
7625 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7626 RParenLoc, *ParentContextOrErr);
7627}
7628
7630
7631 Error Err = Error::success();
7632 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7633 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7634 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7635 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7636 auto ToType = importChecked(Err, E->getType());
7637 if (Err)
7638 return std::move(Err);
7639
7640 return new (Importer.getToContext())
7641 VAArgExpr(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7642 E->getVarargABI());
7643}
7644
7646
7647 Error Err = Error::success();
7648 auto ToCond = importChecked(Err, E->getCond());
7649 auto ToLHS = importChecked(Err, E->getLHS());
7650 auto ToRHS = importChecked(Err, E->getRHS());
7651 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7652 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7653 auto ToType = importChecked(Err, E->getType());
7654 if (Err)
7655 return std::move(Err);
7656
7658 ExprObjectKind OK = E->getObjectKind();
7659
7660 // The value of CondIsTrue only matters if the value is not
7661 // condition-dependent.
7662 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7663
7664 return new (Importer.getToContext())
7665 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7666 ToRParenLoc, CondIsTrue);
7667}
7668
7670 Error Err = Error::success();
7671 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7672 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7673 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7674 auto ToType = importChecked(Err, E->getType());
7675 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7676 if (Err)
7677 return std::move(Err);
7678
7680 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7681 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7683}
7684
7686 Error Err = Error::success();
7687 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7688 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7689 auto ToType = importChecked(Err, E->getType());
7690 const unsigned NumSubExprs = E->getNumSubExprs();
7691
7693 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7694 ToSubExprs.resize(NumSubExprs);
7695
7696 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7697 return std::move(Err);
7698
7699 return new (Importer.getToContext()) ShuffleVectorExpr(
7700 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7701}
7702
7704 ExpectedType TypeOrErr = import(E->getType());
7705 if (!TypeOrErr)
7706 return TypeOrErr.takeError();
7707
7708 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7709 if (!BeginLocOrErr)
7710 return BeginLocOrErr.takeError();
7711
7712 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7713}
7714
7717 Error Err = Error::success();
7718 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7719 Expr *ToControllingExpr = nullptr;
7720 TypeSourceInfo *ToControllingType = nullptr;
7721 if (E->isExprPredicate())
7722 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7723 else
7724 ToControllingType = importChecked(Err, E->getControllingType());
7725 assert((ToControllingExpr || ToControllingType) &&
7726 "Either the controlling expr or type must be nonnull");
7727 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7728 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7729 if (Err)
7730 return std::move(Err);
7731
7733 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7734 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7735 return std::move(Err);
7736
7737 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7738 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7739 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7740 return std::move(Err);
7741
7742 const ASTContext &ToCtx = Importer.getToContext();
7743 if (E->isResultDependent()) {
7744 if (ToControllingExpr) {
7746 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7747 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7749 }
7751 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7752 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7754 }
7755
7756 if (ToControllingExpr) {
7758 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7759 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7761 }
7763 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7764 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7766}
7767
7769
7770 Error Err = Error::success();
7771 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7772 auto ToType = importChecked(Err, E->getType());
7773 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7774 if (Err)
7775 return std::move(Err);
7776
7777 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7778 E->getIdentKind(), E->isTransparent(),
7779 ToFunctionName);
7780}
7781
7783
7784 Error Err = Error::success();
7785 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7786 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7787 auto ToDecl = importChecked(Err, E->getDecl());
7788 auto ToLocation = importChecked(Err, E->getLocation());
7789 auto ToType = importChecked(Err, E->getType());
7790 if (Err)
7791 return std::move(Err);
7792
7793 NamedDecl *ToFoundD = nullptr;
7794 if (E->getDecl() != E->getFoundDecl()) {
7795 auto FoundDOrErr = import(E->getFoundDecl());
7796 if (!FoundDOrErr)
7797 return FoundDOrErr.takeError();
7798 ToFoundD = *FoundDOrErr;
7799 }
7800
7801 TemplateArgumentListInfo ToTAInfo;
7802 TemplateArgumentListInfo *ToResInfo = nullptr;
7803 if (E->hasExplicitTemplateArgs()) {
7804 if (Error Err =
7806 E->template_arguments(), ToTAInfo))
7807 return std::move(Err);
7808 ToResInfo = &ToTAInfo;
7809 }
7810
7811 auto *ToE = DeclRefExpr::Create(
7812 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7813 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7814 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7815 if (E->hadMultipleCandidates())
7816 ToE->setHadMultipleCandidates(true);
7817 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7818 return ToE;
7819}
7820
7822 ExpectedType TypeOrErr = import(E->getType());
7823 if (!TypeOrErr)
7824 return TypeOrErr.takeError();
7825
7826 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7827}
7828
7830 ExpectedExpr ToInitOrErr = import(E->getInit());
7831 if (!ToInitOrErr)
7832 return ToInitOrErr.takeError();
7833
7834 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7835 if (!ToEqualOrColonLocOrErr)
7836 return ToEqualOrColonLocOrErr.takeError();
7837
7838 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7839 // List elements from the second, the first is Init itself
7840 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7841 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7842 ToIndexExprs[I - 1] = *ToArgOrErr;
7843 else
7844 return ToArgOrErr.takeError();
7845 }
7846
7847 SmallVector<Designator, 4> ToDesignators(E->size());
7848 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7849 return std::move(Err);
7850
7852 Importer.getToContext(), ToDesignators,
7853 ToIndexExprs, *ToEqualOrColonLocOrErr,
7854 E->usesGNUSyntax(), *ToInitOrErr);
7855}
7856
7859 ExpectedType ToTypeOrErr = import(E->getType());
7860 if (!ToTypeOrErr)
7861 return ToTypeOrErr.takeError();
7862
7863 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7864 if (!ToLocationOrErr)
7865 return ToLocationOrErr.takeError();
7866
7867 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7868 *ToTypeOrErr, *ToLocationOrErr);
7869}
7870
7872 ExpectedType ToTypeOrErr = import(E->getType());
7873 if (!ToTypeOrErr)
7874 return ToTypeOrErr.takeError();
7875
7876 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7877 if (!ToLocationOrErr)
7878 return ToLocationOrErr.takeError();
7879
7881 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7882}
7883
7884
7886 ExpectedType ToTypeOrErr = import(E->getType());
7887 if (!ToTypeOrErr)
7888 return ToTypeOrErr.takeError();
7889
7890 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7891 if (!ToLocationOrErr)
7892 return ToLocationOrErr.takeError();
7893
7895 Importer.getToContext(), E->getValue(), E->isExact(),
7896 *ToTypeOrErr, *ToLocationOrErr);
7897}
7898
7900 auto ToTypeOrErr = import(E->getType());
7901 if (!ToTypeOrErr)
7902 return ToTypeOrErr.takeError();
7903
7904 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7905 if (!ToSubExprOrErr)
7906 return ToSubExprOrErr.takeError();
7907
7908 return new (Importer.getToContext()) ImaginaryLiteral(
7909 *ToSubExprOrErr, *ToTypeOrErr);
7910}
7911
7913 auto ToTypeOrErr = import(E->getType());
7914 if (!ToTypeOrErr)
7915 return ToTypeOrErr.takeError();
7916
7917 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7918 if (!ToLocationOrErr)
7919 return ToLocationOrErr.takeError();
7920
7921 return new (Importer.getToContext()) FixedPointLiteral(
7922 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7923 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7924}
7925
7927 ExpectedType ToTypeOrErr = import(E->getType());
7928 if (!ToTypeOrErr)
7929 return ToTypeOrErr.takeError();
7930
7931 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7932 if (!ToLocationOrErr)
7933 return ToLocationOrErr.takeError();
7934
7935 return new (Importer.getToContext()) CharacterLiteral(
7936 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7937}
7938
7940 ExpectedType ToTypeOrErr = import(E->getType());
7941 if (!ToTypeOrErr)
7942 return ToTypeOrErr.takeError();
7943
7945 if (Error Err = ImportArrayChecked(
7946 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7947 return std::move(Err);
7948
7949 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7950 E->getKind(), E->isPascal(), *ToTypeOrErr,
7951 ToLocations);
7952}
7953
7955
7956 Error Err = Error::success();
7957 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7958 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7959 auto ToType = importChecked(Err, E->getType());
7960 auto ToInitializer = importChecked(Err, E->getInitializer());
7961 if (Err)
7962 return std::move(Err);
7963
7964 return new (Importer.getToContext()) CompoundLiteralExpr(
7965 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7966 ToInitializer, E->isFileScope());
7967}
7968
7970
7971 Error Err = Error::success();
7972 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7973 auto ToType = importChecked(Err, E->getType());
7974 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7975 if (Err)
7976 return std::move(Err);
7977
7979 if (Error Err = ImportArrayChecked(
7980 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7981 ToExprs.begin()))
7982 return std::move(Err);
7983
7984 return new (Importer.getToContext()) AtomicExpr(
7985
7986 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7987}
7988
7990 Error Err = Error::success();
7991 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7992 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7993 auto ToLabel = importChecked(Err, E->getLabel());
7994 auto ToType = importChecked(Err, E->getType());
7995 if (Err)
7996 return std::move(Err);
7997
7998 return new (Importer.getToContext()) AddrLabelExpr(
7999 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
8000}
8002 Error Err = Error::success();
8003 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8004 auto ToResult = importChecked(Err, E->getAPValueResult());
8005 if (Err)
8006 return std::move(Err);
8007
8008 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
8009}
8011 Error Err = Error::success();
8012 auto ToLParen = importChecked(Err, E->getLParen());
8013 auto ToRParen = importChecked(Err, E->getRParen());
8014 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8015 if (Err)
8016 return std::move(Err);
8017
8018 return new (Importer.getToContext())
8019 ParenExpr(ToLParen, ToRParen, ToSubExpr);
8020}
8021
8023 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
8024 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
8025 return std::move(Err);
8026
8027 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
8028 if (!ToLParenLocOrErr)
8029 return ToLParenLocOrErr.takeError();
8030
8031 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
8032 if (!ToRParenLocOrErr)
8033 return ToRParenLocOrErr.takeError();
8034
8035 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
8036 ToExprs, *ToRParenLocOrErr);
8037}
8038
8040 Error Err = Error::success();
8041 auto ToSubStmt = importChecked(Err, E->getSubStmt());
8042 auto ToType = importChecked(Err, E->getType());
8043 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8044 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8045 if (Err)
8046 return std::move(Err);
8047
8048 return new (Importer.getToContext())
8049 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8050 E->getTemplateDepth());
8051}
8052
8054 Error Err = Error::success();
8055 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8056 auto ToType = importChecked(Err, E->getType());
8057 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8058 if (Err)
8059 return std::move(Err);
8060
8061 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8062 E->hasStoredFPFeatures());
8063 UO->setType(ToType);
8064 UO->setSubExpr(ToSubExpr);
8065 UO->setOpcode(E->getOpcode());
8066 UO->setOperatorLoc(ToOperatorLoc);
8067 UO->setCanOverflow(E->canOverflow());
8068 if (E->hasStoredFPFeatures())
8069 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8070
8071 return UO;
8072}
8073
8075
8077 Error Err = Error::success();
8078 auto ToType = importChecked(Err, E->getType());
8079 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8080 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8081 if (Err)
8082 return std::move(Err);
8083
8084 if (E->isArgumentType()) {
8085 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8086 import(E->getArgumentTypeInfo());
8087 if (!ToArgumentTypeInfoOrErr)
8088 return ToArgumentTypeInfoOrErr.takeError();
8089
8090 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8091 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8092 ToRParenLoc);
8093 }
8094
8095 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8096 if (!ToArgumentExprOrErr)
8097 return ToArgumentExprOrErr.takeError();
8098
8099 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8100 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8101}
8102
8104 Error Err = Error::success();
8105 auto ToLHS = importChecked(Err, E->getLHS());
8106 auto ToRHS = importChecked(Err, E->getRHS());
8107 auto ToType = importChecked(Err, E->getType());
8108 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8109 if (Err)
8110 return std::move(Err);
8111
8113 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8114 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8115 E->getFPFeatures());
8116}
8117
8119 Error Err = Error::success();
8120 auto ToCond = importChecked(Err, E->getCond());
8121 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8122 auto ToLHS = importChecked(Err, E->getLHS());
8123 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8124 auto ToRHS = importChecked(Err, E->getRHS());
8125 auto ToType = importChecked(Err, E->getType());
8126 if (Err)
8127 return std::move(Err);
8128
8129 return new (Importer.getToContext()) ConditionalOperator(
8130 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8131 E->getValueKind(), E->getObjectKind());
8132}
8133
8136 Error Err = Error::success();
8137 auto ToCommon = importChecked(Err, E->getCommon());
8138 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8139 auto ToCond = importChecked(Err, E->getCond());
8140 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8141 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8142 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8143 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8144 auto ToType = importChecked(Err, E->getType());
8145 if (Err)
8146 return std::move(Err);
8147
8148 return new (Importer.getToContext()) BinaryConditionalOperator(
8149 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8150 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8151 E->getObjectKind());
8152}
8153
8156 Error Err = Error::success();
8157 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8158 if (Err)
8159 return std::move(Err);
8160
8161 return new (Importer.getToContext())
8162 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8163}
8164
8166 Error Err = Error::success();
8167 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8168 auto ToQueriedTypeSourceInfo =
8170 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8171 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8172 auto ToType = importChecked(Err, E->getType());
8173 if (Err)
8174 return std::move(Err);
8175
8176 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8177 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8178 ToDimensionExpression, ToEndLoc, ToType);
8179}
8180
8182 Error Err = Error::success();
8183 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8184 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8185 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8186 auto ToType = importChecked(Err, E->getType());
8187 if (Err)
8188 return std::move(Err);
8189
8190 return new (Importer.getToContext()) ExpressionTraitExpr(
8191 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8192 ToEndLoc, ToType);
8193}
8194
8196 Error Err = Error::success();
8197 auto ToLocation = importChecked(Err, E->getLocation());
8198 auto ToType = importChecked(Err, E->getType());
8199 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8200 if (Err)
8201 return std::move(Err);
8202
8203 return new (Importer.getToContext()) OpaqueValueExpr(
8204 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8205}
8206
8208 Error Err = Error::success();
8209 auto ToLHS = importChecked(Err, E->getLHS());
8210 auto ToRHS = importChecked(Err, E->getRHS());
8211 auto ToType = importChecked(Err, E->getType());
8212 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8213 if (Err)
8214 return std::move(Err);
8215
8216 return new (Importer.getToContext()) ArraySubscriptExpr(
8217 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8218 ToRBracketLoc);
8219}
8220
8223 Error Err = Error::success();
8224 auto ToLHS = importChecked(Err, E->getLHS());
8225 auto ToRHS = importChecked(Err, E->getRHS());
8226 auto ToType = importChecked(Err, E->getType());
8227 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8228 auto ToComputationResultType =
8230 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8231 if (Err)
8232 return std::move(Err);
8233
8235 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8236 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8237 E->getFPFeatures(),
8238 ToComputationLHSType, ToComputationResultType);
8239}
8240
8243 CXXCastPath Path;
8244 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8245 if (auto SpecOrErr = import(*I))
8246 Path.push_back(*SpecOrErr);
8247 else
8248 return SpecOrErr.takeError();
8249 }
8250 return Path;
8251}
8252
8254 ExpectedType ToTypeOrErr = import(E->getType());
8255 if (!ToTypeOrErr)
8256 return ToTypeOrErr.takeError();
8257
8258 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8259 if (!ToSubExprOrErr)
8260 return ToSubExprOrErr.takeError();
8261
8262 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8263 if (!ToBasePathOrErr)
8264 return ToBasePathOrErr.takeError();
8265
8267 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8268 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8269}
8270
8272 Error Err = Error::success();
8273 auto ToType = importChecked(Err, E->getType());
8274 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8275 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8276 if (Err)
8277 return std::move(Err);
8278
8279 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8280 if (!ToBasePathOrErr)
8281 return ToBasePathOrErr.takeError();
8282 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8283
8284 switch (E->getStmtClass()) {
8285 case Stmt::CStyleCastExprClass: {
8286 auto *CCE = cast<CStyleCastExpr>(E);
8287 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8288 if (!ToLParenLocOrErr)
8289 return ToLParenLocOrErr.takeError();
8290 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8291 if (!ToRParenLocOrErr)
8292 return ToRParenLocOrErr.takeError();
8294 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8295 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8296 *ToLParenLocOrErr, *ToRParenLocOrErr);
8297 }
8298
8299 case Stmt::CXXFunctionalCastExprClass: {
8300 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8301 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8302 if (!ToLParenLocOrErr)
8303 return ToLParenLocOrErr.takeError();
8304 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8305 if (!ToRParenLocOrErr)
8306 return ToRParenLocOrErr.takeError();
8308 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8309 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8310 *ToLParenLocOrErr, *ToRParenLocOrErr);
8311 }
8312
8313 case Stmt::ObjCBridgedCastExprClass: {
8314 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8315 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8316 if (!ToLParenLocOrErr)
8317 return ToLParenLocOrErr.takeError();
8318 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8319 if (!ToBridgeKeywordLocOrErr)
8320 return ToBridgeKeywordLocOrErr.takeError();
8321 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8322 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8323 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8324 }
8325 case Stmt::BuiltinBitCastExprClass: {
8326 auto *BBC = cast<BuiltinBitCastExpr>(E);
8327 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8328 if (!ToKWLocOrErr)
8329 return ToKWLocOrErr.takeError();
8330 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8331 if (!ToRParenLocOrErr)
8332 return ToRParenLocOrErr.takeError();
8333 return new (Importer.getToContext()) BuiltinBitCastExpr(
8334 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8335 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8336 }
8337 default:
8338 llvm_unreachable("Cast expression of unsupported type!");
8339 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8340 }
8341}
8342
8345 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8346 const OffsetOfNode &FromNode = E->getComponent(I);
8347
8348 SourceLocation ToBeginLoc, ToEndLoc;
8349
8350 if (FromNode.getKind() != OffsetOfNode::Base) {
8351 Error Err = Error::success();
8352 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8353 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8354 if (Err)
8355 return std::move(Err);
8356 }
8357
8358 switch (FromNode.getKind()) {
8360 ToNodes.push_back(
8361 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8362 break;
8363 case OffsetOfNode::Base: {
8364 auto ToBSOrErr = import(FromNode.getBase());
8365 if (!ToBSOrErr)
8366 return ToBSOrErr.takeError();
8367 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8368 break;
8369 }
8370 case OffsetOfNode::Field: {
8371 auto ToFieldOrErr = import(FromNode.getField());
8372 if (!ToFieldOrErr)
8373 return ToFieldOrErr.takeError();
8374 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8375 break;
8376 }
8378 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8379 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8380 break;
8381 }
8382 }
8383 }
8384
8386 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8387 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8388 if (!ToIndexExprOrErr)
8389 return ToIndexExprOrErr.takeError();
8390 ToExprs[I] = *ToIndexExprOrErr;
8391 }
8392
8393 Error Err = Error::success();
8394 auto ToType = importChecked(Err, E->getType());
8395 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8396 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8397 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8398 if (Err)
8399 return std::move(Err);
8400
8401 return OffsetOfExpr::Create(
8402 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8403 ToExprs, ToRParenLoc);
8404}
8405
8407 Error Err = Error::success();
8408 auto ToType = importChecked(Err, E->getType());
8409 auto ToOperand = importChecked(Err, E->getOperand());
8410 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8411 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8412 if (Err)
8413 return std::move(Err);
8414
8415 CanThrowResult ToCanThrow;
8416 if (E->isValueDependent())
8417 ToCanThrow = CT_Dependent;
8418 else
8419 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8420
8421 return new (Importer.getToContext()) CXXNoexceptExpr(
8422 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8423}
8424
8426 Error Err = Error::success();
8427 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8428 auto ToType = importChecked(Err, E->getType());
8429 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8430 if (Err)
8431 return std::move(Err);
8432
8433 return new (Importer.getToContext()) CXXThrowExpr(
8434 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8435}
8436
8438 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8439 if (!ToUsedLocOrErr)
8440 return ToUsedLocOrErr.takeError();
8441
8442 auto ToParamOrErr = import(E->getParam());
8443 if (!ToParamOrErr)
8444 return ToParamOrErr.takeError();
8445
8446 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8447 if (!UsedContextOrErr)
8448 return UsedContextOrErr.takeError();
8449
8450 // Import the default arg if it was not imported yet.
8451 // This is needed because it can happen that during the import of the
8452 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8453 // encountered here. The default argument for a ParmVarDecl is set in the
8454 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8455 // see VisitParmVarDecl).
8456 ParmVarDecl *ToParam = *ToParamOrErr;
8457 if (!ToParam->getDefaultArg()) {
8458 std::optional<ParmVarDecl *> FromParam =
8459 Importer.getImportedFromDecl(ToParam);
8460 assert(FromParam && "ParmVarDecl was not imported?");
8461
8462 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8463 return std::move(Err);
8464 }
8465 Expr *RewrittenInit = nullptr;
8466 if (E->hasRewrittenInit()) {
8467 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8468 if (!ExprOrErr)
8469 return ExprOrErr.takeError();
8470 RewrittenInit = ExprOrErr.get();
8471 }
8472 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8473 *ToParamOrErr, RewrittenInit,
8474 *UsedContextOrErr);
8475}
8476
8479 Error Err = Error::success();
8480 auto ToType = importChecked(Err, E->getType());
8481 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8482 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8483 if (Err)
8484 return std::move(Err);
8485
8486 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8487 ToType, ToTypeSourceInfo, ToRParenLoc);
8488}
8489
8492 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8493 if (!ToSubExprOrErr)
8494 return ToSubExprOrErr.takeError();
8495
8496 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8497 if (!ToDtorOrErr)
8498 return ToDtorOrErr.takeError();
8499
8500 ASTContext &ToCtx = Importer.getToContext();
8501 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8502 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8503}
8504
8506
8508 Error Err = Error::success();
8509 auto ToConstructor = importChecked(Err, E->getConstructor());
8510 auto ToType = importChecked(Err, E->getType());
8511 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8512 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8513 if (Err)
8514 return std::move(Err);
8515
8517 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8518 return std::move(Err);
8519
8521 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8522 ToParenOrBraceRange, E->hadMultipleCandidates(),
8525}
8526
8529 DeclContext *DC, *LexicalDC;
8530 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8531 return std::move(Err);
8532
8533 Error Err = Error::success();
8534 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8535 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8536 if (Err)
8537 return std::move(Err);
8538 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8539
8541 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8542 D->getManglingNumber()))
8543 return To;
8544
8545 To->setLexicalDeclContext(LexicalDC);
8546 LexicalDC->addDeclInternal(To);
8547 return To;
8548}
8549
8552 Error Err = Error::success();
8553 auto ToType = importChecked(Err, E->getType());
8554 Expr *ToTemporaryExpr = importChecked(
8555 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8556 auto ToMaterializedDecl =
8558 if (Err)
8559 return std::move(Err);
8560
8561 if (!ToTemporaryExpr)
8562 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8563
8564 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8565 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8566 ToMaterializedDecl);
8567
8568 return ToMTE;
8569}
8570
8572 Error Err = Error::success();
8573 auto *ToPattern = importChecked(Err, E->getPattern());
8574 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8575 if (Err)
8576 return std::move(Err);
8577
8578 return new (Importer.getToContext())
8579 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8580}
8581
8583 Error Err = Error::success();
8584 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8585 auto ToPack = importChecked(Err, E->getPack());
8586 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8587 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8588 if (Err)
8589 return std::move(Err);
8590
8591 UnsignedOrNone Length = std::nullopt;
8592 if (!E->isValueDependent())
8593 Length = E->getPackLength();
8594
8595 SmallVector<TemplateArgument, 8> ToPartialArguments;
8596 if (E->isPartiallySubstituted()) {
8598 ToPartialArguments))
8599 return std::move(Err);
8600 }
8601
8603 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8604 Length, ToPartialArguments);
8605}
8606
8607
8609 Error Err = Error::success();
8610 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8611 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8612 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8613 auto ToArraySize = importChecked(Err, E->getArraySize());
8614 auto ToInitializer = importChecked(Err, E->getInitializer());
8615 auto ToType = importChecked(Err, E->getType());
8616 auto ToAllocatedTypeSourceInfo =
8618 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8619 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8620 if (Err)
8621 return std::move(Err);
8622
8623 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8624 if (Error Err =
8625 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8626 return std::move(Err);
8627
8628 return CXXNewExpr::Create(
8629 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8630 ToOperatorDelete, E->implicitAllocationParameters(),
8631 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8632 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8633 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8634}
8635
8637 Error Err = Error::success();
8638 auto ToType = importChecked(Err, E->getType());
8639 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8640 auto ToArgument = importChecked(Err, E->getArgument());
8641 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8642 if (Err)
8643 return std::move(Err);
8644
8645 return new (Importer.getToContext()) CXXDeleteExpr(
8646 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8647 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8648 ToBeginLoc);
8649}
8650
8652 Error Err = Error::success();
8653 auto ToType = importChecked(Err, E->getType());
8654 auto ToLocation = importChecked(Err, E->getLocation());
8655 auto ToConstructor = importChecked(Err, E->getConstructor());
8656 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8657 if (Err)
8658 return std::move(Err);
8659
8661 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8662 return std::move(Err);
8663
8665 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8666 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8669 ToParenOrBraceRange);
8671 return ToE;
8672}
8673
8675 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8676 if (!ToSubExprOrErr)
8677 return ToSubExprOrErr.takeError();
8678
8680 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8681 return std::move(Err);
8682
8684 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8685 ToObjects);
8686}
8687
8689 Error Err = Error::success();
8690 auto ToCallee = importChecked(Err, E->getCallee());
8691 auto ToType = importChecked(Err, E->getType());
8692 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8693 if (Err)
8694 return std::move(Err);
8695
8697 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8698 return std::move(Err);
8699
8700 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8701 ToType, E->getValueKind(), ToRParenLoc,
8702 E->getFPFeatures());
8703}
8704
8706 ExpectedType ToTypeOrErr = import(E->getType());
8707 if (!ToTypeOrErr)
8708 return ToTypeOrErr.takeError();
8709
8710 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8711 if (!ToLocationOrErr)
8712 return ToLocationOrErr.takeError();
8713
8714 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8715 *ToTypeOrErr, E->isImplicit());
8716}
8717
8719 ExpectedType ToTypeOrErr = import(E->getType());
8720 if (!ToTypeOrErr)
8721 return ToTypeOrErr.takeError();
8722
8723 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8724 if (!ToLocationOrErr)
8725 return ToLocationOrErr.takeError();
8726
8727 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8728 *ToTypeOrErr, *ToLocationOrErr);
8729}
8730
8732 Error Err = Error::success();
8733 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8734 auto ToTSI = importChecked(Err, E->getTypeSourceInfo());
8735 if (Err)
8736 return std::move(Err);
8737
8738 return CXXReflectExpr::Create(Importer.getToContext(), ToOperatorLoc, ToTSI);
8739}
8740
8742 Error Err = Error::success();
8743 auto ToBase = importChecked(Err, E->getBase());
8744 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8745 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8746 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8747 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8748 auto ToType = importChecked(Err, E->getType());
8749 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8750 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8751 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8752 if (Err)
8753 return std::move(Err);
8754
8755 DeclAccessPair ToFoundDecl =
8757
8758 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8759
8760 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8761 if (E->hasExplicitTemplateArgs()) {
8762 if (Error Err =
8764 E->template_arguments(), ToTAInfo))
8765 return std::move(Err);
8766 ResInfo = &ToTAInfo;
8767 }
8768
8769 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8770 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8771 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8772 ResInfo, ToType, E->getValueKind(),
8773 E->getObjectKind(), E->isNonOdrUse());
8774}
8775
8778 Error Err = Error::success();
8779 auto ToBase = importChecked(Err, E->getBase());
8780 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8781 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8782 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8783 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8784 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8785 if (Err)
8786 return std::move(Err);
8787
8789 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8790 const IdentifierInfo *ToII = Importer.Import(FromII);
8791 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8792 if (!ToDestroyedTypeLocOrErr)
8793 return ToDestroyedTypeLocOrErr.takeError();
8794 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8795 } else {
8796 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8797 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8798 else
8799 return ToTIOrErr.takeError();
8800 }
8801
8802 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8803 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8804 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8805}
8806
8809 Error Err = Error::success();
8810 auto ToType = importChecked(Err, E->getType());
8811 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8812 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8813 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8814 auto ToFirstQualifierFoundInScope =
8816 if (Err)
8817 return std::move(Err);
8818
8819 Expr *ToBase = nullptr;
8820 if (!E->isImplicitAccess()) {
8821 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8822 ToBase = *ToBaseOrErr;
8823 else
8824 return ToBaseOrErr.takeError();
8825 }
8826
8827 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8828
8829 if (E->hasExplicitTemplateArgs()) {
8830 if (Error Err =
8832 E->template_arguments(), ToTAInfo))
8833 return std::move(Err);
8834 ResInfo = &ToTAInfo;
8835 }
8836 auto ToMember = importChecked(Err, E->getMember());
8837 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8838 if (Err)
8839 return std::move(Err);
8840 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8841
8842 // Import additional name location/type info.
8843 if (Error Err =
8844 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8845 return std::move(Err);
8846
8848 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8849 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8850 ToMemberNameInfo, ResInfo);
8851}
8852
8855 Error Err = Error::success();
8856 auto ToName = importChecked(Err, E->getTemplateName());
8857 auto ToDeclName = importChecked(Err, E->getName());
8858 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8859 if (Err)
8860 return std::move(Err);
8861
8862 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8863 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8864 return std::move(Err);
8865
8866 TemplateArgumentListInfo ToTAInfo;
8867 if (Error Err =
8869 E->template_arguments(), ToTAInfo))
8870 return std::move(Err);
8871
8872 return DependentTemplateIdExpr::Create(Importer.getToContext(), ToNameInfo,
8873 ToName, ToTAInfo);
8874}
8875
8878 Error Err = Error::success();
8879 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8880 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8881 auto ToDeclName = importChecked(Err, E->getDeclName());
8882 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8883 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8884 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8885 if (Err)
8886 return std::move(Err);
8887
8888 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8889 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8890 return std::move(Err);
8891
8892 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8893 TemplateArgumentListInfo *ResInfo = nullptr;
8894 if (E->hasExplicitTemplateArgs()) {
8895 if (Error Err =
8897 return std::move(Err);
8898 ResInfo = &ToTAInfo;
8899 }
8900
8902 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8903 ToNameInfo, ResInfo);
8904}
8905
8908 Error Err = Error::success();
8909 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8910 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8911 auto ToType = importChecked(Err, E->getType());
8912 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8913 if (Err)
8914 return std::move(Err);
8915
8917 if (Error Err =
8918 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8919 return std::move(Err);
8920
8922 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8923 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8924}
8925
8928 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8929 if (!ToNamingClassOrErr)
8930 return ToNamingClassOrErr.takeError();
8931
8932 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8933 if (!ToQualifierLocOrErr)
8934 return ToQualifierLocOrErr.takeError();
8935
8936 Error Err = Error::success();
8937 auto ToName = importChecked(Err, E->getName());
8938 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8939 if (Err)
8940 return std::move(Err);
8941 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8942
8943 // Import additional name location/type info.
8944 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8945 return std::move(Err);
8946
8947 UnresolvedSet<8> ToDecls;
8948 for (auto *D : E->decls())
8949 if (auto ToDOrErr = import(D))
8950 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8951 else
8952 return ToDOrErr.takeError();
8953
8954 if (E->hasExplicitTemplateArgs()) {
8955 TemplateArgumentListInfo ToTAInfo;
8958 ToTAInfo))
8959 return std::move(Err);
8960
8961 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8962 if (!ToTemplateKeywordLocOrErr)
8963 return ToTemplateKeywordLocOrErr.takeError();
8964
8965 const bool KnownDependent =
8966 (E->getDependence() & ExprDependence::TypeValue) ==
8967 ExprDependence::TypeValue;
8969 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8970 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8971 ToDecls.begin(), ToDecls.end(), KnownDependent,
8972 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8973 }
8974
8976 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8977 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8978 /*KnownDependent=*/E->isTypeDependent(),
8979 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8980}
8981
8984 Error Err = Error::success();
8985 auto ToType = importChecked(Err, E->getType());
8986 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8987 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8988 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8989 auto ToName = importChecked(Err, E->getName());
8990 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8991 if (Err)
8992 return std::move(Err);
8993
8994 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8995 // Import additional name location/type info.
8996 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8997 return std::move(Err);
8998
8999 UnresolvedSet<8> ToDecls;
9000 for (Decl *D : E->decls())
9001 if (auto ToDOrErr = import(D))
9002 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
9003 else
9004 return ToDOrErr.takeError();
9005
9006 TemplateArgumentListInfo ToTAInfo;
9007 TemplateArgumentListInfo *ResInfo = nullptr;
9008 if (E->hasExplicitTemplateArgs()) {
9009 TemplateArgumentListInfo FromTAInfo;
9010 E->copyTemplateArgumentsInto(FromTAInfo);
9011 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
9012 return std::move(Err);
9013 ResInfo = &ToTAInfo;
9014 }
9015
9016 Expr *ToBase = nullptr;
9017 if (!E->isImplicitAccess()) {
9018 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
9019 ToBase = *ToBaseOrErr;
9020 else
9021 return ToBaseOrErr.takeError();
9022 }
9023
9025 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
9026 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
9027 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
9028}
9029
9031 Error Err = Error::success();
9032 auto ToCallee = importChecked(Err, E->getCallee());
9033 auto ToType = importChecked(Err, E->getType());
9034 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9035 if (Err)
9036 return std::move(Err);
9037
9038 unsigned NumArgs = E->getNumArgs();
9039 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
9040 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
9041 return std::move(Err);
9042
9043 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
9045 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
9046 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
9047 OCE->getADLCallKind());
9048 }
9049
9050 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
9051 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
9052 /*MinNumArgs=*/0, E->getADLCallKind());
9053}
9054
9056 CXXRecordDecl *FromClass = E->getLambdaClass();
9057 auto ToClassOrErr = import(FromClass);
9058 if (!ToClassOrErr)
9059 return ToClassOrErr.takeError();
9060 CXXRecordDecl *ToClass = *ToClassOrErr;
9061
9062 auto ToCallOpOrErr = import(E->getCallOperator());
9063 if (!ToCallOpOrErr)
9064 return ToCallOpOrErr.takeError();
9065
9066 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
9067 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
9068 return std::move(Err);
9069
9070 Error Err = Error::success();
9071 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
9072 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
9073 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9074 if (Err)
9075 return std::move(Err);
9076
9077 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
9078 E->getCaptureDefault(), ToCaptureDefaultLoc,
9080 E->hasExplicitResultType(), ToCaptureInits,
9081 ToEndLoc, E->containsUnexpandedParameterPack());
9082}
9083
9084
9086 Error Err = Error::success();
9087 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9088 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9089 auto ToType = importChecked(Err, E->getType());
9090 if (Err)
9091 return std::move(Err);
9092
9093 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9094 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9095 return std::move(Err);
9096
9097 ASTContext &ToCtx = Importer.getToContext();
9098 InitListExpr *To = new (ToCtx)
9099 InitListExpr(ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc, E->isExplicit());
9100 To->setType(ToType);
9101
9102 if (E->hasArrayFiller()) {
9103 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9104 To->setArrayFiller(*ToFillerOrErr);
9105 else
9106 return ToFillerOrErr.takeError();
9107 }
9108
9109 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9110 if (auto ToFDOrErr = import(FromFD))
9111 To->setInitializedFieldInUnion(*ToFDOrErr);
9112 else
9113 return ToFDOrErr.takeError();
9114 }
9115
9116 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9117 if (auto ToSyntFormOrErr = import(SyntForm))
9118 To->setSyntacticForm(*ToSyntFormOrErr);
9119 else
9120 return ToSyntFormOrErr.takeError();
9121 }
9122
9123 // Copy InitListExprBitfields, which are not handled in the ctor of
9124 // InitListExpr.
9126
9127 return To;
9128}
9129
9132 ExpectedType ToTypeOrErr = import(E->getType());
9133 if (!ToTypeOrErr)
9134 return ToTypeOrErr.takeError();
9135
9136 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9137 if (!ToSubExprOrErr)
9138 return ToSubExprOrErr.takeError();
9139
9140 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9141 *ToTypeOrErr, *ToSubExprOrErr);
9142}
9143
9146 Error Err = Error::success();
9147 auto ToLocation = importChecked(Err, E->getLocation());
9148 auto ToType = importChecked(Err, E->getType());
9149 auto ToConstructor = importChecked(Err, E->getConstructor());
9150 if (Err)
9151 return std::move(Err);
9152
9153 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9154 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9155 E->inheritedFromVBase());
9156}
9157
9159 Error Err = Error::success();
9160 auto ToType = importChecked(Err, E->getType());
9161 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9162 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9163 if (Err)
9164 return std::move(Err);
9165
9166 return new (Importer.getToContext()) ArrayInitLoopExpr(
9167 ToType, ToCommonExpr, ToSubExpr);
9168}
9169
9171 ExpectedType ToTypeOrErr = import(E->getType());
9172 if (!ToTypeOrErr)
9173 return ToTypeOrErr.takeError();
9174 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9175}
9176
9178 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9179 if (!ToBeginLocOrErr)
9180 return ToBeginLocOrErr.takeError();
9181
9182 auto ToFieldOrErr = import(E->getField());
9183 if (!ToFieldOrErr)
9184 return ToFieldOrErr.takeError();
9185
9186 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9187 if (!UsedContextOrErr)
9188 return UsedContextOrErr.takeError();
9189
9190 FieldDecl *ToField = *ToFieldOrErr;
9191 assert(ToField->hasInClassInitializer() &&
9192 "Field should have in-class initializer if there is a default init "
9193 "expression that uses it.");
9194 if (!ToField->getInClassInitializer()) {
9195 // The in-class initializer may be not yet set in "To" AST even if the
9196 // field is already there. This must be set here to make construction of
9197 // CXXDefaultInitExpr work.
9198 auto ToInClassInitializerOrErr =
9199 import(E->getField()->getInClassInitializer());
9200 if (!ToInClassInitializerOrErr)
9201 return ToInClassInitializerOrErr.takeError();
9202 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9203 }
9204
9205 Expr *RewrittenInit = nullptr;
9206 if (E->hasRewrittenInit()) {
9207 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9208 if (!ExprOrErr)
9209 return ExprOrErr.takeError();
9210 RewrittenInit = ExprOrErr.get();
9211 }
9212
9213 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9214 ToField, *UsedContextOrErr, RewrittenInit);
9215}
9216
9218 Error Err = Error::success();
9219 auto ToType = importChecked(Err, E->getType());
9220 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9221 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9222 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9223 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9224 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9225 if (Err)
9226 return std::move(Err);
9227
9229 CastKind CK = E->getCastKind();
9230 auto ToBasePathOrErr = ImportCastPath(E);
9231 if (!ToBasePathOrErr)
9232 return ToBasePathOrErr.takeError();
9233
9234 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9236 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9237 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9238 ToAngleBrackets);
9239 } else if (isa<CXXDynamicCastExpr>(E)) {
9241 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9242 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9243 } else if (isa<CXXReinterpretCastExpr>(E)) {
9245 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9246 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9247 } else if (isa<CXXConstCastExpr>(E)) {
9249 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9250 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9251 } else {
9252 llvm_unreachable("Unknown cast type");
9253 return make_error<ASTImportError>();
9254 }
9255}
9256
9259 Error Err = Error::success();
9260 auto ToType = importChecked(Err, E->getType());
9261 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9262 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9263 auto ToParamType = importChecked(Err, E->getParameterType());
9264 auto ToReplacement = importChecked(Err, E->getReplacement());
9265 if (Err)
9266 return std::move(Err);
9267
9268 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9269 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9270 ToParamType, E->getIndex(), E->getPackIndex(), E->getFinal());
9271}
9272
9274 Error Err = Error::success();
9275 auto ToType = importChecked(Err, E->getType());
9276 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9277 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9278 if (Err)
9279 return std::move(Err);
9280
9282 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9283 return std::move(Err);
9284
9285 if (E->isStoredAsBoolean()) {
9286 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9287 // Value is always false.
9288 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9289 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9290 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9291 }
9292 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9293 E->getTrait(), ToArgs, ToEndLoc,
9294 E->getAPValue());
9295}
9296
9298 ExpectedType ToTypeOrErr = import(E->getType());
9299 if (!ToTypeOrErr)
9300 return ToTypeOrErr.takeError();
9301
9302 auto ToSourceRangeOrErr = import(E->getSourceRange());
9303 if (!ToSourceRangeOrErr)
9304 return ToSourceRangeOrErr.takeError();
9305
9306 if (E->isTypeOperand()) {
9307 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9308 return new (Importer.getToContext()) CXXTypeidExpr(
9309 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9310 else
9311 return ToTSIOrErr.takeError();
9312 }
9313
9314 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9315 if (!ToExprOperandOrErr)
9316 return ToExprOperandOrErr.takeError();
9317
9318 return new (Importer.getToContext()) CXXTypeidExpr(
9319 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9320}
9321
9323 Error Err = Error::success();
9324
9325 QualType ToType = importChecked(Err, E->getType());
9326 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9327 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9328 Expr *ToLHS = importChecked(Err, E->getLHS());
9329 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9330 Expr *ToRHS = importChecked(Err, E->getRHS());
9331 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9332
9333 if (Err)
9334 return std::move(Err);
9335
9336 return new (Importer.getToContext())
9337 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9338 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9339}
9340
9342 Error Err = Error::success();
9343 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9344 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9345 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9346
9347 auto Body = importChecked(Err, E->getBody());
9348 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9349 if (Err)
9350 return std::move(Err);
9351 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9352 if (Error Err =
9353 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9354 return std::move(Err);
9356 E->getRequirements().size());
9357 if (Error Err =
9358 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9359 return std::move(Err);
9360 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9361 LParenLoc, LocalParameters, RParenLoc,
9362 Requirements, RBraceLoc);
9363}
9364
9367 Error Err = Error::success();
9368 auto CL = importChecked(Err, E->getConceptReference());
9369 auto CSD = importChecked(Err, E->getSpecializationDecl());
9370 if (Err)
9371 return std::move(Err);
9372 if (E->isValueDependent())
9374 Importer.getToContext(), CL,
9375 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9376 ConstraintSatisfaction Satisfaction;
9377 if (Error Err =
9379 return std::move(Err);
9381 Importer.getToContext(), CL,
9382 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9383}
9384
9387 Error Err = Error::success();
9388 auto ToType = importChecked(Err, E->getType());
9389 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9390 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9391 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9392 if (Err)
9393 return std::move(Err);
9394
9395 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9396 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9397 E->getIndex(), E->getFinal());
9398}
9399
9402 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9403 return std::move(Err);
9404 auto ToSyntOrErr = import(E->getSyntacticForm());
9405 if (!ToSyntOrErr)
9406 return ToSyntOrErr.takeError();
9407 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9408 ToSemantics, E->getResultExprIndex());
9409}
9410
9413 Error Err = Error::success();
9414 auto ToType = importChecked(Err, E->getType());
9415 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9416 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9417 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9418 if (Err)
9419 return std::move(Err);
9420
9421 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9422 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9423 return std::move(Err);
9424 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9425 E->getUserSpecifiedInitExprs().size(),
9426 ToInitLoc, ToBeginLoc, ToEndLoc);
9427}
9428
9431 Error Err = Error::success();
9432 auto ToRange = importChecked(Err, E->getRangeExpr());
9433 auto ToIndex = importChecked(Err, E->getIndexExpr());
9434 if (Err)
9435 return std::move(Err);
9436
9437 return new (Importer.getToContext())
9438 CXXExpansionSelectExpr(Importer.getToContext(), ToRange, ToIndex);
9439}
9440
9442 CXXMethodDecl *FromMethod) {
9443 Error ImportErrors = Error::success();
9444 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9445 if (auto ImportedOrErr = import(FromOverriddenMethod))
9447 (*ImportedOrErr)->getCanonicalDecl()));
9448 else
9449 ImportErrors =
9450 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9451 }
9452 return ImportErrors;
9453}
9454
9456 ASTContext &FromContext, FileManager &FromFileManager,
9457 bool MinimalImport,
9458 std::shared_ptr<ASTImporterSharedState> SharedState)
9459 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9460 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9461 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9462
9463 // Create a default state without the lookup table: LLDB case.
9464 if (!SharedState) {
9465 this->SharedState = std::make_shared<ASTImporterSharedState>();
9466 }
9467
9468 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9469 ToContext.getTranslationUnitDecl();
9470}
9471
9472ASTImporter::~ASTImporter() = default;
9473
9475 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9476 "Try to get field index for non-field.");
9477
9478 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9479 if (!Owner)
9480 return std::nullopt;
9481
9482 unsigned Index = 0;
9483 for (const auto *D : Owner->decls()) {
9484 if (D == F)
9485 return Index;
9486
9488 ++Index;
9489 }
9490
9491 llvm_unreachable("Field was not found in its parent context.");
9492
9493 return std::nullopt;
9494}
9495
9496ASTImporter::FoundDeclsTy
9497ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9498 // We search in the redecl context because of transparent contexts.
9499 // E.g. a simple C language enum is a transparent context:
9500 // enum E { A, B };
9501 // Now if we had a global variable in the TU
9502 // int A;
9503 // then the enum constant 'A' and the variable 'A' violates ODR.
9504 // We can diagnose this only if we search in the redecl context.
9505 DeclContext *ReDC = DC->getRedeclContext();
9506 if (SharedState->getLookupTable()) {
9507 if (ReDC->isNamespace()) {
9508 // Namespaces can be reopened.
9509 // Lookup table does not handle this, we must search here in all linked
9510 // namespaces.
9511 FoundDeclsTy Result;
9512 SmallVector<Decl *, 2> NSChain =
9514 dyn_cast<NamespaceDecl>(ReDC));
9515 for (auto *D : NSChain) {
9517 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9518 Name);
9520 }
9521 return Result;
9522 } else {
9524 SharedState->getLookupTable()->lookup(ReDC, Name);
9525 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9526 }
9527 } else {
9528 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9529 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9530 // We must search by the slow case of localUncachedLookup because that is
9531 // working even if there is no LookupPtr for the DC. We could use
9532 // DC::buildLookup() to create the LookupPtr, but that would load external
9533 // decls again, we must avoid that case.
9534 // Also, even if we had the LookupPtr, we must find Decls which are not
9535 // in the LookupPtr, so we need the slow case.
9536 // These cases are handled in ASTImporterLookupTable, but we cannot use
9537 // that with LLDB since that traverses through the AST which initiates the
9538 // load of external decls again via DC::decls(). And again, we must avoid
9539 // loading external decls during the import.
9540 if (Result.empty())
9541 ReDC->localUncachedLookup(Name, Result);
9542 return Result;
9543 }
9544}
9545
9546void ASTImporter::AddToLookupTable(Decl *ToD) {
9547 SharedState->addDeclToLookup(ToD);
9548}
9549
9551 // Import the decl using ASTNodeImporter.
9552 ASTNodeImporter Importer(*this);
9553 return Importer.Visit(FromD);
9554}
9555
9557 MapImported(FromD, ToD);
9558}
9559
9562 if (auto *CLE = dyn_cast<CompoundLiteralExpr *>(From)) {
9563 if (Expected<Expr *> R = Import(CLE))
9565 }
9566
9567 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9568 // ASTNodeImporter.
9569 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9570}
9571
9573 if (!FromT)
9574 return FromT;
9575
9576 // Check whether we've already imported this type.
9577 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9578 ImportedTypes.find(FromT);
9579 if (Pos != ImportedTypes.end())
9580 return Pos->second;
9581
9582 // Import the type.
9583 ASTNodeImporter Importer(*this);
9584 ExpectedType ToTOrErr = Importer.Visit(FromT);
9585 if (!ToTOrErr)
9586 return ToTOrErr.takeError();
9587
9588 // Record the imported type.
9589 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9590
9591 return ToTOrErr->getTypePtr();
9592}
9593
9595 if (FromT.isNull())
9596 return QualType{};
9597
9598 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9599 if (!ToTyOrErr)
9600 return ToTyOrErr.takeError();
9601
9602 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9603}
9604
9606 if (!FromTSI)
9607 return FromTSI;
9608
9609 // FIXME: For now we just create a "trivial" type source info based
9610 // on the type and a single location. Implement a real version of this.
9611 ExpectedType TOrErr = Import(FromTSI->getType());
9612 if (!TOrErr)
9613 return TOrErr.takeError();
9614 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9615 if (!BeginLocOrErr)
9616 return BeginLocOrErr.takeError();
9617
9618 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9619}
9620
9621namespace {
9622// To use this object, it should be created before the new attribute is created,
9623// and destructed after it is created. The construction already performs the
9624// import of the data.
9625template <typename T> struct AttrArgImporter {
9626 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9627 AttrArgImporter(AttrArgImporter<T> &&) = default;
9628 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9629 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9630
9631 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9632 : To(I.importChecked(Err, From)) {}
9633
9634 const T &value() { return To; }
9635
9636private:
9637 T To;
9638};
9639
9640// To use this object, it should be created before the new attribute is created,
9641// and destructed after it is created. The construction already performs the
9642// import of the data. The array data is accessible in a pointer form, this form
9643// is used by the attribute classes. This object should be created once for the
9644// array data to be imported (the array size is not imported, just copied).
9645template <typename T> struct AttrArgArrayImporter {
9646 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9647 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9648 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9649 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9650
9651 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9652 const llvm::iterator_range<T *> &From,
9653 unsigned ArraySize) {
9654 if (Err)
9655 return;
9656 To.reserve(ArraySize);
9657 Err = I.ImportContainerChecked(From, To);
9658 }
9659
9660 T *value() { return To.data(); }
9661
9662private:
9663 llvm::SmallVector<T, 2> To;
9664};
9665
9666class AttrImporter {
9667 Error Err{Error::success()};
9668 Attr *ToAttr = nullptr;
9669 ASTImporter &Importer;
9670 ASTNodeImporter NImporter;
9671
9672public:
9673 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9674
9675 // Create an "importer" for an attribute parameter.
9676 // Result of the 'value()' of that object is to be passed to the function
9677 // 'importAttr', in the order that is expected by the attribute class.
9678 template <class T> AttrArgImporter<T> importArg(const T &From) {
9679 return AttrArgImporter<T>(NImporter, Err, From);
9680 }
9681
9682 // Create an "importer" for an attribute parameter that has array type.
9683 // Result of the 'value()' of that object is to be passed to the function
9684 // 'importAttr', then the size of the array as next argument.
9685 template <typename T>
9686 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9687 unsigned ArraySize) {
9688 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9689 }
9690
9691 // Create an attribute object with the specified arguments.
9692 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9693 // should be values that are passed to the 'Create' function of the attribute.
9694 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9695 // used here.) As much data is copied or imported from the old attribute
9696 // as possible. The passed arguments should be already imported.
9697 // If an import error happens, the internal error is set to it, and any
9698 // further import attempt is ignored.
9699 template <typename T, typename... Arg>
9700 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9701 static_assert(std::is_base_of<Attr, T>::value,
9702 "T should be subclass of Attr.");
9703 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9704
9705 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9706 const IdentifierInfo *ToScopeName =
9707 Importer.Import(FromAttr->getScopeName());
9708 SourceRange ToAttrRange =
9709 NImporter.importChecked(Err, FromAttr->getRange());
9710 SourceLocation ToScopeLoc =
9711 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9712
9713 if (Err)
9714 return;
9715
9716 AttributeCommonInfo ToI(
9717 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9718 FromAttr->getParsedKind(), FromAttr->getForm());
9719 // The "SemanticSpelling" is not needed to be passed to the constructor.
9720 // That value is recalculated from the SpellingListIndex if needed.
9721 ToAttr = T::Create(Importer.getToContext(),
9722 std::forward<Arg>(ImportedArg)..., ToI);
9723
9724 ToAttr->setImplicit(FromAttr->isImplicit());
9725 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9726 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9727 ToInheritableAttr->setInherited(FromAttr->isInherited());
9728 }
9729
9730 // Create a clone of the 'FromAttr' and import its source range only.
9731 // This causes objects with invalid references to be created if the 'FromAttr'
9732 // contains other data that should be imported.
9733 void cloneAttr(const Attr *FromAttr) {
9734 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9735
9736 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9737 if (Err)
9738 return;
9739
9740 ToAttr = FromAttr->clone(Importer.getToContext());
9741 ToAttr->setRange(ToRange);
9742 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9743 }
9744
9745 // Get the result of the previous import attempt (can be used only once).
9746 llvm::Expected<Attr *> getResult() && {
9747 if (Err)
9748 return std::move(Err);
9749 assert(ToAttr && "Attribute should be created.");
9750 return ToAttr;
9751 }
9752};
9753} // namespace
9754
9756 AttrImporter AI(*this);
9757
9758 // FIXME: Is there some kind of AttrVisitor to use here?
9759 switch (FromAttr->getKind()) {
9760 case attr::Aligned: {
9761 auto *From = cast<AlignedAttr>(FromAttr);
9762 if (From->isAlignmentExpr())
9763 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9764 else
9765 AI.importAttr(From, false,
9766 AI.importArg(From->getAlignmentType()).value());
9767 break;
9768 }
9769
9770 case attr::AlignValue: {
9771 auto *From = cast<AlignValueAttr>(FromAttr);
9772 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9773 break;
9774 }
9775
9776 case attr::Format: {
9777 const auto *From = cast<FormatAttr>(FromAttr);
9778 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9779 From->getFirstArg());
9780 break;
9781 }
9782
9783 case attr::EnableIf: {
9784 const auto *From = cast<EnableIfAttr>(FromAttr);
9785 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9786 From->getMessage());
9787 break;
9788 }
9789
9790 case attr::AssertCapability: {
9791 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9792 AI.importAttr(From,
9793 AI.importArrayArg(From->args(), From->args_size()).value(),
9794 From->args_size());
9795 break;
9796 }
9797 case attr::AcquireCapability: {
9798 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9799 AI.importAttr(From,
9800 AI.importArrayArg(From->args(), From->args_size()).value(),
9801 From->args_size());
9802 break;
9803 }
9804 case attr::TryAcquireCapability: {
9805 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9806 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9807 AI.importArrayArg(From->args(), From->args_size()).value(),
9808 From->args_size());
9809 break;
9810 }
9811 case attr::ReleaseCapability: {
9812 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9813 AI.importAttr(From,
9814 AI.importArrayArg(From->args(), From->args_size()).value(),
9815 From->args_size());
9816 break;
9817 }
9818 case attr::RequiresCapability: {
9819 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9820 AI.importAttr(From,
9821 AI.importArrayArg(From->args(), From->args_size()).value(),
9822 From->args_size());
9823 break;
9824 }
9825 case attr::GuardedBy: {
9826 const auto *From = cast<GuardedByAttr>(FromAttr);
9827 AI.importAttr(From,
9828 AI.importArrayArg(From->args(), From->args_size()).value(),
9829 From->args_size());
9830 break;
9831 }
9832 case attr::PtGuardedBy: {
9833 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9834 AI.importAttr(From,
9835 AI.importArrayArg(From->args(), From->args_size()).value(),
9836 From->args_size());
9837 break;
9838 }
9839 case attr::AcquiredAfter: {
9840 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9841 AI.importAttr(From,
9842 AI.importArrayArg(From->args(), From->args_size()).value(),
9843 From->args_size());
9844 break;
9845 }
9846 case attr::AcquiredBefore: {
9847 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9848 AI.importAttr(From,
9849 AI.importArrayArg(From->args(), From->args_size()).value(),
9850 From->args_size());
9851 break;
9852 }
9853 case attr::LockReturned: {
9854 const auto *From = cast<LockReturnedAttr>(FromAttr);
9855 AI.importAttr(From, AI.importArg(From->getArg()).value());
9856 break;
9857 }
9858 case attr::LocksExcluded: {
9859 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9860 AI.importAttr(From,
9861 AI.importArrayArg(From->args(), From->args_size()).value(),
9862 From->args_size());
9863 break;
9864 }
9865 default: {
9866 // The default branch works for attributes that have no arguments to import.
9867 // FIXME: Handle every attribute type that has arguments of type to import
9868 // (most often Expr* or Decl* or type) in the switch above.
9869 AI.cloneAttr(FromAttr);
9870 break;
9871 }
9872 }
9873
9874 return std::move(AI).getResult();
9875}
9876
9878 return ImportedDecls.lookup(FromD);
9879}
9880
9882 auto FromDPos = ImportedFromDecls.find(ToD);
9883 if (FromDPos == ImportedFromDecls.end())
9884 return nullptr;
9885 return FromDPos->second->getTranslationUnitDecl();
9886}
9887
9889 if (!FromD)
9890 return nullptr;
9891
9892 // Push FromD to the stack, and remove that when we return.
9893 ImportPath.push(FromD);
9894 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9895
9896 // Check whether there was a previous failed import.
9897 // If yes return the existing error.
9898 if (auto Error = getImportDeclErrorIfAny(FromD))
9899 return make_error<ASTImportError>(*Error);
9900
9901 // Check whether we've already imported this declaration.
9902 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9903 if (ToD) {
9904 // Already imported (possibly from another TU) and with an error.
9905 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9906 setImportDeclError(FromD, *Error);
9907 return make_error<ASTImportError>(*Error);
9908 }
9909
9910 // If FromD has some updated flags after last import, apply it.
9911 updateFlags(FromD, ToD);
9912 // If we encounter a cycle during an import then we save the relevant part
9913 // of the import path associated to the Decl.
9914 if (ImportPath.hasCycleAtBack())
9915 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9916 return ToD;
9917 }
9918
9919 // Import the declaration.
9920 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9921 if (!ToDOrErr) {
9922 // Failed to import.
9923
9924 auto Pos = ImportedDecls.find(FromD);
9925 bool ToDWasCreated = Pos != ImportedDecls.end();
9926 // Capture the mapped decl before erasing: the iterator is invalidated by
9927 // the erase below under backward-shift deletion, but it is still needed
9928 // further down to record the import error.
9929 Decl *CreatedToD = ToDWasCreated ? Pos->second : nullptr;
9930 if (ToDWasCreated) {
9931 // Import failed after the object was created.
9932 // Remove all references to it.
9933 auto *ToD = CreatedToD;
9934 ImportedDecls.erase(Pos);
9935
9936 // Remove the imported type mapping as well.
9937 // The imported type can point to a declaration that failed to import
9938 // later.
9939 if (const auto *FromTD = dyn_cast<TagDecl>(FromD)) {
9940 if (const Type *FromTy =
9941 getFromContext().getCanonicalTagType(FromTD).getTypePtr()) {
9942 ImportedTypes.erase(FromTy);
9943 }
9944 }
9945
9946 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9947 // (e.g. with namespaces) that several decls from the 'from' context are
9948 // mapped to the same decl in the 'to' context. If we removed entries
9949 // from the LookupTable here then we may end up removing them multiple
9950 // times.
9951
9952 // The Lookuptable contains decls only which are in the 'to' context.
9953 // Remove from the Lookuptable only if it is *imported* into the 'to'
9954 // context (and do not remove it if it was added during the initial
9955 // traverse of the 'to' context).
9956 auto PosF = ImportedFromDecls.find(ToD);
9957 if (PosF != ImportedFromDecls.end()) {
9958 // In the case of TypedefNameDecl we create the Decl first and only
9959 // then we import and set its DeclContext. So, the DC might not be set
9960 // when we reach here.
9961 if (ToD->getDeclContext())
9962 SharedState->removeDeclFromLookup(ToD);
9963 ImportedFromDecls.erase(PosF);
9964 }
9965
9966 // FIXME: AST may contain remaining references to the failed object.
9967 // However, the ImportDeclErrors in the shared state contains all the
9968 // failed objects together with their error.
9969 }
9970
9971 // Error encountered for the first time.
9972 // After takeError the error is not usable any more in ToDOrErr.
9973 // Get a copy of the error object (any more simple solution for this?).
9974 ASTImportError ErrOut;
9975 handleAllErrors(ToDOrErr.takeError(),
9976 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9977 setImportDeclError(FromD, ErrOut);
9978 // Set the error for the mapped to Decl, which is in the "to" context.
9979 if (ToDWasCreated)
9980 SharedState->setImportDeclError(CreatedToD, ErrOut);
9981
9982 // Set the error for all nodes which have been created before we
9983 // recognized the error.
9984 for (const auto &Path : SavedImportPaths[FromD]) {
9985 // The import path contains import-dependency nodes first.
9986 // Save the node that was imported as dependency of the current node.
9987 Decl *PrevFromDi = FromD;
9988 for (Decl *FromDi : Path) {
9989 // Begin and end of the path equals 'FromD', skip it.
9990 if (FromDi == FromD)
9991 continue;
9992 // We should not set import error on a node and all following nodes in
9993 // the path if child import errors are ignored.
9994 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9995 PrevFromDi))
9996 break;
9997 PrevFromDi = FromDi;
9998 setImportDeclError(FromDi, ErrOut);
9999
10000 if (const auto *FromTDi = dyn_cast<TagDecl>(FromDi)) {
10001 if (const Type *FromTyi =
10002 getFromContext().getCanonicalTagType(FromTDi).getTypePtr()) {
10003 ImportedTypes.erase(FromTyi);
10004 }
10005 }
10006
10007 //FIXME Should we remove these Decls from ImportedDecls?
10008 // Set the error for the mapped to Decl, which is in the "to" context.
10009 auto Ii = ImportedDecls.find(FromDi);
10010 if (Ii != ImportedDecls.end())
10011 SharedState->setImportDeclError(Ii->second, ErrOut);
10012 // FIXME Should we remove these Decls from the LookupTable,
10013 // and from ImportedFromDecls?
10014 }
10015 }
10016 SavedImportPaths.erase(FromD);
10017
10018 // Do not return ToDOrErr, error was taken out of it.
10019 return make_error<ASTImportError>(ErrOut);
10020 }
10021
10022 ToD = *ToDOrErr;
10023
10024 // FIXME: Handle the "already imported with error" case. We can get here
10025 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
10026 // previously failed create was requested).
10027 // Later GetImportedOrCreateDecl can be updated to return the error.
10028 if (!ToD) {
10029 auto Err = getImportDeclErrorIfAny(FromD);
10030 assert(Err);
10031 return make_error<ASTImportError>(*Err);
10032 }
10033
10034 // We could import from the current TU without error. But previously we
10035 // already had imported a Decl as `ToD` from another TU (with another
10036 // ASTImporter object) and with an error.
10037 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
10038 setImportDeclError(FromD, *Error);
10039 return make_error<ASTImportError>(*Error);
10040 }
10041 // Make sure that ImportImpl registered the imported decl.
10042 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
10043
10044 if (FromD->hasAttrs())
10045 for (const Attr *FromAttr : FromD->getAttrs()) {
10046 auto ToAttrOrErr = Import(FromAttr);
10047 if (ToAttrOrErr)
10048 ToD->addAttr(*ToAttrOrErr);
10049 else
10050 return ToAttrOrErr.takeError();
10051 }
10052
10053 // Notify subclasses.
10054 Imported(FromD, ToD);
10055
10056 updateFlags(FromD, ToD);
10057 SavedImportPaths.erase(FromD);
10058 return ToDOrErr;
10059}
10060
10063 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
10064}
10065
10067 if (!FromDC)
10068 return FromDC;
10069
10070 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
10071 if (!ToDCOrErr)
10072 return ToDCOrErr.takeError();
10073 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
10074
10075 // When we're using a record/enum/Objective-C class/protocol as a context, we
10076 // need it to have a definition.
10077 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
10078 auto *FromRecord = cast<RecordDecl>(FromDC);
10079 if (ToRecord->isCompleteDefinition())
10080 return ToDC;
10081
10082 // If FromRecord is not defined we need to force it to be.
10083 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
10084 // it will start the definition but we never finish it.
10085 // If there are base classes they won't be imported and we will
10086 // be missing anything that we inherit from those bases.
10087 if (FromRecord->getASTContext().getExternalSource() &&
10088 !FromRecord->isCompleteDefinition())
10089 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
10090
10091 if (FromRecord->isCompleteDefinition())
10092 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10093 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
10094 return std::move(Err);
10095 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
10096 auto *FromEnum = cast<EnumDecl>(FromDC);
10097 if (ToEnum->isCompleteDefinition()) {
10098 // Do nothing.
10099 } else if (FromEnum->isCompleteDefinition()) {
10100 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10101 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
10102 return std::move(Err);
10103 } else {
10104 CompleteDecl(ToEnum);
10105 }
10106 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
10107 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
10108 if (ToClass->getDefinition()) {
10109 // Do nothing.
10110 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
10111 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10112 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10113 return std::move(Err);
10114 } else {
10115 CompleteDecl(ToClass);
10116 }
10117 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10118 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10119 if (ToProto->getDefinition()) {
10120 // Do nothing.
10121 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10122 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10123 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10124 return std::move(Err);
10125 } else {
10126 CompleteDecl(ToProto);
10127 }
10128 }
10129
10130 return ToDC;
10131}
10132
10134 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10135 return cast_or_null<Expr>(*ToSOrErr);
10136 else
10137 return ToSOrErr.takeError();
10138}
10139
10141 if (!FromS)
10142 return nullptr;
10143
10144 // Check whether we've already imported this statement.
10145 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10146 if (Pos != ImportedStmts.end())
10147 return Pos->second;
10148
10149 // Import the statement.
10150 ASTNodeImporter Importer(*this);
10151 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10152 if (!ToSOrErr)
10153 return ToSOrErr;
10154
10155 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10156 auto *FromE = cast<Expr>(FromS);
10157 // Copy ExprBitfields, which may not be handled in Expr subclasses
10158 // constructors.
10159 ToE->setValueKind(FromE->getValueKind());
10160 ToE->setObjectKind(FromE->getObjectKind());
10161 ToE->setDependence(FromE->getDependence());
10162 }
10163
10164 // Record the imported statement object.
10165 ImportedStmts[FromS] = *ToSOrErr;
10166 return ToSOrErr;
10167}
10168
10170 switch (FromNNS.getKind()) {
10173 return FromNNS;
10175 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10176 auto NSOrErr = Import(Namespace);
10177 if (!NSOrErr)
10178 return NSOrErr.takeError();
10179 auto PrefixOrErr = Import(Prefix);
10180 if (!PrefixOrErr)
10181 return PrefixOrErr.takeError();
10182 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10183 *PrefixOrErr);
10184 }
10186 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10187 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10188 else
10189 return RDOrErr.takeError();
10191 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10192 return NestedNameSpecifier(*TyOrErr);
10193 } else {
10194 return TyOrErr.takeError();
10195 }
10196 }
10197 llvm_unreachable("Invalid nested name specifier kind");
10198}
10199
10202 // Copied from NestedNameSpecifier mostly.
10204 NestedNameSpecifierLoc NNS = FromNNS;
10205
10206 // Push each of the nested-name-specifiers's onto a stack for
10207 // serialization in reverse order.
10208 while (NNS) {
10209 NestedNames.push_back(NNS);
10210 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10211 }
10212
10214
10215 while (!NestedNames.empty()) {
10216 NNS = NestedNames.pop_back_val();
10217 NestedNameSpecifier Spec = std::nullopt;
10218 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10219 return std::move(Err);
10220
10221 NestedNameSpecifier::Kind Kind = Spec.getKind();
10222
10223 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10225 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10226 return std::move(Err);
10227
10229 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10230 return std::move(Err);
10231 }
10232
10233 switch (Kind) {
10235 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10236 ToLocalBeginLoc, ToLocalEndLoc);
10237 break;
10238
10240 SourceLocation ToTLoc;
10241 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10242 return std::move(Err);
10244 QualType(Spec.getAsType(), 0), ToTLoc);
10245 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10246 break;
10247 }
10248
10250 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10251 break;
10252
10254 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10255 if (!ToSourceRangeOrErr)
10256 return ToSourceRangeOrErr.takeError();
10257
10258 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10259 ToSourceRangeOrErr->getBegin(),
10260 ToSourceRangeOrErr->getEnd());
10261 break;
10262 }
10264 llvm_unreachable("unexpected null nested name specifier");
10265 }
10266 }
10267
10268 return Builder.getWithLocInContext(getToContext());
10269}
10270
10272 switch (From.getKind()) {
10274 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10275 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10276 else
10277 return ToTemplateOrErr.takeError();
10278
10281 UnresolvedSet<2> ToTemplates;
10282 for (auto *I : *FromStorage) {
10283 if (auto ToOrErr = Import(I))
10284 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10285 else
10286 return ToOrErr.takeError();
10287 }
10288 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10289 ToTemplates.end());
10290 }
10291
10294 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10295 if (!DeclNameOrErr)
10296 return DeclNameOrErr.takeError();
10297 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10298 }
10299
10302 auto QualifierOrErr = Import(QTN->getQualifier());
10303 if (!QualifierOrErr)
10304 return QualifierOrErr.takeError();
10305 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10306 if (!TNOrErr)
10307 return TNOrErr.takeError();
10308 return ToContext.getQualifiedTemplateName(
10309 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10310 }
10311
10314 auto QualifierOrErr = Import(DTN->getQualifier());
10315 if (!QualifierOrErr)
10316 return QualifierOrErr.takeError();
10317 return ToContext.getDependentTemplateName(
10318 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10319 }
10320
10324 auto ReplacementOrErr = Import(Subst->getReplacement());
10325 if (!ReplacementOrErr)
10326 return ReplacementOrErr.takeError();
10327
10328 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10329 if (!AssociatedDeclOrErr)
10330 return AssociatedDeclOrErr.takeError();
10331
10332 return ToContext.getSubstTemplateTemplateParm(
10333 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10334 Subst->getPackIndex(), Subst->getFinal());
10335 }
10336
10340 ASTNodeImporter Importer(*this);
10341 auto ArgPackOrErr =
10342 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10343 if (!ArgPackOrErr)
10344 return ArgPackOrErr.takeError();
10345
10346 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10347 if (!AssociatedDeclOrErr)
10348 return AssociatedDeclOrErr.takeError();
10349
10350 return ToContext.getSubstTemplateTemplateParmPack(
10351 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10352 SubstPack->getFinal());
10353 }
10356 auto PatternOrErr = Import(PI->getPattern());
10357 if (!PatternOrErr)
10358 return PatternOrErr.takeError();
10359
10360 auto IndexExprOrErr = Import(PI->getIndexExpr());
10361 if (!IndexExprOrErr)
10362 return IndexExprOrErr.takeError();
10363
10365 for (TemplateName T : PI->getExpansions()) {
10366 auto ExpansionOrErr = Import(T);
10367 if (!ExpansionOrErr)
10368 return ExpansionOrErr.takeError();
10369 Expansions.push_back(*ExpansionOrErr);
10370 }
10371
10372 return ToContext.getPackIndexingTemplateName(
10373 *PatternOrErr, *IndexExprOrErr, PI->isFullySubstituted(), Expansions);
10374 }
10376 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10377 if (!UsingOrError)
10378 return UsingOrError.takeError();
10379 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10380 }
10382 llvm_unreachable("Unexpected DeducedTemplate");
10383 }
10384
10385 llvm_unreachable("Invalid template name kind");
10386}
10387
10389 if (FromLoc.isInvalid())
10390 return SourceLocation{};
10391
10392 SourceManager &FromSM = FromContext.getSourceManager();
10393 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10394
10395 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10396 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10397 if (!ToFileIDOrErr)
10398 return ToFileIDOrErr.takeError();
10399 SourceManager &ToSM = ToContext.getSourceManager();
10400 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10401}
10402
10404 SourceLocation ToBegin, ToEnd;
10405 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10406 return std::move(Err);
10407 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10408 return std::move(Err);
10409
10410 return SourceRange(ToBegin, ToEnd);
10411}
10412
10414 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10415 if (Pos != ImportedFileIDs.end())
10416 return Pos->second;
10417
10418 SourceManager &FromSM = FromContext.getSourceManager();
10419 SourceManager &ToSM = ToContext.getSourceManager();
10420 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10421
10422 // Map the FromID to the "to" source manager.
10423 FileID ToID;
10424 if (FromSLoc.isExpansion()) {
10425 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10426 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10427 if (!ToSpLoc)
10428 return ToSpLoc.takeError();
10429 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10430 if (!ToExLocS)
10431 return ToExLocS.takeError();
10432 unsigned ExLength = FromSM.getFileIDSize(FromID);
10433 SourceLocation MLoc;
10434 if (FromEx.isMacroArgExpansion()) {
10435 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10436 } else {
10437 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10438 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10439 FromEx.isExpansionTokenRange());
10440 else
10441 return ToExLocE.takeError();
10442 }
10443 ToID = ToSM.getFileID(MLoc);
10444 } else {
10445 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10446
10447 if (!IsBuiltin && !Cache->BufferOverridden) {
10448 // Include location of this file.
10449 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10450 if (!ToIncludeLoc)
10451 return ToIncludeLoc.takeError();
10452
10453 // Every FileID that is not the main FileID needs to have a valid include
10454 // location so that the include chain points to the main FileID. When
10455 // importing the main FileID (which has no include location), we need to
10456 // create a fake include location in the main file to keep this property
10457 // intact.
10458 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10459 if (FromID == FromSM.getMainFileID())
10460 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10461
10462 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10463 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10464 // the disk again
10465 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10466 // than mmap the files several times.
10467 auto Entry =
10468 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10469 // FIXME: The filename may be a virtual name that does probably not
10470 // point to a valid file and we get no Entry here. In this case try with
10471 // the memory buffer below.
10472 if (Entry)
10473 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10474 FromSLoc.getFile().getFileCharacteristic());
10475 }
10476 }
10477
10478 if (ToID.isInvalid() || IsBuiltin) {
10479 // FIXME: We want to re-use the existing MemoryBuffer!
10480 std::optional<llvm::MemoryBufferRef> FromBuf =
10481 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10482 FromSM.getFileManager(), SourceLocation{});
10483 if (!FromBuf)
10484 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10485
10486 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10487 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10488 FromBuf->getBufferIdentifier());
10489 ToID = ToSM.createFileID(std::move(ToBuf),
10490 FromSLoc.getFile().getFileCharacteristic());
10491 }
10492 }
10493
10494 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10495
10496 ImportedFileIDs[FromID] = ToID;
10497 return ToID;
10498}
10499
10501 ExpectedExpr ToExprOrErr = Import(From->getInit());
10502 if (!ToExprOrErr)
10503 return ToExprOrErr.takeError();
10504
10505 auto LParenLocOrErr = Import(From->getLParenLoc());
10506 if (!LParenLocOrErr)
10507 return LParenLocOrErr.takeError();
10508
10509 auto RParenLocOrErr = Import(From->getRParenLoc());
10510 if (!RParenLocOrErr)
10511 return RParenLocOrErr.takeError();
10512
10513 if (From->isBaseInitializer()) {
10514 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10515 if (!ToTInfoOrErr)
10516 return ToTInfoOrErr.takeError();
10517
10518 SourceLocation EllipsisLoc;
10519 if (From->isPackExpansion())
10520 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10521 return std::move(Err);
10522
10523 return new (ToContext) CXXCtorInitializer(
10524 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10525 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10526 } else if (From->isMemberInitializer()) {
10527 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10528 if (!ToFieldOrErr)
10529 return ToFieldOrErr.takeError();
10530
10531 auto MemberLocOrErr = Import(From->getMemberLocation());
10532 if (!MemberLocOrErr)
10533 return MemberLocOrErr.takeError();
10534
10535 return new (ToContext) CXXCtorInitializer(
10536 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10537 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10538 } else if (From->isIndirectMemberInitializer()) {
10539 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10540 if (!ToIFieldOrErr)
10541 return ToIFieldOrErr.takeError();
10542
10543 auto MemberLocOrErr = Import(From->getMemberLocation());
10544 if (!MemberLocOrErr)
10545 return MemberLocOrErr.takeError();
10546
10547 return new (ToContext) CXXCtorInitializer(
10548 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10549 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10550 } else if (From->isDelegatingInitializer()) {
10551 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10552 if (!ToTInfoOrErr)
10553 return ToTInfoOrErr.takeError();
10554
10555 return new (ToContext)
10556 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10557 *ToExprOrErr, *RParenLocOrErr);
10558 } else {
10559 // FIXME: assert?
10560 return make_error<ASTImportError>();
10561 }
10562}
10563
10566 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10567 if (Pos != ImportedCXXBaseSpecifiers.end())
10568 return Pos->second;
10569
10570 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10571 if (!ToSourceRange)
10572 return ToSourceRange.takeError();
10574 if (!ToTSI)
10575 return ToTSI.takeError();
10576 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10577 if (!ToEllipsisLoc)
10578 return ToEllipsisLoc.takeError();
10579 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10580 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10581 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10582 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10583 return Imported;
10584}
10585
10587 ASTNodeImporter Importer(*this);
10588 return Importer.ImportAPValue(FromValue);
10589}
10590
10592 ExpectedDecl ToOrErr = Import(From);
10593 if (!ToOrErr)
10594 return ToOrErr.takeError();
10595 Decl *To = *ToOrErr;
10596
10597 auto *FromDC = cast<DeclContext>(From);
10598 ASTNodeImporter Importer(*this);
10599
10600 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10601 if (!ToRecord->getDefinition()) {
10602 return Importer.ImportDefinition(
10603 cast<RecordDecl>(FromDC), ToRecord,
10605 }
10606 }
10607
10608 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10609 if (!ToEnum->getDefinition()) {
10610 return Importer.ImportDefinition(
10612 }
10613 }
10614
10615 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10616 if (!ToIFace->getDefinition()) {
10617 return Importer.ImportDefinition(
10618 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10620 }
10621 }
10622
10623 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10624 if (!ToProto->getDefinition()) {
10625 return Importer.ImportDefinition(
10626 cast<ObjCProtocolDecl>(FromDC), ToProto,
10628 }
10629 }
10630
10631 return Importer.ImportDeclContext(FromDC, true);
10632}
10633
10635 if (!FromName)
10636 return DeclarationName{};
10637
10638 switch (FromName.getNameKind()) {
10640 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10641
10645 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10646 return DeclarationName(*ToSelOrErr);
10647 else
10648 return ToSelOrErr.takeError();
10649
10651 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10652 return ToContext.DeclarationNames.getCXXConstructorName(
10653 ToContext.getCanonicalType(*ToTyOrErr));
10654 else
10655 return ToTyOrErr.takeError();
10656 }
10657
10659 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10660 return ToContext.DeclarationNames.getCXXDestructorName(
10661 ToContext.getCanonicalType(*ToTyOrErr));
10662 else
10663 return ToTyOrErr.takeError();
10664 }
10665
10667 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10668 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10669 cast<TemplateDecl>(*ToTemplateOrErr));
10670 else
10671 return ToTemplateOrErr.takeError();
10672 }
10673
10675 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10676 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10677 ToContext.getCanonicalType(*ToTyOrErr));
10678 else
10679 return ToTyOrErr.takeError();
10680 }
10681
10683 return ToContext.DeclarationNames.getCXXOperatorName(
10684 FromName.getCXXOverloadedOperator());
10685
10687 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10688 Import(FromName.getCXXLiteralIdentifier()));
10689
10691 // FIXME: STATICS!
10693 }
10694
10695 llvm_unreachable("Invalid DeclarationName Kind!");
10696}
10697
10699 if (!FromId)
10700 return nullptr;
10701
10702 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10703
10704 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10705 ToId->setBuiltinID(FromId->getBuiltinID());
10706
10707 return ToId;
10708}
10709
10712 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10713 return Import(FromII);
10714 return FromIO.getOperator();
10715}
10716
10718 if (FromSel.isNull())
10719 return Selector{};
10720
10722 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10723 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10724 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10725 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10726}
10727
10731 llvm::Error Err = llvm::Error::success();
10732 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10733 for (unsigned Idx = 0; Idx < Size; Idx++) {
10734 APValue Tmp = importChecked(Err, From[Idx]);
10735 To[Idx] = Tmp;
10736 }
10737 };
10738 switch (FromValue.getKind()) {
10739 case APValue::None:
10741 case APValue::Int:
10742 case APValue::Float:
10746 Result = FromValue;
10747 break;
10748 case APValue::Vector: {
10749 Result.MakeVector();
10751 Result.setVectorUninit(FromValue.getVectorLength());
10752 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10753 Elts.data(), FromValue.getVectorLength());
10754 break;
10755 }
10756 case APValue::Matrix:
10757 // Matrix values cannot currently arise in APValue import contexts.
10758 llvm_unreachable("Matrix APValue import not yet supported");
10759 case APValue::Array:
10760 Result.MakeArray(FromValue.getArrayInitializedElts(),
10761 FromValue.getArraySize());
10762 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10763 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10764 FromValue.getArrayInitializedElts());
10765 break;
10766 case APValue::Struct:
10767 Result.MakeStruct(FromValue.getStructNumBases(),
10768 FromValue.getStructNumFields(),
10769 FromValue.getStructNumVirtualBases());
10770 ImportLoop(
10771 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10772 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10773 FromValue.getStructNumBases() + FromValue.getStructNumFields() +
10774 FromValue.getStructNumVirtualBases());
10775 break;
10776 case APValue::Union: {
10777 Result.MakeUnion();
10778 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10779 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10780 if (Err)
10781 return std::move(Err);
10782 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10783 break;
10784 }
10786 Result.MakeAddrLabelDiff();
10787 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10788 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10789 if (Err)
10790 return std::move(Err);
10791 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10792 cast<AddrLabelExpr>(ImpRHS));
10793 break;
10794 }
10796 const Decl *ImpMemPtrDecl =
10797 importChecked(Err, FromValue.getMemberPointerDecl());
10798 if (Err)
10799 return std::move(Err);
10801 Result.setMemberPointerUninit(
10802 cast<const ValueDecl>(ImpMemPtrDecl),
10804 FromValue.getMemberPointerPath().size());
10805 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10806 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10807 Idx++) {
10808 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10809 if (Err)
10810 return std::move(Err);
10811 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10812 }
10813 break;
10814 }
10815 case APValue::LValue: {
10817 QualType FromElemTy;
10818 if (FromValue.getLValueBase()) {
10819 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10820 "in C++20 dynamic allocation are transient so they shouldn't "
10821 "appear in the AST");
10822 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10823 if (const auto *E =
10824 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10825 FromElemTy = E->getType();
10826 const Expr *ImpExpr = importChecked(Err, E);
10827 if (Err)
10828 return std::move(Err);
10829 Base = APValue::LValueBase(ImpExpr,
10830 FromValue.getLValueBase().getCallIndex(),
10831 FromValue.getLValueBase().getVersion());
10832 } else {
10833 FromElemTy =
10834 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10835 const Decl *ImpDecl = importChecked(
10836 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10837 if (Err)
10838 return std::move(Err);
10840 FromValue.getLValueBase().getCallIndex(),
10841 FromValue.getLValueBase().getVersion());
10842 }
10843 } else {
10844 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10845 const Type *ImpTypeInfo = importChecked(
10846 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10847 QualType ImpType =
10848 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10849 if (Err)
10850 return std::move(Err);
10852 ImpType);
10853 }
10854 }
10855 CharUnits Offset = FromValue.getLValueOffset();
10856 unsigned PathLength = FromValue.getLValuePath().size();
10857 Result.MakeLValue();
10858 if (FromValue.hasLValuePath()) {
10859 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10860 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10861 FromValue.isNullPointer());
10863 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10864 if (FromElemTy->isRecordType()) {
10865 const Decl *FromDecl =
10866 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10867 const Decl *ImpDecl = importChecked(Err, FromDecl);
10868 if (Err)
10869 return std::move(Err);
10870 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10871 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10872 else
10873 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10875 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10876 } else {
10877 FromElemTy =
10878 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10879 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10880 FromPath[LoopIdx].getAsArrayIndex());
10881 }
10882 }
10883 } else
10884 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10885 FromValue.isNullPointer());
10886 break;
10887 }
10888 case APValue::Reflection: {
10889 switch (FromValue.getReflectionOperandKind()) {
10892 break;
10893 case ReflectionKind::Type: {
10894 auto *FromTSI =
10895 const_cast<TypeSourceInfo *>(static_cast<const TypeSourceInfo *>(
10896 FromValue.getReflectionOpaqueOperand()));
10897 TypeSourceInfo *ToTSI = importChecked(Err, FromTSI);
10898 if (Err)
10899 return std::move(Err);
10901 break;
10902 }
10903 }
10904 break;
10905 }
10906 }
10907 if (Err)
10908 return std::move(Err);
10909 return Result;
10910}
10911
10913 DeclContext *DC,
10914 unsigned IDNS,
10915 NamedDecl **Decls,
10916 unsigned NumDecls) {
10917 if (ODRHandling == ODRHandlingType::Conservative)
10918 // Report error at any name conflict.
10919 return make_error<ASTImportError>(ASTImportError::NameConflict);
10920 else
10921 // Allow to create the new Decl with the same name.
10922 return Name;
10923}
10924
10926 if (LastDiagFromFrom)
10927 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10928 FromContext.getDiagnostics());
10929 LastDiagFromFrom = false;
10930 return ToContext.getDiagnostics().Report(Loc, DiagID);
10931}
10932
10934 if (!LastDiagFromFrom)
10935 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10936 ToContext.getDiagnostics());
10937 LastDiagFromFrom = true;
10938 return FromContext.getDiagnostics().Report(Loc, DiagID);
10939}
10940
10942 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10943 if (!ID->getDefinition())
10944 ID->startDefinition();
10945 }
10946 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10947 if (!PD->getDefinition())
10948 PD->startDefinition();
10949 }
10950 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10951 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10952 TD->startDefinition();
10953 TD->setCompleteDefinition(true);
10954 }
10955 }
10956 else {
10957 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10958 }
10959}
10960
10962 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10963 assert((Inserted || Pos->second == To) &&
10964 "Try to import an already imported Decl");
10965 if (!Inserted)
10966 return Pos->second;
10967 // This mapping should be maintained only in this function. Therefore do not
10968 // check for additional consistency.
10969 ImportedFromDecls[To] = From;
10970 // In the case of TypedefNameDecl we create the Decl first and only then we
10971 // import and set its DeclContext. So, the DC is still not set when we reach
10972 // here from GetImportedOrCreateDecl.
10973 if (To->getDeclContext())
10974 AddToLookupTable(To);
10975 return To;
10976}
10977
10978std::optional<ASTImportError>
10980 auto Pos = ImportDeclErrors.find(FromD);
10981 if (Pos != ImportDeclErrors.end())
10982 return Pos->second;
10983 else
10984 return std::nullopt;
10985}
10986
10988 auto InsertRes = ImportDeclErrors.insert({From, Error});
10989 (void)InsertRes;
10990 // Either we set the error for the first time, or we already had set one and
10991 // now we want to set the same error.
10992 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10993}
10994
10996 bool Complain) {
10997 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10998 ImportedTypes.find(From.getTypePtr());
10999 if (Pos != ImportedTypes.end()) {
11000 if (ExpectedType ToFromOrErr = Import(From)) {
11001 if (ToContext.hasSameType(*ToFromOrErr, To))
11002 return true;
11003 } else {
11004 llvm::consumeError(ToFromOrErr.takeError());
11005 }
11006 }
11007
11009 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
11010 getStructuralEquivalenceKind(*this), false, Complain);
11011 return Ctx.IsEquivalent(From, To);
11012}
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:112
QualType getTypeInfoType() const
Definition APValue.cpp:116
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition APValue.cpp:54
unsigned getCallIndex() const
Definition APValue.cpp:107
A non-discriminated union of a base, field, or array index.
Definition APValue.h:211
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition APValue.h:219
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:124
const LValueBase getLValueBase() const
Definition APValue.cpp:1065
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1085
const void * getReflectionOpaqueOperand() const
Definition APValue.h:747
const FieldDecl * getUnionField() const
Definition APValue.h:717
unsigned getStructNumFields() const
Definition APValue.h:683
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:208
ValueKind getKind() const
Definition APValue.h:503
ReflectionKind getReflectionOperandKind() const
Definition APValue.h:742
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:1070
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1155
unsigned getArrayInitializedElts() const
Definition APValue.h:670
unsigned getStructNumBases() const
Definition APValue.h:679
unsigned getStructNumVirtualBases() const
Definition APValue.h:687
bool hasLValuePath() const
Definition APValue.cpp:1080
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1148
APValue & getUnionValue()
Definition APValue.h:721
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:737
CharUnits & getLValueOffset()
Definition APValue.cpp:1075
unsigned getVectorLength() const
Definition APValue.h:615
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1162
unsigned getArraySize() const
Definition APValue.h:674
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition APValue.h:133
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:131
bool isNullPointer() const
Definition APValue.cpp:1101
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:733
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:239
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
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 VisitCXXReflectExpr(CXXReflectExpr *E)
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)
ExpectedDecl VisitFriendTemplateDecl(FriendTemplateDecl *D)
ExpectedStmt VisitCXXParenListInitExpr(CXXParenListInitExpr *E)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
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 VisitDependentTemplateIdExpr(DependentTemplateIdExpr *E)
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:4425
SourceLocation getQuestionLoc() const
Definition Expr.h:4424
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:4594
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4609
SourceLocation getLabelLoc() const
Definition Expr.h:4611
LabelDecl * getLabel() const
Definition Expr.h:4617
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6071
Represents a loop initializing the elements of an array.
Definition Expr.h:6018
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:6033
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:6038
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2765
SourceLocation getRBracketLoc() const
Definition Expr.h:2813
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2794
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:3011
uint64_t getValue() const
Definition ExprCXX.h:3059
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3049
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3051
Expr * getDimensionExpression() const
Definition ExprCXX.h:3061
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3057
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3048
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3820
bool isVolatile() const
Definition Stmt.h:3325
outputs_range outputs()
Definition Stmt.h:3432
SourceLocation getAsmLoc() const
Definition Stmt.h:3319
inputs_range inputs()
Definition Stmt.h:3403
unsigned getNumClobbers() const
Definition Stmt.h:3380
unsigned getNumOutputs() const
Definition Stmt.h:3348
unsigned getNumInputs() const
Definition Stmt.h:3370
bool isSimple() const
Definition Stmt.h:3322
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:6978
Expr ** getSubExprs()
Definition Expr.h:7053
SourceLocation getRParenLoc() const
Definition Expr.h:7107
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5315
AtomicOp getOp() const
Definition Expr.h:7041
SourceLocation getBuiltinLoc() const
Definition Expr.h:7106
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:2215
Stmt * getSubStmt()
Definition Stmt.h:2251
SourceLocation getAttrLoc() const
Definition Stmt.h:2246
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2247
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:3526
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3516
shadow_range shadows() const
Definition DeclCXX.h:3592
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4497
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4551
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4535
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4539
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4544
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4532
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4082
Expr * getLHS() const
Definition Expr.h:4132
SourceLocation getOperatorLoc() const
Definition Expr.h:4124
Expr * getRHS() const
Definition Expr.h:4134
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:5141
Opcode getOpcode() const
Definition Expr.h:4127
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4302
A binding in a decomposition declaration.
Definition DeclCXX.h:4215
void setDecomposedDecl(DecompositionDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4259
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4241
DecompositionDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4248
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:4253
BreakStmt - This represents a break.
Definition Stmt.h:3147
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5530
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:3245
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:2138
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:1498
CXXTemporary * getTemporary()
Definition ExprCXX.h:1516
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition ExprCXX.cpp:1150
const Expr * getSubExpr() const
Definition ExprCXX.h:1520
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:728
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition ExprCXX.h:740
bool getValue() const
Definition ExprCXX.h:745
SourceLocation getLocation() const
Definition ExprCXX.h:751
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:924
Represents a call to a C++ constructor.
Definition ExprCXX.h:1553
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1734
void setIsImmediateEscalating(bool Set)
Definition ExprCXX.h:1715
bool isElidable() const
Whether this construction is elidable.
Definition ExprCXX.h:1622
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition ExprCXX.h:1627
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:1212
arg_range arguments()
Definition ExprCXX.h:1677
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1646
bool isImmediateEscalating() const
Definition ExprCXX.h:1711
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition ExprCXX.h:1655
SourceLocation getLocation() const
Definition ExprCXX.h:1618
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1616
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1635
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1693
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1664
Represents a C++ constructor within a class.
Definition DeclCXX.h:2642
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2977
Represents a C++ base or member initializer.
Definition DeclCXX.h:2407
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2547
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2507
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2609
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2606
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2517
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2605
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2512
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2541
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2485
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2479
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2491
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2567
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2561
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2533
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:2001
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2084
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1275
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition ExprCXX.h:1349
const ParmVarDecl * getParam() const
Definition ExprCXX.h:1317
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1345
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1071
bool hasRewrittenInit() const
Definition ExprCXX.h:1320
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1382
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:1125
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1439
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition ExprCXX.h:1427
bool hasRewrittenInit() const
Definition ExprCXX.h:1411
FieldDecl * getField()
Get the field whose initializer will be used.
Definition ExprCXX.h:1416
SourceLocation getBeginLoc() const
Definition ExprCXX.h:1446
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2631
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2670
bool isArrayForm() const
Definition ExprCXX.h:2657
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2681
bool isGlobalDelete() const
Definition ExprCXX.h:2656
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2666
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2658
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3924
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4023
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4026
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:1581
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:4078
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4070
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4057
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4097
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4066
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4086
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4062
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:4050
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4014
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:4037
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:4006
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4125
Represents a C++ destructor within a class.
Definition DeclCXX.h:2907
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:838
Helper that selects an expression from an InitListExpr depending on the current expansion index.
Definition ExprCXX.h:5622
InitListExpr * getRangeExpr()
Definition ExprCXX.h:5632
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:5086
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5108
Expr * getRHS() const
Definition ExprCXX.h:5112
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5128
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5130
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5133
Expr * getLHS() const
Definition ExprCXX.h:5111
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5129
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5131
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:950
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1756
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1797
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1793
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1809
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1807
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:184
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:724
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2150
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:2263
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:380
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:411
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:418
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:414
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2360
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:300
SourceRange getDirectInitRange() const
Definition ExprCXX.h:2614
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2577
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:2474
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2532
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2567
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2466
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2499
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2443
SourceRange getSourceRange() const
Definition ExprCXX.h:2615
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2521
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2561
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2464
bool isGlobalNew() const
Definition ExprCXX.h:2526
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2538
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4363
bool getValue() const
Definition ExprCXX.h:4386
SourceLocation getEndLoc() const
Definition ExprCXX.h:4383
Expr * getOperand() const
Definition ExprCXX.h:4380
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4382
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:773
SourceLocation getLocation() const
Definition ExprCXX.h:787
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:654
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5195
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Definition ExprCXX.cpp:2038
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5251
SourceLocation getInitLoc() const LLVM_READONLY
Definition ExprCXX.h:5253
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5235
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5249
MutableArrayRef< Expr * > getUserSpecifiedInitExprs()
Definition ExprCXX.h:5241
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2750
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2844
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2814
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2828
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2835
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2803
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2859
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2832
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2817
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:2851
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition DeclCXX.h:540
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:651
CXXRecordDecl * getDefinition() const
Definition DeclCXX.h:549
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:531
Represents a C++26 reflect expression [expr.reflect].
Definition ExprCXX.h:5562
SourceLocation getOperatorLoc() const
Returns location of the '^^'-operator.
Definition ExprCXX.h:5598
const TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:5601
static CXXReflectExpr * Create(ASTContext &C, SourceLocation OperatorLoc, const TypeSourceInfo *TSI)
Definition ExprCXX.cpp:1983
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:902
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:291
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:309
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition ExprCXX.h:327
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2201
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2220
SourceLocation getRParenLoc() const
Definition ExprCXX.h:2224
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:812
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:805
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1904
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:1178
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:1933
Represents a C++ temporary.
Definition ExprCXX.h:1464
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition ExprCXX.cpp:1145
Represents the this expression in C++.
Definition ExprCXX.h:1159
bool isImplicit() const
Definition ExprCXX.h:1182
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition ExprCXX.cpp:1616
SourceLocation getLocation() const
Definition ExprCXX.h:1176
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1213
const Expr * getSubExpr() const
Definition ExprCXX.h:1233
SourceLocation getThrowLoc() const
Definition ExprCXX.h:1236
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition ExprCXX.h:1243
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:853
bool isTypeOperand() const
Definition ExprCXX.h:889
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition ExprCXX.h:896
Expr * getExprOperand() const
Definition ExprCXX.h:900
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:907
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3798
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3842
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3853
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition ExprCXX.cpp:1520
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3836
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3847
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3856
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2987
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:1549
ADLCallKind getADLCallKind() const
Definition Expr.h:3138
Expr * getCallee()
Definition Expr.h:3134
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3286
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3178
arg_range arguments()
Definition Expr.h:3239
SourceLocation getRParenLoc() const
Definition Expr.h:3318
CaseStmt - Represent a case statement.
Definition Stmt.h:1932
Stmt * getSubStmt()
Definition Stmt.h:2045
Expr * getLHS()
Definition Stmt.h:2015
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:2001
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:1997
Expr * getRHS()
Definition Stmt.h:2027
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3720
path_iterator path_begin()
Definition Expr.h:3790
CastKind getCastKind() const
Definition Expr.h:3764
path_iterator path_end()
Definition Expr.h:3791
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3840
Expr * getSubExpr()
Definition Expr.h:3770
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1641
unsigned getValue() const
Definition Expr.h:1649
CharacterLiteralKind getKind() const
Definition Expr.h:1642
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:4892
SourceLocation getBuiltinLoc() const
Definition Expr.h:4939
Expr * getLHS() const
Definition Expr.h:4934
bool isConditionDependent() const
Definition Expr.h:4922
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4915
Expr * getRHS() const
Definition Expr.h:4936
SourceLocation getRParenLoc() const
Definition Expr.h:4942
Expr * getCond() const
Definition Expr.h:4932
Declaration of a class template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, llvm::FoldingSetInsertToken &InsertToken)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, llvm::FoldingSetInsertToken InsertToken)
Insert the specified specialization knowing that it is not already in.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, llvm::FoldingSetInsertToken InsertToken)
Insert the specified partial specialization knowing that it is not already in.
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:4344
QualType getComputationLHSType() const
Definition Expr.h:4378
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:5163
QualType getComputationResultType() const
Definition Expr.h:4381
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3649
SourceLocation getLParenLoc() const
Definition Expr.h:3684
bool isFileScope() const
Definition Expr.h:3681
const Expr * getInitializer() const
Definition Expr.h:3677
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3687
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1752
unsigned size() const
Definition Stmt.h:1797
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1802
body_range body()
Definition Stmt.h:1815
SourceLocation getLBracLoc() const
Definition Stmt.h:1869
bool hasStoredFPFeatures() const
Definition Stmt.h:1799
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:1870
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
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateName NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:203
TemplateName 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:4435
Expr * getLHS() const
Definition Expr.h:4469
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4458
Expr * getRHS() const
Definition Expr.h:4470
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1102
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:3707
ContinueStmt - This represents a continue.
Definition Stmt.h:3131
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4763
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4831
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4867
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:5728
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4864
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4856
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4853
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:2627
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2239
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:2226
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:2738
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:2423
bool isFunctionOrMethod() const
Returns true if this DeclContext is a function, Objective-C method, or block, or a DeclContext that c...
Definition DeclBase.h:2181
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:1290
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1401
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1445
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1494
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1417
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:498
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1425
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1383
ValueDecl * getDecl()
Definition Expr.h:1358
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1471
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1488
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1477
SourceLocation getLocation() const
Definition Expr.h:1366
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1433
bool isImmediateEscalating() const
Definition Expr.h:1498
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1643
SourceLocation getEndLoc() const
Definition Stmt.h:1666
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1661
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1669
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
Kind getKind() const
Definition DeclBase.h:450
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:823
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:832
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:856
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:815
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2016
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:846
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:810
A decomposition declaration.
Definition DeclCXX.h:4279
SourceLocation getDefaultLoc() const
Definition Stmt.h:2097
Stmt * getSubStmt()
Definition Stmt.h:2093
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3564
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition ExprCXX.cpp:574
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3638
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3612
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3630
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3672
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3648
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3622
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3603
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3600
A template-id naming a variable template or a concept through a template template parameter.
Definition ExprCXX.h:3480
static DependentTemplateIdExpr * Create(const ASTContext &Context, const DeclarationNameInfo &NameInfo, TemplateName Name, const TemplateArgumentListInfo &TemplateArgs)
Definition ExprCXX.cpp:423
const DeclarationNameInfo & getNameInfo() const
Definition ExprCXX.h:3504
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3525
SourceLocation getRAngleLoc() const
Definition ExprCXX.h:3521
DeclarationName getName() const
Definition ExprCXX.h:3505
TemplateName getTemplateName() const
Definition ExprCXX.h:3508
SourceLocation getNameLoc() const
Definition ExprCXX.h:3506
SourceLocation getLAngleLoc() const
Definition ExprCXX.h:3520
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:5644
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5771
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5725
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5761
SourceLocation getFieldLoc() const
Definition Expr.h:5752
SourceLocation getRBracketLoc() const
Definition Expr.h:5800
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4832
SourceLocation getEllipsisLoc() const
Definition Expr.h:5794
SourceLocation getDotLoc() const
Definition Expr.h:5747
SourceLocation getLBracketLoc() const
Definition Expr.h:5788
Represents a C99 designated initializer expression.
Definition Expr.h:5601
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5883
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5865
MutableArrayRef< Designator > designators()
Definition Expr.h:5834
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5869
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5831
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5856
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5881
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4873
A little helper class used to produce diagnostics.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2844
Stmt * getBody()
Definition Stmt.h:2869
Expr * getCond()
Definition Stmt.h:2862
SourceLocation getWhileLoc() const
Definition Stmt.h:2875
SourceLocation getDoLoc() const
Definition Stmt.h:2873
SourceLocation getRParenLoc() const
Definition Stmt.h:2877
Symbolic representation of a dynamic allocation.
Definition APValue.h:67
Represents an empty-declaration.
Definition Decl.h:5317
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3558
llvm::APSInt getInitVal() const
Definition Decl.h:3578
const Expr * getInitExpr() const
Definition Decl.h:3576
Represents an enum.
Definition Decl.h:4146
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4418
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4364
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4356
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4367
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4328
EnumDecl * getMostRecentDecl()
Definition Decl.h:4251
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4373
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5165
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4319
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5225
EnumDecl * getDefinition() const
Definition Decl.h:4258
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4345
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4311
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3972
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3994
Store information needed for an explicit specifier.
Definition DeclCXX.h:1949
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1957
const Expr * getExpr() const
Definition DeclCXX.h:1958
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3715
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3750
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3739
unsigned getNumObjects() const
Definition ExprCXX.h:3743
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3721
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition ExprCXX.cpp:1496
This represents one expression.
Definition Expr.h:113
void setType(QualType t)
Definition Expr.h:146
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:178
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:448
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:195
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:242
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:455
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:224
QualType getType() const
Definition Expr.h:145
ExprDependence getDependence() const
Definition Expr.h:165
An expression trait intrinsic.
Definition ExprCXX.h:3084
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3116
Expr * getQueriedExpression() const
Definition ExprCXX.h:3123
ExpressionTrait getTrait() const
Definition ExprCXX.h:3119
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3117
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:3295
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3395
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4790
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3475
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3469
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4800
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3411
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3519
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4900
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:57
SourceLocation getAsmLoc() const
Definition Decl.h:4748
const Expr * getAsmStringExpr() const
Definition Decl.h:4755
SourceLocation getRParenLoc() const
Definition Decl.h:4749
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1601
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1595
SourceLocation getLocation() const
Definition Expr.h:1727
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1086
llvm::APFloat getValue() const
Definition Expr.h:1686
bool isExact() const
Definition Expr.h:1719
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2900
Stmt * getInit()
Definition Stmt.h:2915
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getRParenLoc() const
Definition Stmt.h:2960
Stmt * getBody()
Definition Stmt.h:2944
Expr * getInc()
Definition Stmt.h:2943
SourceLocation getForLoc() const
Definition Stmt.h:2956
Expr * getCond()
Definition Stmt.h:2942
SourceLocation getLParenLoc() const
Definition Stmt.h:2958
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:46
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition DeclFriend.h:50
SourceLocation getFriendLoc() const
Definition DeclFriend.h:109
SourceLocation getEllipsisLoc() const
Retrieves the location of the '...', if present.
Definition DeclFriend.h:107
virtual NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:102
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:96
Declaration of a friend template.
TemplateName getFriendTemplateName() const
FriendTemplateEntityKind getFriendKind() const
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
const Expr * getSubExpr() const
Definition Expr.h:1082
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, FPOptionsOverride FPFeatures, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3126
Represents a function declaration or definition.
Definition Decl.h:2059
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3266
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2603
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3181
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4237
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4232
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3340
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3147
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2832
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3593
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:3040
SourceLocation getDefaultLoc() const
Definition Decl.h:2525
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2905
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2516
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2504
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2575
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4211
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4362
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2529
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2440
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4428
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2075
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2078
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:3019
void setTrivial(bool IT)
Definition Decl.h:2505
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2838
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4183
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4250
bool isDeletedAsWritten() const
Definition Decl.h:2671
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:4417
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2480
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:2476
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3597
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3601
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3605
void setRangeEnd(SourceLocation E)
Definition Decl.h:2332
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2512
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4256
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4456
void setDefaulted(bool D=true)
Definition Decl.h:2513
void setBody(Stmt *B)
Definition Decl.cpp:3278
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2471
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3156
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2521
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4204
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2325
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3186
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:3030
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5416
QualType desugar() const
Definition TypeBase.h:5997
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5705
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5870
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5856
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:4968
QualType getReturnType() const
Definition TypeBase.h:4952
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3458
unsigned getNumLabels() const
Definition Stmt.h:3608
labels_range labels()
Definition Stmt.h:3631
SourceLocation getRParenLoc() const
Definition Stmt.h:3480
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3573
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3560
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3586
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3549
const Expr * getAsmStringExpr() const
Definition Stmt.h:3485
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3665
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4967
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4984
Represents a C11 generic selection.
Definition Expr.h:6232
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6509
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6529
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6490
SourceLocation getGenericLoc() const
Definition Expr.h:6587
SourceLocation getRParenLoc() const
Definition Expr.h:6591
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6479
SourceLocation getDefaultLoc() const
Definition Expr.h:6590
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:4762
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6486
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6497
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6534
GotoStmt - This represents a direct goto.
Definition Stmt.h:2981
SourceLocation getLabelLoc() const
Definition Stmt.h:2999
SourceLocation getGotoLoc() const
Definition Stmt.h:2997
LabelDecl * getLabel() const
Definition Stmt.h:2994
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:2271
Stmt * getThen()
Definition Stmt.h:2360
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:2437
IfStatementKind getStatementKind() const
Definition Stmt.h:2472
SourceLocation getElseLoc() const
Definition Stmt.h:2440
Stmt * getInit()
Definition Stmt.h:2421
SourceLocation getLParenLoc() const
Definition Stmt.h:2489
Expr * getCond()
Definition Stmt.h:2348
Stmt * getElse()
Definition Stmt.h:2369
SourceLocation getRParenLoc() const
Definition Stmt.h:2491
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:1751
const Expr * getSubExpr() const
Definition Expr.h:1763
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3897
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2106
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1810
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6107
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5191
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3602
unsigned getChainingSize() const
Definition Decl.h:3627
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3623
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3020
SourceLocation getGotoLoc() const
Definition Stmt.h:3036
SourceLocation getStarLoc() const
Definition Stmt.h:3038
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2613
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2626
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2625
Describes an C or C++ initializer list.
Definition Expr.h:5352
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5465
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5526
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5479
unsigned getNumInits() const
Definition Expr.h:5385
SourceLocation getLBraceLoc() const
Definition Expr.h:5510
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2474
InitListExpr * getSyntacticForm() const
Definition Expr.h:5522
bool hadArrayRangeDesignator() const
Definition Expr.h:5533
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5455
bool isExplicit() const
Definition Expr.h:5495
SourceLocation getRBraceLoc() const
Definition Expr.h:5512
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5485
ArrayRef< Expr * > inits() const
Definition Expr.h:5405
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5536
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:985
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1556
Represents the declaration of a label.
Definition Decl.h:525
bool isGnuLocal() const
Definition Decl.h:552
LabelStmt * getStmt() const
Definition Decl.h:549
void setStmt(LabelStmt *T)
Definition Decl.h:550
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2158
LabelDecl * getDecl() const
Definition Stmt.h:2176
Stmt * getSubStmt()
Definition Stmt.h:2180
SourceLocation getIdentLoc() const
Definition Stmt.h:2173
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:1296
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:1973
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:1344
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2191
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition ExprCXX.h:2176
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition ExprCXX.h:2124
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2054
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition ExprCXX.cpp:1436
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition ExprCXX.h:2179
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition ExprCXX.h:2031
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2088
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition ExprCXX.h:2026
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1432
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition DeclCXX.h:3338
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3384
Represents a linkage specification.
Definition DeclCXX.h:3045
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3087
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3068
SourceLocation getExternLoc() const
Definition DeclCXX.h:3084
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3085
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3079
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:4974
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4991
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:5043
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:5014
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3408
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3580
SourceLocation getOperatorLoc() const
Definition Expr.h:3590
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3525
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3510
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3491
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3552
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3632
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:1783
Expr * getBase() const
Definition Expr.h:3485
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3541
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3533
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3585
bool isArrow() const
Definition Expr.h:3592
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3495
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:275
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1183
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:296
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:341
Represents a C++ namespace alias.
Definition DeclCXX.h:3231
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3292
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3314
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3317
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3320
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3301
Represent a C++ namespace.
Definition Decl.h:593
SourceLocation getRBraceLoc() const
Definition Decl.h:693
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:692
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:649
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:676
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:658
void setRBraceLoc(SourceLocation L)
Definition Decl.h:695
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:1715
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1729
SourceLocation getSemiLoc() const
Definition Stmt.h:1726
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:1675
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:3673
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:2571
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2630
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2604
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2618
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1687
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2611
unsigned getNumExpressions() const
Definition Expr.h:2642
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2608
unsigned getNumComponents() const
Definition Expr.h:2626
Helper class for OffsetOfExpr.
Definition Expr.h:2465
const IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1722
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2523
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2529
@ Array
An index into an array.
Definition Expr.h:2470
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2474
@ Field
A field.
Definition Expr.h:2472
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2477
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2551
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2519
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2552
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2539
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1198
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1248
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1220
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3295
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3277
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3250
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3256
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3269
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3265
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3242
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition ExprCXX.h:3325
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3253
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3285
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3320
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:4417
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4446
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4457
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4453
A structure for storing a pack-index-template-name ([temp.names]).
ArrayRef< TemplateName > getExpansions() const
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2226
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2251
const Expr * getSubExpr() const
Definition Expr.h:2243
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2255
ArrayRef< Expr * > exprs() const
Definition Expr.h:6177
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:5013
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6160
SourceLocation getLParenLoc() const
Definition Expr.h:6179
SourceLocation getRParenLoc() const
Definition Expr.h:6180
Represents a parameter to a function.
Definition Decl.h:1820
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1901
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1880
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1888
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3008
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1916
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1961
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1949
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3033
bool isObjCMethodParameter() const
Definition Decl.h:1863
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1884
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1853
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1953
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1848
bool hasInheritedDefaultArg() const
Definition Decl.h:1965
void setKNRPromoted(bool promoted)
Definition Decl.h:1904
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1912
Expr * getDefaultArg()
Definition Decl.cpp:2996
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3038
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3044
unsigned getFunctionScopeDepth() const
Definition Decl.h:1870
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1969
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2049
SourceLocation getBeginLoc() const
Definition Expr.h:2114
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:643
bool isTransparent() const
Definition Expr.h:2088
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2084
StringLiteral * getFunctionName()
Definition Expr.h:2093
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2699
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6854
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6896
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5235
ArrayRef< Expr * > semantics()
Definition Expr.h:6926
unsigned getNumSemanticExprs() const
Definition Expr.h:6911
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6891
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:8446
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8478
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:4460
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5317
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4516
field_range fields() const
Definition Decl.h:4663
RecordDecl * getMostRecentDecl()
Definition Decl.h:4486
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5362
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4644
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4512
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:5468
Represents the body of a requires-expression.
Definition DeclCXX.h:2119
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:3172
SourceLocation getReturnLoc() const
Definition Stmt.h:3221
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3208
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:3199
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:4687
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4723
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4720
SourceLocation getRParenLoc() const
Definition Expr.h:4707
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4710
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4495
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4557
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4580
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1739
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4585
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4554
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4560
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4563
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4569
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5070
SourceLocation getBeginLoc() const
Definition Expr.h:5115
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5111
SourceLocation getEndLoc() const
Definition Expr.h:5116
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5090
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:4166
bool isFailed() const
Definition DeclCXX.h:4195
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4197
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4639
CompoundStmt * getSubStmt()
Definition Expr.h:4656
unsigned getTemplateDepth() const
Definition Expr.h:4668
SourceLocation getRParenLoc() const
Definition Expr.h:4665
SourceLocation getLParenLoc() const
Definition Expr.h:4663
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:1505
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:1819
bool isPascal() const
Definition Expr.h:1958
tokloc_iterator tokloc_begin() const
Definition Expr.h:2009
tokloc_iterator tokloc_end() const
Definition Expr.h:2013
StringLiteralKind getKind() const
Definition Expr.h:1948
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:1198
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1895
unsigned getNumConcatenated() const
Get the number of string literal tokens that were concatenated in translation phase #6 to form this s...
Definition Expr.h:1985
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4718
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4763
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4771
QualType getParameterType() const
Determine the substituted type of the template parameter.
Definition ExprCXX.h:4782
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4769
SourceLocation getNameLoc() const
Definition ExprCXX.h:4753
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4808
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition ExprCXX.cpp:1815
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
Definition ExprCXX.h:4856
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4842
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4846
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:1907
SourceLocation getColonLoc() const
Definition Stmt.h:1911
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1905
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2521
SourceLocation getSwitchLoc() const
Definition Stmt.h:2656
SourceLocation getLParenLoc() const
Definition Stmt.h:2658
SourceLocation getRParenLoc() const
Definition Stmt.h:2660
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:2584
Stmt * getBody()
Definition Stmt.h:2596
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2601
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2652
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3852
SourceRange getBraceRange() const
Definition Decl.h:3929
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3973
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:5000
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3948
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3953
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4106
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:4089
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4977
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4972
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:5014
TagKind getTagKind() const
Definition Decl.h:4052
void setBraceRange(SourceRange R)
Definition Decl.h:3930
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3956
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.
bool isNull() const
Determine whether this template name is NULL.
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.
@ PackIndexingTemplate
A pack-index-template-name.
@ 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.
PackIndexingTemplateStorage * getAsPackIndexingTemplate() const
Retrieve the pack-index-template-name storage, if any.
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:106
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3823
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3841
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:3682
Symbolic representation of typeid(T) for some type T.
Definition APValue.h:46
const Type * getType() const
Definition APValue.h:53
SourceLocation getBeginLoc() const
Get the begin source location.
Definition TypeLoc.cpp:193
A container of type source information.
Definition TypeBase.h:8417
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:8428
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2901
bool getBoolValue() const
Definition ExprCXX.h:2962
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2982
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:1937
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2987
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2973
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2950
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2986
const APValue & getAPValue() const
Definition ExprCXX.h:2967
bool isStoredAsBoolean() const
Definition ExprCXX.h:2954
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:8782
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:883
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9252
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2653
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:9299
bool isRecordType() const
Definition TypeBase.h:8810
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3802
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3697
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3747
QualType getUnderlyingType() const
Definition Decl.h:3752
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2669
SourceLocation getRParenLoc() const
Definition Expr.h:2745
SourceLocation getOperatorLoc() const
Definition Expr.h:2742
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2715
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2701
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2288
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2333
Expr * getSubExpr() const
Definition Expr.h:2329
Opcode getOpcode() const
Definition Expr.h:2324
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2425
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2428
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5177
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2342
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3373
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3447
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3442
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:464
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4180
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4272
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4275
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4266
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4253
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:1682
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:1675
void addDecl(NamedDecl *D)
A set of unresolved declarations.
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4067
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4097
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4101
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4094
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4118
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3970
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4001
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4011
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:4018
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4028
Represents a C++ using-declaration.
Definition DeclCXX.h:3621
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3670
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3655
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3662
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3648
Represents C++ using-directive.
Definition DeclCXX.h:3126
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3197
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:3193
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3201
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3204
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3171
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3822
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3846
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3858
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3842
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3903
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3932
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3936
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3429
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3493
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:5001
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:5034
SourceLocation getBuiltinLoc() const
Definition Expr.h:5037
SourceLocation getRParenLoc() const
Definition Expr.h:5040
VarArgKind getVarargABI() const
Definition Expr.h:5025
const Expr * getSubExpr() const
Definition Expr.h:5021
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:713
void setType(QualType newType)
Definition Decl.h:725
QualType getType() const
Definition Decl.h:724
Represents a variable declaration or definition.
Definition Decl.h:933
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2780
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1594
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2905
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:2240
bool isInlineSpecified() const
Definition Decl.h:1579
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2346
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2551
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2537
void setInlineSpecified()
Definition Decl.h:1583
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2742
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1366
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1180
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1576
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1184
const Expr * getInit() const
Definition Decl.h:1392
void setConstexpr(bool IC)
Definition Decl.h:1597
void setInit(Expr *I)
Definition Decl.cpp:2457
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2785
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1175
void setImplicitlyInline()
Definition Decl.h:1588
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:1382
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2868
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:2709
Expr * getCond()
Definition Stmt.h:2761
SourceLocation getWhileLoc() const
Definition Stmt.h:2814
SourceLocation getRParenLoc() const
Definition Stmt.h:2819
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition Stmt.cpp:1247
SourceLocation getLParenLoc() const
Definition Stmt.h:2817
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:2773
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:153
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:579
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:136
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:192
U cast(CodeGen::Address addr)
Definition Address.h:327
llvm::Expected< Stmt * > ExpectedStmt
static void updateFlags(const Decl *From, Decl *To)
int32_t 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:89
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:886
unsigned HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:900
unsigned HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:908
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5485
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5489
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5475
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5478
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5481
Extra information about a function prototype.
Definition TypeBase.h:5501
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