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