clang 24.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 if (auto *VD = dyn_cast<VarDecl>(D))
125 if (auto *TD = dyn_cast<TagDecl>(D))
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 Expected<FriendDecl::FriendUnion> importFriendUnion(FriendDecl *D);
189
190 // Use this to import pointers of specific type.
191 template <typename ImportT>
192 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
193 auto ToOrErr = Importer.Import(From);
194 if (ToOrErr)
195 To = cast_or_null<ImportT>(*ToOrErr);
196 return ToOrErr.takeError();
197 }
198
199 // Call the import function of ASTImporter for a baseclass of type `T` and
200 // cast the return value to `T`.
201 template <typename T>
202 auto import(T *From)
203 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
205 auto ToOrErr = Importer.Import(From);
206 if (!ToOrErr)
207 return ToOrErr.takeError();
208 return cast_or_null<T>(*ToOrErr);
209 }
210
211 template <typename T>
212 auto import(const T *From) {
213 return import(const_cast<T *>(From));
214 }
215
216 // Call the import function of ASTImporter for type `T`.
217 template <typename T>
218 Expected<T> import(const T &From) {
219 return Importer.Import(From);
220 }
221
222 // Import an std::optional<T> by importing the contained T, if any.
223 template <typename T>
224 Expected<std::optional<T>> import(std::optional<T> From) {
225 if (!From)
226 return std::nullopt;
227 return import(*From);
228 }
229
230 ExplicitSpecifier importExplicitSpecifier(Error &Err,
231 ExplicitSpecifier ESpec);
232
233 // Wrapper for an overload set.
234 template <typename ToDeclT> struct CallOverloadedCreateFun {
235 template <typename... Args> decltype(auto) operator()(Args &&... args) {
236 return ToDeclT::Create(std::forward<Args>(args)...);
237 }
238 };
239
240 // Always use these functions to create a Decl during import. There are
241 // certain tasks which must be done after the Decl was created, e.g. we
242 // must immediately register that as an imported Decl. The parameter `ToD`
243 // will be set to the newly created Decl or if had been imported before
244 // then to the already imported Decl. Returns a bool value set to true if
245 // the `FromD` had been imported before.
246 template <typename ToDeclT, typename FromDeclT, typename... Args>
247 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
248 Args &&...args) {
249 // There may be several overloads of ToDeclT::Create. We must make sure
250 // to call the one which would be chosen by the arguments, thus we use a
251 // wrapper for the overload set.
252 CallOverloadedCreateFun<ToDeclT> OC;
253 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
254 std::forward<Args>(args)...);
255 }
256 // Use this overload if a special Type is needed to be created. E.g if we
257 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
258 // then:
259 // TypedefNameDecl *ToTypedef;
260 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
261 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
262 typename... Args>
263 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
264 Args &&...args) {
265 CallOverloadedCreateFun<NewDeclT> OC;
266 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
267 std::forward<Args>(args)...);
268 }
269 // Use this version if a special create function must be
270 // used, e.g. CXXRecordDecl::CreateLambda .
271 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
272 typename... Args>
273 [[nodiscard]] bool
274 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
275 FromDeclT *FromD, Args &&...args) {
276 if (Importer.getImportDeclErrorIfAny(FromD)) {
277 ToD = nullptr;
278 return true; // Already imported but with error.
279 }
280 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
281 if (ToD)
282 return true; // Already imported.
283 ToD = CreateFun(std::forward<Args>(args)...);
284 // Keep track of imported Decls.
285 Importer.RegisterImportedDecl(FromD, ToD);
286 Importer.SharedState->markAsNewDecl(ToD);
287 InitializeImportedDecl(FromD, ToD);
288 return false; // A new Decl is created.
289 }
290
291 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
292 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
293 if (FromD->isUsed())
294 ToD->setIsUsed();
295 if (FromD->isImplicit())
296 ToD->setImplicit();
297 }
298
299 // Check if we have found an existing definition. Returns with that
300 // definition if yes, otherwise returns null.
301 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
302 const FunctionDecl *Definition = nullptr;
303 if (D->doesThisDeclarationHaveABody() &&
304 FoundFunction->hasBody(Definition))
305 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
306 return nullptr;
307 }
308
309 void addDeclToContexts(Decl *FromD, Decl *ToD) {
310 if (Importer.isMinimalImport()) {
311 // In minimal import case the decl must be added even if it is not
312 // contained in original context, for LLDB compatibility.
313 // FIXME: Check if a better solution is possible.
314 if (!FromD->getDescribedTemplate() &&
315 FromD->getFriendObjectKind() == Decl::FOK_None)
317 return;
318 }
319
320 DeclContext *FromDC = FromD->getDeclContext();
321 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
322 DeclContext *ToDC = ToD->getDeclContext();
323 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
324
325 bool Visible = false;
326 if (FromDC->containsDeclAndLoad(FromD)) {
327 ToDC->addDeclInternal(ToD);
328 Visible = true;
329 }
330 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
331 ToLexicalDC->addDeclInternal(ToD);
332 Visible = true;
333 }
334
335 // If the Decl was added to any context, it was made already visible.
336 // Otherwise it is still possible that it should be visible.
337 if (!Visible) {
338 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
339 auto *ToNamed = cast<NamedDecl>(ToD);
340 DeclContextLookupResult FromLookup =
341 FromDC->lookup(FromNamed->getDeclName());
342 if (llvm::is_contained(FromLookup, FromNamed))
343 ToDC->makeDeclVisibleInContext(ToNamed);
344 }
345 }
346 }
347
348 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
349 DeclContext *OldDC) {
350 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
351 if (!LT)
352 return;
353
354 for (NamedDecl *TP : Params)
355 LT->update(TP, OldDC);
356 }
357
358 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
359 updateLookupTableForTemplateParameters(
360 Params, Importer.getToContext().getTranslationUnitDecl());
361 }
362
363 template <typename TemplateParmDeclT>
364 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
365 TemplateParmDeclT *ToD) {
366 if (D->hasDefaultArgument()) {
367 if (D->defaultArgumentWasInherited()) {
368 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
369 import(D->getDefaultArgStorage().getInheritedFrom());
370 if (!ToInheritedFromOrErr)
371 return ToInheritedFromOrErr.takeError();
372 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
373 if (!ToInheritedFrom->hasDefaultArgument()) {
374 // Resolve possible circular dependency between default value of the
375 // template argument and the template declaration.
376 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
377 import(D->getDefaultArgStorage()
378 .getInheritedFrom()
379 ->getDefaultArgument());
380 if (!ToInheritedDefaultArgOrErr)
381 return ToInheritedDefaultArgOrErr.takeError();
382 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
383 *ToInheritedDefaultArgOrErr);
384 }
385 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
386 ToInheritedFrom);
387 } else {
388 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
389 import(D->getDefaultArgument());
390 if (!ToDefaultArgOrErr)
391 return ToDefaultArgOrErr.takeError();
392 // Default argument could have been set in the
393 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
394 if (!ToD->hasDefaultArgument())
395 ToD->setDefaultArgument(Importer.getToContext(),
396 *ToDefaultArgOrErr);
397 }
398 }
399 return Error::success();
400 }
401
402 public:
403 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
404
408
409 // Importing types
411#define TYPE(Class, Base) \
412 ExpectedType Visit##Class##Type(const Class##Type *T);
413#include "clang/AST/TypeNodes.inc"
414
415 // Importing declarations
417 SourceLocation &Loc);
419 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
420 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
421 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
424 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
426 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
428
429 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
431 Expected<APValue> ImportAPValue(const APValue &FromValue);
432
434
435 /// What we should import from the definition.
437 /// Import the default subset of the definition, which might be
438 /// nothing (if minimal import is set) or might be everything (if minimal
439 /// import is not set).
441 /// Import everything.
443 /// Import only the bare bones needed to establish a valid
444 /// DeclContext.
446 };
447
449 return IDK == IDK_Everything ||
450 (IDK == IDK_Default && !Importer.isMinimalImport());
451 }
452
455 RecordDecl *From, RecordDecl *To,
458 EnumDecl *From, EnumDecl *To,
470
471 template <typename InContainerTy>
473 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
474
475 template<typename InContainerTy>
477 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
478 const InContainerTy &Container, TemplateArgumentListInfo &Result);
479
482 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
485 FunctionDecl *FromFD);
486
487 template <typename DeclTy>
488 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
489
491
493
495 ParmVarDecl *ToParam);
496
499
500 // Use for allocating string for newly imported object.
501 StringRef ImportASTStringRef(StringRef FromStr);
510
511 template <typename T>
513
514 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
515 bool IgnoreTemplateParmDepth = false);
565
568
587
588 // Importing statements
608 // FIXME: MSAsmStmt
609 // FIXME: SEHExceptStmt
610 // FIXME: SEHFinallyStmt
611 // FIXME: SEHTryStmt
612 // FIXME: SEHLeaveStmt
613 // FIXME: CapturedStmt
620 // FIXME: MSDependentExistsStmt
628
629 // Importing expressions
714
715 // Helper for chaining together multiple imports. If an error is detected,
716 // subsequent imports will return default constructed nodes, so that failure
717 // can be detected with a single conditional branch after a sequence of
718 // imports.
719 template <typename T> T importChecked(Error &Err, const T &From) {
720 // Don't attempt to import nodes if we hit an error earlier.
721 if (Err)
722 return T{};
723 Expected<T> MaybeVal = import(From);
724 if (!MaybeVal) {
725 Err = MaybeVal.takeError();
726 return T{};
727 }
728 return *MaybeVal;
729 }
730
731 template<typename IIter, typename OIter>
732 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
733 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
734 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
735 Expected<ItemT> ToOrErr = import(*Ibegin);
736 if (!ToOrErr)
737 return ToOrErr.takeError();
738 *Obegin = *ToOrErr;
739 }
740 return Error::success();
741 }
742
743 // Import every item from a container structure into an output container.
744 // If error occurs, stops at first error and returns the error.
745 // The output container should have space for all needed elements (it is not
746 // expanded, new items are put into from the beginning).
747 template<typename InContainerTy, typename OutContainerTy>
749 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
750 return ImportArrayChecked(
751 InContainer.begin(), InContainer.end(), OutContainer.begin());
752 }
753
754 template<typename InContainerTy, typename OIter>
755 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
756 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
757 }
758
760 CXXMethodDecl *FromMethod);
761
764 };
765
766template <typename InContainerTy>
768 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
769 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
770 auto ToLAngleLocOrErr = import(FromLAngleLoc);
771 if (!ToLAngleLocOrErr)
772 return ToLAngleLocOrErr.takeError();
773 auto ToRAngleLocOrErr = import(FromRAngleLoc);
774 if (!ToRAngleLocOrErr)
775 return ToRAngleLocOrErr.takeError();
776
777 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
778 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
779 return Err;
780 Result = std::move(ToTAInfo);
781 return Error::success();
782}
783
784template <>
790
791template <>
799
802 FunctionDecl *FromFD) {
803 assert(FromFD->getTemplatedKind() ==
805
807
808 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
809 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
810 return std::move(Err);
811
812 // Import template arguments.
813 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
814 std::get<1>(Result)))
815 return std::move(Err);
816
817 return Result;
818}
819
820template <>
822ASTNodeImporter::import(TemplateParameterList *From) {
824 if (Error Err = ImportContainerChecked(*From, To))
825 return std::move(Err);
826
827 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
828 if (!ToRequiresClause)
829 return ToRequiresClause.takeError();
830
831 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
832 if (!ToTemplateLocOrErr)
833 return ToTemplateLocOrErr.takeError();
834 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
835 if (!ToLAngleLocOrErr)
836 return ToLAngleLocOrErr.takeError();
837 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
838 if (!ToRAngleLocOrErr)
839 return ToRAngleLocOrErr.takeError();
840
842 Importer.getToContext(),
843 *ToTemplateLocOrErr,
844 *ToLAngleLocOrErr,
845 To,
846 *ToRAngleLocOrErr,
847 *ToRequiresClause);
848}
849
850template <>
852ASTNodeImporter::import(const TemplateArgument &From) {
853 switch (From.getKind()) {
855 return TemplateArgument();
856
858 ExpectedType ToTypeOrErr = import(From.getAsType());
859 if (!ToTypeOrErr)
860 return ToTypeOrErr.takeError();
861 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
862 From.getIsDefaulted());
863 }
864
866 ExpectedType ToTypeOrErr = import(From.getIntegralType());
867 if (!ToTypeOrErr)
868 return ToTypeOrErr.takeError();
869 return TemplateArgument(From, *ToTypeOrErr);
870 }
871
873 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
874 if (!ToOrErr)
875 return ToOrErr.takeError();
876 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
877 if (!ToTypeOrErr)
878 return ToTypeOrErr.takeError();
879 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
880 *ToTypeOrErr, From.getIsDefaulted());
881 }
882
884 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
885 if (!ToTypeOrErr)
886 return ToTypeOrErr.takeError();
887 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
888 From.getIsDefaulted());
889 }
890
892 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
893 if (!ToTypeOrErr)
894 return ToTypeOrErr.takeError();
895 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
896 if (!ToValueOrErr)
897 return ToValueOrErr.takeError();
898 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
899 *ToValueOrErr);
900 }
901
903 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
904 if (!ToTemplateOrErr)
905 return ToTemplateOrErr.takeError();
906
907 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
908 }
909
911 Expected<TemplateName> ToTemplateOrErr =
912 import(From.getAsTemplateOrTemplatePattern());
913 if (!ToTemplateOrErr)
914 return ToTemplateOrErr.takeError();
915
916 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
917 From.getIsDefaulted());
918 }
919
921 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
922 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
923 From.getIsDefaulted());
924 else
925 return ToExpr.takeError();
926
929 ToPack.reserve(From.pack_size());
930 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
931 return std::move(Err);
932
933 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
934 }
935 }
936
937 llvm_unreachable("Invalid template argument kind");
938}
939
940template <>
942ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
943 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
944 if (!ArgOrErr)
945 return ArgOrErr.takeError();
946 TemplateArgument Arg = *ArgOrErr;
947
948 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
949
952 ExpectedExpr E = import(FromInfo.getAsExpr());
953 if (!E)
954 return E.takeError();
955 ToInfo = TemplateArgumentLocInfo(*E);
956 } else if (Arg.getKind() == TemplateArgument::Type) {
957 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
958 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
959 else
960 return TSIOrErr.takeError();
961 } else {
962 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
963 if (!ToTemplateKWLocOrErr)
964 return ToTemplateKWLocOrErr.takeError();
965 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
966 if (!ToTemplateQualifierLocOrErr)
967 return ToTemplateQualifierLocOrErr.takeError();
968 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
969 if (!ToTemplateNameLocOrErr)
970 return ToTemplateNameLocOrErr.takeError();
971 auto ToTemplateEllipsisLocOrErr =
972 import(FromInfo.getTemplateEllipsisLoc());
973 if (!ToTemplateEllipsisLocOrErr)
974 return ToTemplateEllipsisLocOrErr.takeError();
976 Importer.getToContext(), *ToTemplateKWLocOrErr,
977 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
978 *ToTemplateEllipsisLocOrErr);
979 }
980
981 return TemplateArgumentLoc(Arg, ToInfo);
982}
983
984template <>
985Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
986 if (DG.isNull())
987 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
988 size_t NumDecls = DG.end() - DG.begin();
990 ToDecls.reserve(NumDecls);
991 for (Decl *FromD : DG) {
992 if (auto ToDOrErr = import(FromD))
993 ToDecls.push_back(*ToDOrErr);
994 else
995 return ToDOrErr.takeError();
996 }
997 return DeclGroupRef::Create(Importer.getToContext(),
998 ToDecls.begin(),
999 NumDecls);
1000}
1001
1002template <>
1004ASTNodeImporter::import(const Designator &D) {
1005 if (D.isFieldDesignator()) {
1006 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
1007
1008 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
1009 if (!ToDotLocOrErr)
1010 return ToDotLocOrErr.takeError();
1011
1012 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1013 if (!ToFieldLocOrErr)
1014 return ToFieldLocOrErr.takeError();
1015
1017 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1018 }
1019
1020 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1021 if (!ToLBracketLocOrErr)
1022 return ToLBracketLocOrErr.takeError();
1023
1024 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1025 if (!ToRBracketLocOrErr)
1026 return ToRBracketLocOrErr.takeError();
1027
1028 if (D.isArrayDesignator())
1030 *ToLBracketLocOrErr,
1031 *ToRBracketLocOrErr);
1032
1033 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1034 if (!ToEllipsisLocOrErr)
1035 return ToEllipsisLocOrErr.takeError();
1036
1037 assert(D.isArrayRangeDesignator());
1039 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1040 *ToRBracketLocOrErr);
1041}
1042
1043template <>
1044Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1045 Error Err = Error::success();
1046 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1047 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1048 auto ToConceptNameLoc =
1049 importChecked(Err, From->getConceptNameInfo().getLoc());
1050 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1051 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1052 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1053 if (Err)
1054 return std::move(Err);
1055 TemplateArgumentListInfo ToTAInfo;
1056 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1057 if (ASTTemplateArgs)
1058 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1059 return std::move(Err);
1060 auto *ConceptRef = ConceptReference::Create(
1061 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1062 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1063 ToNamedConcept,
1064 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1065 Importer.getToContext(), ToTAInfo)
1066 : nullptr);
1067 return ConceptRef;
1068}
1069
1070StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1071 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1072 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1073 return StringRef(ToStore, FromStr.size());
1074}
1075
1077 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1078 ToSat.IsSatisfied = FromSat.IsSatisfied;
1079 ToSat.ContainsErrors = FromSat.ContainsErrors;
1080 if (!ToSat.IsSatisfied) {
1081 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1082 if (const Expr *E = Record->dyn_cast<const Expr *>()) {
1083 ExpectedExpr ToSecondExpr = import(E);
1084 if (!ToSecondExpr)
1085 return ToSecondExpr.takeError();
1086 ToSat.Details.emplace_back(ToSecondExpr.get());
1087 } else if (auto CR = Record->dyn_cast<const ConceptReference *>()) {
1088 Expected<ConceptReference *> ToCROrErr = import(CR);
1089 if (!ToCROrErr)
1090 return ToCROrErr.takeError();
1091 ToSat.Details.emplace_back(ToCROrErr.get());
1092 } else {
1093 auto Pair =
1094 Record->dyn_cast<const ConstraintSubstitutionDiagnostic *>();
1095
1096 ExpectedSLoc ToPairFirst = import(Pair->first);
1097 if (!ToPairFirst)
1098 return ToPairFirst.takeError();
1099 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1100 ToSat.Details.emplace_back(new (Importer.getToContext())
1102 ToPairFirst.get(), ToPairSecond});
1103 }
1104 }
1105 }
1106 return Error::success();
1107}
1108
1109template <>
1111ASTNodeImporter::import(
1113 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1114 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1115 if (!ToLoc)
1116 return ToLoc.takeError();
1117 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1118 return new (Importer.getToContext())
1120 ToDiagMessage};
1121}
1122
1125 using namespace concepts;
1126
1127 if (From->isSubstitutionFailure()) {
1128 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1129 if (!DiagOrErr)
1130 return DiagOrErr.takeError();
1131 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1132 } else {
1133 Expected<TypeSourceInfo *> ToType = import(From->getType());
1134 if (!ToType)
1135 return ToType.takeError();
1136 return new (Importer.getToContext()) TypeRequirement(*ToType);
1137 }
1138}
1139
1142 using namespace concepts;
1143
1144 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1145 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1146
1147 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1148 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1149
1150 if (IsRKSimple) {
1151 Req.emplace();
1152 } else {
1153 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1155
1156 if (FromTypeRequirement.isTypeConstraint()) {
1157 const bool IsDependent = FromTypeRequirement.isDependent();
1158 auto ParamsOrErr =
1159 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1160 if (!ParamsOrErr)
1161 return ParamsOrErr.takeError();
1162 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1163 auto SubstConstraintExprOrErr =
1165 if (!SubstConstraintExprOrErr)
1166 return SubstConstraintExprOrErr.takeError();
1167 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1168 }
1169 Req.emplace(ParamsOrErr.get(), IsDependent);
1170 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1171 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1172 if (!DiagOrErr)
1173 return DiagOrErr.takeError();
1174 Req.emplace(DiagOrErr.get());
1175 } else {
1176 Req.emplace();
1177 }
1178 }
1179
1180 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1181 if (!NoexceptLocOrErr)
1182 return NoexceptLocOrErr.takeError();
1183
1184 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1185 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1186 if (!DiagOrErr)
1187 return DiagOrErr.takeError();
1188 return new (Importer.getToContext()) ExprRequirement(
1189 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1190 } else {
1191 Expected<Expr *> ExprOrErr = import(From->getExpr());
1192 if (!ExprOrErr)
1193 return ExprOrErr.takeError();
1194 return new (Importer.getToContext()) concepts::ExprRequirement(
1195 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1196 SubstitutedConstraintExpr);
1197 }
1198}
1199
1202 using namespace concepts;
1203
1204 const ASTConstraintSatisfaction &FromSatisfaction =
1206 if (From->hasInvalidConstraint()) {
1207 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1208 ASTConstraintSatisfaction *ToSatisfaction =
1209 ASTConstraintSatisfaction::Rebuild(Importer.getToContext(),
1210 FromSatisfaction);
1211 return new (Importer.getToContext())
1212 NestedRequirement(ToEntity, ToSatisfaction);
1213 } else {
1214 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1215 if (!ToExpr)
1216 return ToExpr.takeError();
1217 if (ToExpr.get()->isInstantiationDependent()) {
1218 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1219 } else {
1220 ConstraintSatisfaction Satisfaction;
1221 if (Error Err =
1222 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1223 return std::move(Err);
1224 return new (Importer.getToContext()) NestedRequirement(
1225 Importer.getToContext(), ToExpr.get(), Satisfaction);
1226 }
1227 }
1228}
1229
1230template <>
1232ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1233 switch (FromRequire->getKind()) {
1242 }
1243 llvm_unreachable("Unhandled requirement kind");
1244}
1245
1246template <>
1247Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1248 ValueDecl *Var = nullptr;
1249 if (From.capturesVariable()) {
1250 if (auto VarOrErr = import(From.getCapturedVar()))
1251 Var = *VarOrErr;
1252 else
1253 return VarOrErr.takeError();
1254 }
1255
1256 auto LocationOrErr = import(From.getLocation());
1257 if (!LocationOrErr)
1258 return LocationOrErr.takeError();
1259
1260 SourceLocation EllipsisLoc;
1261 if (From.isPackExpansion())
1262 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1263 return std::move(Err);
1264
1265 return LambdaCapture(
1266 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1267 EllipsisLoc);
1268}
1269
1270template <typename T>
1272 if (Found->getLinkageInternal() != From->getLinkageInternal())
1273 return false;
1274
1275 if (From->hasExternalFormalLinkage())
1276 return Found->hasExternalFormalLinkage();
1277 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1278 return false;
1279 if (From->isInAnonymousNamespace())
1280 return Found->isInAnonymousNamespace();
1281 else
1282 return !Found->isInAnonymousNamespace() &&
1283 !Found->hasExternalFormalLinkage();
1284}
1285
1286template <>
1288 TypedefNameDecl *From) {
1289 if (Found->getLinkageInternal() != From->getLinkageInternal())
1290 return false;
1291
1292 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1293 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1294 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1295}
1296
1297} // namespace clang
1298
1299//----------------------------------------------------------------------------
1300// Import Types
1301//----------------------------------------------------------------------------
1302
1303using namespace clang;
1304
1306 const FunctionDecl *D) {
1307 const FunctionDecl *LambdaD = nullptr;
1308 if (!isCycle(D) && D) {
1309 FunctionDeclsWithImportInProgress.insert(D);
1310 LambdaD = D;
1311 }
1312 return llvm::scope_exit([this, LambdaD]() {
1313 if (LambdaD) {
1314 FunctionDeclsWithImportInProgress.erase(LambdaD);
1315 }
1316 });
1317}
1318
1320 const FunctionDecl *D) const {
1321 return FunctionDeclsWithImportInProgress.find(D) !=
1322 FunctionDeclsWithImportInProgress.end();
1323}
1324
1326 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1327 << T->getTypeClassName();
1328 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1329}
1330
1331ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1332 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1333 if (!UnderlyingTypeOrErr)
1334 return UnderlyingTypeOrErr.takeError();
1335
1336 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1337}
1338
1339ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1340 switch (T->getKind()) {
1341#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1342 case BuiltinType::Id: \
1343 return Importer.getToContext().SingletonId;
1344#include "clang/Basic/OpenCLImageTypes.def"
1345#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1346 case BuiltinType::Id: \
1347 return Importer.getToContext().Id##Ty;
1348#include "clang/Basic/OpenCLExtensionTypes.def"
1349#define SVE_TYPE(Name, Id, SingletonId) \
1350 case BuiltinType::Id: \
1351 return Importer.getToContext().SingletonId;
1352#include "clang/Basic/AArch64ACLETypes.def"
1353#define PPC_VECTOR_TYPE(Name, Id, Size) \
1354 case BuiltinType::Id: \
1355 return Importer.getToContext().Id##Ty;
1356#include "clang/Basic/PPCTypes.def"
1357#define RVV_TYPE(Name, Id, SingletonId) \
1358 case BuiltinType::Id: \
1359 return Importer.getToContext().SingletonId;
1360#include "clang/Basic/RISCVVTypes.def"
1361#define WASM_TYPE(Name, Id, SingletonId) \
1362 case BuiltinType::Id: \
1363 return Importer.getToContext().SingletonId;
1364#include "clang/Basic/WebAssemblyReferenceTypes.def"
1365#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1366 case BuiltinType::Id: \
1367 return Importer.getToContext().SingletonId;
1368#include "clang/Basic/AMDGPUTypes.def"
1369#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1370 case BuiltinType::Id: \
1371 return Importer.getToContext().SingletonId;
1372#include "clang/Basic/HLSLIntangibleTypes.def"
1373#define SPIRV_TYPE(Name, Id, SingletonId) \
1374 case BuiltinType::Id: \
1375 return Importer.getToContext().SingletonId;
1376#include "clang/Basic/SPIRVTypes.def"
1377#define SHARED_SINGLETON_TYPE(Expansion)
1378#define BUILTIN_TYPE(Id, SingletonId) \
1379 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1380#include "clang/AST/BuiltinTypes.def"
1381
1382 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1383 // context supports C++.
1384
1385 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1386 // context supports ObjC.
1387
1388 case BuiltinType::Char_U:
1389 // The context we're importing from has an unsigned 'char'. If we're
1390 // importing into a context with a signed 'char', translate to
1391 // 'unsigned char' instead.
1392 if (Importer.getToContext().getLangOpts().CharIsSigned)
1393 return Importer.getToContext().UnsignedCharTy;
1394
1395 return Importer.getToContext().CharTy;
1396
1397 case BuiltinType::Char_S:
1398 // The context we're importing from has an unsigned 'char'. If we're
1399 // importing into a context with a signed 'char', translate to
1400 // 'unsigned char' instead.
1401 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1402 return Importer.getToContext().SignedCharTy;
1403
1404 return Importer.getToContext().CharTy;
1405
1406 case BuiltinType::WChar_S:
1407 case BuiltinType::WChar_U:
1408 // FIXME: If not in C++, shall we translate to the C equivalent of
1409 // wchar_t?
1410 return Importer.getToContext().WCharTy;
1411 }
1412
1413 llvm_unreachable("Invalid BuiltinType Kind!");
1414}
1415
1416ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1417 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1418 if (!ToOriginalTypeOrErr)
1419 return ToOriginalTypeOrErr.takeError();
1420
1421 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1422}
1423
1424ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1425 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1426 if (!ToElementTypeOrErr)
1427 return ToElementTypeOrErr.takeError();
1428
1429 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1430}
1431
1432ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1433 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1434 if (!ToPointeeTypeOrErr)
1435 return ToPointeeTypeOrErr.takeError();
1436
1437 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1438}
1439
1440ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1441 // FIXME: Check for blocks support in "to" context.
1442 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1443 if (!ToPointeeTypeOrErr)
1444 return ToPointeeTypeOrErr.takeError();
1445
1446 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1447}
1448
1450ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1451 // FIXME: Check for C++ support in "to" context.
1452 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1453 if (!ToPointeeTypeOrErr)
1454 return ToPointeeTypeOrErr.takeError();
1455
1456 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1457}
1458
1460ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1461 // FIXME: Check for C++0x support in "to" context.
1462 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1463 if (!ToPointeeTypeOrErr)
1464 return ToPointeeTypeOrErr.takeError();
1465
1466 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1467}
1468
1470ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1471 // FIXME: Check for C++ support in "to" context.
1472 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1473 if (!ToPointeeTypeOrErr)
1474 return ToPointeeTypeOrErr.takeError();
1475
1476 auto QualifierOrErr = import(T->getQualifier());
1477 if (!QualifierOrErr)
1478 return QualifierOrErr.takeError();
1479
1480 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1481 if (!ClsOrErr)
1482 return ClsOrErr.takeError();
1483
1484 return Importer.getToContext().getMemberPointerType(
1485 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1486}
1487
1489ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1490 Error Err = Error::success();
1491 auto ToElementType = importChecked(Err, T->getElementType());
1492 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1493 if (Err)
1494 return std::move(Err);
1495
1496 return Importer.getToContext().getConstantArrayType(
1497 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1498 T->getIndexTypeCVRQualifiers());
1499}
1500
1502ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1503 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1504 if (!ToArrayTypeOrErr)
1505 return ToArrayTypeOrErr.takeError();
1506
1507 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1508}
1509
1511ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1512 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1513 if (!ToElementTypeOrErr)
1514 return ToElementTypeOrErr.takeError();
1515
1516 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1517 T->getSizeModifier(),
1518 T->getIndexTypeCVRQualifiers());
1519}
1520
1522ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1523 Error Err = Error::success();
1524 QualType ToElementType = importChecked(Err, T->getElementType());
1525 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1526 if (Err)
1527 return std::move(Err);
1528 return Importer.getToContext().getVariableArrayType(
1529 ToElementType, ToSizeExpr, T->getSizeModifier(),
1530 T->getIndexTypeCVRQualifiers());
1531}
1532
1533ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1534 const DependentSizedArrayType *T) {
1535 Error Err = Error::success();
1536 QualType ToElementType = importChecked(Err, T->getElementType());
1537 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1538 if (Err)
1539 return std::move(Err);
1540 // SizeExpr may be null if size is not specified directly.
1541 // For example, 'int a[]'.
1542
1543 return Importer.getToContext().getDependentSizedArrayType(
1544 ToElementType, ToSizeExpr, T->getSizeModifier(),
1545 T->getIndexTypeCVRQualifiers());
1546}
1547
1548ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1549 const DependentSizedExtVectorType *T) {
1550 Error Err = Error::success();
1551 QualType ToElementType = importChecked(Err, T->getElementType());
1552 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1553 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1554 if (Err)
1555 return std::move(Err);
1556 return Importer.getToContext().getDependentSizedExtVectorType(
1557 ToElementType, ToSizeExpr, ToAttrLoc);
1558}
1559
1560ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1561 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1562 if (!ToElementTypeOrErr)
1563 return ToElementTypeOrErr.takeError();
1564
1565 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1566 T->getNumElements(),
1567 T->getVectorKind());
1568}
1569
1570ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1571 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1572 if (!ToElementTypeOrErr)
1573 return ToElementTypeOrErr.takeError();
1574
1575 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1576 T->getNumElements());
1577}
1578
1580ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1581 // FIXME: What happens if we're importing a function without a prototype
1582 // into C++? Should we make it variadic?
1583 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1584 if (!ToReturnTypeOrErr)
1585 return ToReturnTypeOrErr.takeError();
1586
1587 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1588 T->getExtInfo());
1589}
1590
1592ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1593 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1594 if (!ToReturnTypeOrErr)
1595 return ToReturnTypeOrErr.takeError();
1596
1597 // Import argument types
1598 SmallVector<QualType, 4> ArgTypes;
1599 for (const auto &A : T->param_types()) {
1600 ExpectedType TyOrErr = import(A);
1601 if (!TyOrErr)
1602 return TyOrErr.takeError();
1603 ArgTypes.push_back(*TyOrErr);
1604 }
1605
1606 // Import exception types
1607 SmallVector<QualType, 4> ExceptionTypes;
1608 for (const auto &E : T->exceptions()) {
1609 ExpectedType TyOrErr = import(E);
1610 if (!TyOrErr)
1611 return TyOrErr.takeError();
1612 ExceptionTypes.push_back(*TyOrErr);
1613 }
1614
1615 FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
1616 Error Err = Error::success();
1617 FunctionProtoType::ExtProtoInfo ToEPI;
1618 ToEPI.ExtInfo = FromEPI.ExtInfo;
1619 ToEPI.Variadic = FromEPI.Variadic;
1620 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1621 ToEPI.TypeQuals = FromEPI.TypeQuals;
1622 ToEPI.RefQualifier = FromEPI.RefQualifier;
1623 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1625 importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr);
1627 importChecked(Err, FromEPI.ExceptionSpec.SourceDecl);
1629 importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate);
1630 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1631
1632 if (Err)
1633 return std::move(Err);
1634
1635 return Importer.getToContext().getFunctionType(
1636 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1637}
1638
1639ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1640 const UnresolvedUsingType *T) {
1641 Error Err = Error::success();
1642 auto ToQualifier = importChecked(Err, T->getQualifier());
1643 auto *ToD = importChecked(Err, T->getDecl());
1644 if (Err)
1645 return std::move(Err);
1646
1648 return Importer.getToContext().getCanonicalUnresolvedUsingType(ToD);
1649 return Importer.getToContext().getUnresolvedUsingType(T->getKeyword(),
1650 ToQualifier, ToD);
1651}
1652
1653ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1654 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1655 if (!ToInnerTypeOrErr)
1656 return ToInnerTypeOrErr.takeError();
1657
1658 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1659}
1660
1662ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1663
1664 ExpectedType Pattern = import(T->getPattern());
1665 if (!Pattern)
1666 return Pattern.takeError();
1667 ExpectedExpr Index = import(T->getIndexExpr());
1668 if (!Index)
1669 return Index.takeError();
1670 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1671}
1672
1673ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1674 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1675 if (!ToDeclOrErr)
1676 return ToDeclOrErr.takeError();
1677
1678 auto ToQualifierOrErr = import(T->getQualifier());
1679 if (!ToQualifierOrErr)
1680 return ToQualifierOrErr.takeError();
1681
1682 ExpectedType ToUnderlyingTypeOrErr =
1683 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1684 if (!ToUnderlyingTypeOrErr)
1685 return ToUnderlyingTypeOrErr.takeError();
1686
1687 return Importer.getToContext().getTypedefType(
1688 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1689}
1690
1691ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1692 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1693 if (!ToExprOrErr)
1694 return ToExprOrErr.takeError();
1695 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1696}
1697
1698ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1699 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1700 if (!ToUnderlyingTypeOrErr)
1701 return ToUnderlyingTypeOrErr.takeError();
1702 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1703 T->getKind());
1704}
1705
1706ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1707 Error Err = Error::success();
1708 auto ToQualifier = importChecked(Err, T->getQualifier());
1709 auto *ToD = importChecked(Err, T->getDecl());
1710 QualType ToT = importChecked(Err, T->desugar());
1711 if (Err)
1712 return std::move(Err);
1713 return Importer.getToContext().getUsingType(T->getKeyword(), ToQualifier, ToD,
1714 ToT);
1715}
1716
1717ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1718 // FIXME: Make sure that the "to" context supports C++0x!
1719 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1720 if (!ToExprOrErr)
1721 return ToExprOrErr.takeError();
1722
1723 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1724 if (!ToUnderlyingTypeOrErr)
1725 return ToUnderlyingTypeOrErr.takeError();
1726
1727 return Importer.getToContext().getDecltypeType(
1728 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1729}
1730
1732ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1733 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1734 if (!ToBaseTypeOrErr)
1735 return ToBaseTypeOrErr.takeError();
1736
1737 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1738 if (!ToUnderlyingTypeOrErr)
1739 return ToUnderlyingTypeOrErr.takeError();
1740
1741 return Importer.getToContext().getUnaryTransformType(
1742 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1743}
1744
1745ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1746 // FIXME: Make sure that the "to" context supports C++11!
1747 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1748 if (!ToDeducedTypeOrErr)
1749 return ToDeducedTypeOrErr.takeError();
1750
1751 TemplateName ToTypeConstraint;
1752 if (TemplateName FromTypeConstraint = T->getTypeConstraintConcept();
1753 !FromTypeConstraint.isNull()) {
1754 Expected<TemplateName> ToTypeConstraintOrErr = import(FromTypeConstraint);
1755 if (!ToTypeConstraintOrErr)
1756 return ToTypeConstraintOrErr.takeError();
1757 ToTypeConstraint = *ToTypeConstraintOrErr;
1758 }
1759
1760 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1761 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1762 ToTemplateArgs))
1763 return std::move(Err);
1764
1765 return Importer.getToContext().getAutoType(
1766 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1767 ToTypeConstraint, ToTemplateArgs);
1768}
1769
1770ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1771 const DeducedTemplateSpecializationType *T) {
1772 // FIXME: Make sure that the "to" context supports C++17!
1773 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1774 if (!ToTemplateNameOrErr)
1775 return ToTemplateNameOrErr.takeError();
1776 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1777 if (!ToDeducedTypeOrErr)
1778 return ToDeducedTypeOrErr.takeError();
1779
1780 return Importer.getToContext().getDeducedTemplateSpecializationType(
1781 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1782 *ToTemplateNameOrErr);
1783}
1784
1785ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1786 TagDecl *DeclForType = T->getDecl();
1787 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1788 if (!ToDeclOrErr)
1789 return ToDeclOrErr.takeError();
1790
1791 // If there is a definition of the 'OriginalDecl', it should be imported to
1792 // have all information for the type in the "To" AST. (In some cases no
1793 // other reference may exist to the definition decl and it would not be
1794 // imported otherwise.)
1795 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1796 if (!ToDefDeclOrErr)
1797 return ToDefDeclOrErr.takeError();
1798
1800 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1801
1802 auto ToQualifierOrErr = import(T->getQualifier());
1803 if (!ToQualifierOrErr)
1804 return ToQualifierOrErr.takeError();
1805
1806 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1807 *ToDeclOrErr, T->isTagOwned());
1808}
1809
1810ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1811 return VisitTagType(T);
1812}
1813
1814ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1815 return VisitTagType(T);
1816}
1817
1819ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1820 return VisitTagType(T);
1821}
1822
1823ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1824 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1825 if (!ToModifiedTypeOrErr)
1826 return ToModifiedTypeOrErr.takeError();
1827 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1828 if (!ToEquivalentTypeOrErr)
1829 return ToEquivalentTypeOrErr.takeError();
1830
1831 return Importer.getToContext().getAttributedType(
1832 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1833 T->getAttr());
1834}
1835
1837ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1838 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1839 if (!ToWrappedTypeOrErr)
1840 return ToWrappedTypeOrErr.takeError();
1841
1842 Error Err = Error::success();
1843 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1844
1845 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1846 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1847 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1848 if (!ToDeclOrErr)
1849 return ToDeclOrErr.takeError();
1850 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1851 }
1852
1853 return Importer.getToContext().getCountAttributedType(
1854 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1855 ArrayRef(CoupledDecls));
1856}
1857
1859ASTNodeImporter::VisitLateParsedAttrType(const LateParsedAttrType *T) {
1860 llvm_unreachable("should be replaced with a concrete type before AST import");
1861}
1862
1863ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1864 const TemplateTypeParmType *T) {
1865 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1866 if (!ToDeclOrErr)
1867 return ToDeclOrErr.takeError();
1868
1869 return Importer.getToContext().getTemplateTypeParmType(
1870 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1871}
1872
1873ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1874 const SubstTemplateTypeParmType *T) {
1875 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1876 if (!ReplacedOrErr)
1877 return ReplacedOrErr.takeError();
1878
1879 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1880 if (!ToReplacementTypeOrErr)
1881 return ToReplacementTypeOrErr.takeError();
1882
1883 return Importer.getToContext().getSubstTemplateTypeParmType(
1884 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1885 T->getFinal());
1886}
1887
1888ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1889 const SubstTemplateTypeParmPackType *T) {
1890 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1891 if (!ReplacedOrErr)
1892 return ReplacedOrErr.takeError();
1893
1894 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1895 if (!ToArgumentPack)
1896 return ToArgumentPack.takeError();
1897
1898 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1899 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1900}
1901
1902ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1903 const SubstBuiltinTemplatePackType *T) {
1904 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1905 if (!ToArgumentPack)
1906 return ToArgumentPack.takeError();
1907 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1908}
1909
1910ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1911 const TemplateSpecializationType *T) {
1912 auto ToTemplateOrErr = import(T->getTemplateName());
1913 if (!ToTemplateOrErr)
1914 return ToTemplateOrErr.takeError();
1915
1916 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1917 if (Error Err =
1918 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1919 return std::move(Err);
1920
1921 ExpectedType ToUnderlyingOrErr =
1922 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1923 if (!ToUnderlyingOrErr)
1924 return ToUnderlyingOrErr.takeError();
1925 return Importer.getToContext().getTemplateSpecializationType(
1926 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1927 *ToUnderlyingOrErr);
1928}
1929
1931ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1932 ExpectedType ToPatternOrErr = import(T->getPattern());
1933 if (!ToPatternOrErr)
1934 return ToPatternOrErr.takeError();
1935
1936 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1937 T->getNumExpansions(),
1938 /*ExpactPack=*/false);
1939}
1940
1942ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1943 auto ToQualifierOrErr = import(T->getQualifier());
1944 if (!ToQualifierOrErr)
1945 return ToQualifierOrErr.takeError();
1946
1947 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1948 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1949 *ToQualifierOrErr, Name);
1950}
1951
1953ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1954 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1955 if (!ToDeclOrErr)
1956 return ToDeclOrErr.takeError();
1957
1958 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1959}
1960
1961ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1962 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1963 if (!ToBaseTypeOrErr)
1964 return ToBaseTypeOrErr.takeError();
1965
1966 SmallVector<QualType, 4> TypeArgs;
1967 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1968 if (ExpectedType TyOrErr = import(TypeArg))
1969 TypeArgs.push_back(*TyOrErr);
1970 else
1971 return TyOrErr.takeError();
1972 }
1973
1974 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1975 for (auto *P : T->quals()) {
1976 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1977 Protocols.push_back(*ProtocolOrErr);
1978 else
1979 return ProtocolOrErr.takeError();
1980
1981 }
1982
1983 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1984 Protocols,
1985 T->isKindOfTypeAsWritten());
1986}
1987
1989ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1990 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1991 if (!ToPointeeTypeOrErr)
1992 return ToPointeeTypeOrErr.takeError();
1993
1994 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1995}
1996
1998ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1999 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
2000 if (!ToUnderlyingTypeOrErr)
2001 return ToUnderlyingTypeOrErr.takeError();
2002
2003 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
2004 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
2005 ToIdentifier);
2006}
2007
2008ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
2009 Error Err = Error::success();
2010 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
2011 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
2012 if (Err)
2013 return std::move(Err);
2014
2015 return Importer.getToContext().getAdjustedType(ToOriginalType,
2016 ToAdjustedType);
2017}
2018
2019ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
2020 return Importer.getToContext().getBitIntType(T->isUnsigned(),
2021 T->getNumBits());
2022}
2023
2024ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
2025 const clang::BTFTagAttributedType *T) {
2026 Error Err = Error::success();
2027 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
2028 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2029 if (Err)
2030 return std::move(Err);
2031
2032 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
2033 ToWrappedType);
2034}
2035
2036ExpectedType clang::ASTNodeImporter::VisitOverflowBehaviorType(
2037 const clang::OverflowBehaviorType *T) {
2038 Error Err = Error::success();
2039 OverflowBehaviorType::OverflowBehaviorKind ToKind = T->getBehaviorKind();
2040 QualType ToUnderlyingType = importChecked(Err, T->getUnderlyingType());
2041 if (Err)
2042 return std::move(Err);
2043
2044 return Importer.getToContext().getOverflowBehaviorType(ToKind,
2046}
2047
2048ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2049 const clang::HLSLAttributedResourceType *T) {
2050 Error Err = Error::success();
2051 HLSLAttributedResourceType::Attributes ToAttrs = T->getAttrs();
2052 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2053 QualType ToContainedType = importChecked(Err, T->getContainedType());
2054 ToAttrs.SampleCountExpr = importChecked(Err, T->getSampleCountExpr());
2055 if (Err)
2056 return std::move(Err);
2057
2058 return Importer.getToContext().getHLSLAttributedResourceType(
2059 ToWrappedType, ToContainedType, ToAttrs);
2060}
2061
2062ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2063 const clang::HLSLInlineSpirvType *T) {
2064 Error Err = Error::success();
2065
2066 uint32_t ToOpcode = T->getOpcode();
2067 uint32_t ToSize = T->getSize();
2068 uint32_t ToAlignment = T->getAlignment();
2069
2070 llvm::SmallVector<SpirvOperand> ToOperands;
2071
2072 for (auto &Operand : T->getOperands()) {
2073 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2074
2075 switch (Operand.getKind()) {
2076 case SpirvOperandKind::ConstantId:
2077 ToOperands.push_back(SpirvOperand::createConstant(
2078 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2079 break;
2080 case SpirvOperandKind::Literal:
2081 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2082 break;
2083 case SpirvOperandKind::TypeId:
2084 ToOperands.push_back(SpirvOperand::createType(
2085 importChecked(Err, Operand.getResultType())));
2086 break;
2087 default:
2088 llvm_unreachable("Invalid SpirvOperand kind");
2089 }
2090
2091 if (Err)
2092 return std::move(Err);
2093 }
2094
2095 return Importer.getToContext().getHLSLInlineSpirvType(
2096 ToOpcode, ToSize, ToAlignment, ToOperands);
2097}
2098
2099ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2100 const clang::ConstantMatrixType *T) {
2101 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2102 if (!ToElementTypeOrErr)
2103 return ToElementTypeOrErr.takeError();
2104
2105 return Importer.getToContext().getConstantMatrixType(
2106 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2107}
2108
2109ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2110 const clang::DependentAddressSpaceType *T) {
2111 Error Err = Error::success();
2112 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2113 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2114 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2115 if (Err)
2116 return std::move(Err);
2117
2118 return Importer.getToContext().getDependentAddressSpaceType(
2119 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2120}
2121
2122ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2123 const clang::DependentBitIntType *T) {
2124 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2125 if (!ToNumBitsExprOrErr)
2126 return ToNumBitsExprOrErr.takeError();
2127 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2128 *ToNumBitsExprOrErr);
2129}
2130
2131ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2132 const clang::PredefinedSugarType *T) {
2133 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2134}
2135
2136ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2137 const clang::DependentSizedMatrixType *T) {
2138 Error Err = Error::success();
2139 QualType ToElementType = importChecked(Err, T->getElementType());
2140 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2141 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2142 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2143 if (Err)
2144 return std::move(Err);
2145
2146 return Importer.getToContext().getDependentSizedMatrixType(
2147 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2148}
2149
2150ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2151 const clang::DependentVectorType *T) {
2152 Error Err = Error::success();
2153 QualType ToElementType = importChecked(Err, T->getElementType());
2154 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2155 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2156 if (Err)
2157 return std::move(Err);
2158
2159 return Importer.getToContext().getDependentVectorType(
2160 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2161}
2162
2163ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2164 const clang::ObjCTypeParamType *T) {
2165 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2166 if (!ToDeclOrErr)
2167 return ToDeclOrErr.takeError();
2168
2169 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2170 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2171 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2172 if (!ToProtocolOrErr)
2173 return ToProtocolOrErr.takeError();
2174 ToProtocols.push_back(*ToProtocolOrErr);
2175 }
2176
2177 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2178 ToProtocols);
2179}
2180
2181ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2182 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2183 if (!ToElementTypeOrErr)
2184 return ToElementTypeOrErr.takeError();
2185
2186 ASTContext &ToCtx = Importer.getToContext();
2187 if (T->isReadOnly())
2188 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2189 else
2190 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2191}
2192
2193//----------------------------------------------------------------------------
2194// Import Declarations
2195//----------------------------------------------------------------------------
2197 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2198 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2199 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2200 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2201 // FIXME: We could support these constructs by importing a different type of
2202 // this parameter and by importing the original type of the parameter only
2203 // after the FunctionDecl is created. See
2204 // VisitFunctionDecl::UsedDifferentProtoType.
2205 DeclContext *OrigDC = D->getDeclContext();
2206 FunctionDecl *FunDecl;
2207 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2208 FunDecl->hasBody()) {
2209 auto getLeafPointeeType = [](const Type *T) {
2210 while (T->isPointerType() || T->isArrayType()) {
2211 T = T->getPointeeOrArrayElementType();
2212 }
2213 return T;
2214 };
2215 for (const ParmVarDecl *P : FunDecl->parameters()) {
2216 const Type *LeafT =
2217 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2218 auto *RT = dyn_cast<RecordType>(LeafT);
2219 if (RT && RT->getDecl() == D) {
2220 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2221 << D->getDeclKindName();
2222 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2223 }
2224 }
2225 }
2226
2227 // Import the context of this declaration.
2228 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2229 return Err;
2230
2231 // Import the name of this declaration.
2232 if (Error Err = importInto(Name, D->getDeclName()))
2233 return Err;
2234
2235 // Import the location of this declaration.
2236 if (Error Err = importInto(Loc, D->getLocation()))
2237 return Err;
2238
2239 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2240 if (ToD)
2241 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2242 return Err;
2243
2244 return Error::success();
2245}
2246
2248 NamedDecl *&ToD, SourceLocation &Loc) {
2249
2250 // Import the name of this declaration.
2251 if (Error Err = importInto(Name, D->getDeclName()))
2252 return Err;
2253
2254 // Import the location of this declaration.
2255 if (Error Err = importInto(Loc, D->getLocation()))
2256 return Err;
2257
2258 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2259 if (ToD)
2260 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2261 return Err;
2262
2263 return Error::success();
2264}
2265
2267 if (!FromD)
2268 return Error::success();
2269
2270 if (!ToD)
2271 if (Error Err = importInto(ToD, FromD))
2272 return Err;
2273
2274 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2275 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2276 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2277 !ToRecord->getDefinition()) {
2278 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2279 return Err;
2280 }
2281 }
2282 return Error::success();
2283 }
2284
2285 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2286 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2287 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2288 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2289 return Err;
2290 }
2291 }
2292 return Error::success();
2293 }
2294
2295 return Error::success();
2296}
2297
2298Error
2300 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2301 // NOTE: To.Name and To.Loc are already imported.
2302 // We only have to import To.LocInfo.
2303 switch (To.getName().getNameKind()) {
2310 return Error::success();
2311
2313 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2314 To.setCXXOperatorNameRange(*ToRangeOrErr);
2315 else
2316 return ToRangeOrErr.takeError();
2317 return Error::success();
2318 }
2320 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2321 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2322 else
2323 return LocOrErr.takeError();
2324 return Error::success();
2325 }
2329 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2330 To.setNamedTypeInfo(*ToTInfoOrErr);
2331 else
2332 return ToTInfoOrErr.takeError();
2333 return Error::success();
2334 }
2335 }
2336 llvm_unreachable("Unknown name kind.");
2337}
2338
2339Error
2341 if (Importer.isMinimalImport() && !ForceImport) {
2342 auto ToDCOrErr = Importer.ImportContext(FromDC);
2343 return ToDCOrErr.takeError();
2344 }
2345
2346 // We use strict error handling in case of records and enums, but not
2347 // with e.g. namespaces.
2348 //
2349 // FIXME Clients of the ASTImporter should be able to choose an
2350 // appropriate error handling strategy for their needs. For instance,
2351 // they may not want to mark an entire namespace as erroneous merely
2352 // because there is an ODR error with two typedefs. As another example,
2353 // the client may allow EnumConstantDecls with same names but with
2354 // different values in two distinct translation units.
2355 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2356
2357 auto MightNeedReordering = [](const Decl *D) {
2359 };
2360
2361 // Import everything that might need reordering first.
2362 Error ChildErrors = Error::success();
2363 for (auto *From : FromDC->decls()) {
2364 if (!MightNeedReordering(From))
2365 continue;
2366
2367 ExpectedDecl ImportedOrErr = import(From);
2368
2369 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2370 // want to make sure that we are also completing each FieldDecl. There
2371 // are currently cases where this does not happen and this is correctness
2372 // fix since operations such as code generation will expect this to be so.
2373 if (!ImportedOrErr) {
2374 HandleChildErrors.handleChildImportResult(ChildErrors,
2375 ImportedOrErr.takeError());
2376 continue;
2377 }
2378 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2379 Decl *ImportedDecl = *ImportedOrErr;
2380 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2381 if (FieldFrom && FieldTo) {
2382 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2383 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2384 }
2385 }
2386
2387 // We reorder declarations in RecordDecls because they may have another order
2388 // in the "to" context than they have in the "from" context. This may happen
2389 // e.g when we import a class like this:
2390 // struct declToImport {
2391 // int a = c + b;
2392 // int b = 1;
2393 // int c = 2;
2394 // };
2395 // During the import of `a` we import first the dependencies in sequence,
2396 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2397 // first removing the already imported members and then adding them in the
2398 // order as they appear in the "from" context.
2399 //
2400 // Keeping field order is vital because it determines structure layout.
2401 //
2402 // Here and below, we cannot call field_begin() method and its callers on
2403 // ToDC if it has an external storage. Calling field_begin() will
2404 // automatically load all the fields by calling
2405 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2406 // call ASTImporter::Import(). This is because the ExternalASTSource
2407 // interface in LLDB is implemented by the means of the ASTImporter. However,
2408 // calling an import at this point would result in an uncontrolled import, we
2409 // must avoid that.
2410
2411 auto ToDCOrErr = Importer.ImportContext(FromDC);
2412 if (!ToDCOrErr) {
2413 consumeError(std::move(ChildErrors));
2414 return ToDCOrErr.takeError();
2415 }
2416
2417 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2418 DeclContext *ToDC = *ToDCOrErr;
2419 // Remove all declarations, which may be in wrong order in the
2420 // lexical DeclContext and then add them in the proper order.
2421 for (auto *D : FromRD->decls()) {
2422 if (!MightNeedReordering(D))
2423 continue;
2424
2425 assert(D && "DC contains a null decl");
2426 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2427 // Remove only the decls which we successfully imported.
2428 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2429 // Remove the decl from its wrong place in the linked list.
2430 ToDC->removeDecl(ToD);
2431 // Add the decl to the end of the linked list.
2432 // This time it will be at the proper place because the enclosing for
2433 // loop iterates in the original (good) order of the decls.
2434 ToDC->addDeclInternal(ToD);
2435 }
2436 }
2437 }
2438
2439 // Import everything else.
2440 for (auto *From : FromDC->decls()) {
2441 if (MightNeedReordering(From))
2442 continue;
2443
2444 ExpectedDecl ImportedOrErr = import(From);
2445 if (!ImportedOrErr)
2446 HandleChildErrors.handleChildImportResult(ChildErrors,
2447 ImportedOrErr.takeError());
2448 }
2449
2450 return ChildErrors;
2451}
2452
2454 const FieldDecl *To) {
2455 RecordDecl *FromRecordDecl = nullptr;
2456 RecordDecl *ToRecordDecl = nullptr;
2457 // If we have a field that is an ArrayType we need to check if the array
2458 // element is a RecordDecl and if so we need to import the definition.
2459 QualType FromType = From->getType();
2460 QualType ToType = To->getType();
2461 if (FromType->isArrayType()) {
2462 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2463 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2464 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2465 }
2466
2467 if (!FromRecordDecl || !ToRecordDecl) {
2468 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2469 const RecordType *RecordTo = ToType->getAs<RecordType>();
2470
2471 if (RecordFrom && RecordTo) {
2472 FromRecordDecl = RecordFrom->getDecl();
2473 ToRecordDecl = RecordTo->getDecl();
2474 }
2475 }
2476
2477 if (FromRecordDecl && ToRecordDecl) {
2478 if (FromRecordDecl->isCompleteDefinition() &&
2479 !ToRecordDecl->isCompleteDefinition())
2480 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2481 }
2482
2483 return Error::success();
2484}
2485
2487 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2488 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2489 if (!ToDCOrErr)
2490 return ToDCOrErr.takeError();
2491 ToDC = *ToDCOrErr;
2492
2493 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2494 auto ToLexicalDCOrErr = Importer.ImportContext(
2495 FromD->getLexicalDeclContext());
2496 if (!ToLexicalDCOrErr)
2497 return ToLexicalDCOrErr.takeError();
2498 ToLexicalDC = *ToLexicalDCOrErr;
2499 } else
2500 ToLexicalDC = ToDC;
2501
2502 return Error::success();
2503}
2504
2506 const CXXRecordDecl *From, CXXRecordDecl *To) {
2507 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2508 "Import implicit methods to or from non-definition");
2509
2510 for (CXXMethodDecl *FromM : From->methods())
2511 if (FromM->isImplicit()) {
2512 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2513 if (!ToMOrErr)
2514 return ToMOrErr.takeError();
2515 }
2516
2517 return Error::success();
2518}
2519
2521 ASTImporter &Importer) {
2522 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2523 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2525 else
2526 return ToTypedefOrErr.takeError();
2527 }
2528 return Error::success();
2529}
2530
2532 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2533 auto DefinitionCompleter = [To]() {
2534 // There are cases in LLDB when we first import a class without its
2535 // members. The class will have DefinitionData, but no members. Then,
2536 // importDefinition is called from LLDB, which tries to get the members, so
2537 // when we get here, the class already has the DefinitionData set, so we
2538 // must unset the CompleteDefinition here to be able to complete again the
2539 // definition.
2540 To->setCompleteDefinition(false);
2541 To->completeDefinition();
2542 };
2543
2544 if (To->getDefinition() || To->isBeingDefined()) {
2545 if (Kind == IDK_Everything ||
2546 // In case of lambdas, the class already has a definition ptr set, but
2547 // the contained decls are not imported yet. Also, isBeingDefined was
2548 // set in CXXRecordDecl::CreateLambda. We must import the contained
2549 // decls here and finish the definition.
2550 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2551 if (To->isLambda()) {
2552 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2554 ToCaptures.reserve(FromCXXRD->capture_size());
2555 for (const auto &FromCapture : FromCXXRD->captures()) {
2556 if (auto ToCaptureOrErr = import(FromCapture))
2557 ToCaptures.push_back(*ToCaptureOrErr);
2558 else
2559 return ToCaptureOrErr.takeError();
2560 }
2561 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2562 ToCaptures);
2563 }
2564
2565 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2566 // Finish the definition of the lambda, set isBeingDefined to false.
2567 if (To->isLambda())
2568 DefinitionCompleter();
2569 return Result;
2570 }
2571
2572 return Error::success();
2573 }
2574
2575 To->startDefinition();
2576 // Set the definition to complete even if it is really not complete during
2577 // import. Some AST constructs (expressions) require the record layout
2578 // to be calculated (see 'clang::computeDependence') at the time they are
2579 // constructed. Import of such AST node is possible during import of the
2580 // same record, there is no way to have a completely defined record (all
2581 // fields imported) at that time without multiple AST import passes.
2582 if (!Importer.isMinimalImport())
2583 To->setCompleteDefinition(true);
2584 // Complete the definition even if error is returned.
2585 // The RecordDecl may be already part of the AST so it is better to
2586 // have it in complete state even if something is wrong with it.
2587 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2588
2589 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2590 return Err;
2591
2592 // Add base classes.
2593 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2594 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2595 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2596
2597 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2598 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2599
2600 #define FIELD(Name, Width, Merge) \
2601 ToData.Name = FromData.Name;
2602 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2603
2604 // Copy over the data stored in RecordDeclBits
2605 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2606
2608 for (const auto &Base1 : FromCXX->bases()) {
2609 ExpectedType TyOrErr = import(Base1.getType());
2610 if (!TyOrErr)
2611 return TyOrErr.takeError();
2612
2613 SourceLocation EllipsisLoc;
2614 if (Base1.isPackExpansion()) {
2615 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2616 EllipsisLoc = *LocOrErr;
2617 else
2618 return LocOrErr.takeError();
2619 }
2620
2621 // Ensure that we have a definition for the base.
2622 if (Error Err =
2623 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2624 return Err;
2625
2626 auto RangeOrErr = import(Base1.getSourceRange());
2627 if (!RangeOrErr)
2628 return RangeOrErr.takeError();
2629
2630 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2631 if (!TSIOrErr)
2632 return TSIOrErr.takeError();
2633
2634 Bases.push_back(
2635 new (Importer.getToContext()) CXXBaseSpecifier(
2636 *RangeOrErr,
2637 Base1.isVirtual(),
2638 Base1.isBaseOfClass(),
2639 Base1.getAccessSpecifierAsWritten(),
2640 *TSIOrErr,
2641 EllipsisLoc));
2642 }
2643 if (!Bases.empty())
2644 ToCXX->setBases(Bases.data(), Bases.size());
2645 }
2646
2647 if (shouldForceImportDeclContext(Kind)) {
2648 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2649 return Err;
2650 }
2651
2652 return Error::success();
2653}
2654
2656 if (To->getAnyInitializer())
2657 return Error::success();
2658
2659 Expr *FromInit = From->getInit();
2660 if (!FromInit)
2661 return Error::success();
2662
2663 ExpectedExpr ToInitOrErr = import(FromInit);
2664 if (!ToInitOrErr)
2665 return ToInitOrErr.takeError();
2666
2667 To->setInit(*ToInitOrErr);
2668 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2669 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2670 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2671 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2672 // FIXME: Also import the initializer value.
2673 }
2674
2675 // FIXME: Other bits to merge?
2676 return Error::success();
2677}
2678
2680 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2681 if (To->getDefinition() || To->isBeingDefined()) {
2682 if (Kind == IDK_Everything)
2683 return ImportDeclContext(From, /*ForceImport=*/true);
2684 return Error::success();
2685 }
2686
2687 To->startDefinition();
2688
2689 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2690 return Err;
2691
2692 ExpectedType ToTypeOrErr =
2693 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2694 if (!ToTypeOrErr)
2695 return ToTypeOrErr.takeError();
2696
2697 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2698 if (!ToPromotionTypeOrErr)
2699 return ToPromotionTypeOrErr.takeError();
2700
2702 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2703 return Err;
2704
2705 // FIXME: we might need to merge the number of positive or negative bits
2706 // if the enumerator lists don't match.
2707 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2708 From->getNumPositiveBits(),
2709 From->getNumNegativeBits());
2710 return Error::success();
2711}
2712
2716 for (const auto &Arg : FromArgs) {
2717 if (auto ToOrErr = import(Arg))
2718 ToArgs.push_back(*ToOrErr);
2719 else
2720 return ToOrErr.takeError();
2721 }
2722
2723 return Error::success();
2724}
2725
2726// FIXME: Do not forget to remove this and use only 'import'.
2729 return import(From);
2730}
2731
2732template <typename InContainerTy>
2734 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2735 for (const auto &FromLoc : Container) {
2736 if (auto ToLocOrErr = import(FromLoc))
2737 ToTAInfo.addArgument(*ToLocOrErr);
2738 else
2739 return ToLocOrErr.takeError();
2740 }
2741 return Error::success();
2742}
2743
2749
2750bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2751 bool IgnoreTemplateParmDepth) {
2752 // Eliminate a potential failure point where we attempt to re-import
2753 // something we're trying to import while completing ToRecord.
2754 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2755 if (ToOrigin) {
2756 To = ToOrigin;
2757 }
2758
2760 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2761 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2763 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2764 IgnoreTemplateParmDepth);
2765 return Ctx.IsEquivalent(From, To);
2766}
2767
2769 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2770 << D->getDeclKindName();
2771 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2772}
2773
2775 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2776 << D->getDeclKindName();
2777 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2778}
2779
2781 // Import the context of this declaration.
2782 DeclContext *DC, *LexicalDC;
2783 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2784 return std::move(Err);
2785
2786 // Import the location of this declaration.
2787 ExpectedSLoc LocOrErr = import(D->getLocation());
2788 if (!LocOrErr)
2789 return LocOrErr.takeError();
2790
2791 EmptyDecl *ToD;
2792 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2793 return ToD;
2794
2795 ToD->setLexicalDeclContext(LexicalDC);
2796 LexicalDC->addDeclInternal(ToD);
2797 return ToD;
2798}
2799
2801 TranslationUnitDecl *ToD =
2802 Importer.getToContext().getTranslationUnitDecl();
2803
2804 Importer.MapImported(D, ToD);
2805
2806 return ToD;
2807}
2808
2810 Error Err = Error::success();
2811 Expr *ToAsmString = importChecked(Err, D->getAsmStringExpr());
2812 SourceLocation ToAsmLoc = importChecked(Err, D->getAsmLoc());
2813 SourceLocation ToRParenLoc = importChecked(Err, D->getRParenLoc());
2814 if (Err)
2815 return std::move(Err);
2816
2817 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2818 if (!DCOrErr)
2819 return DCOrErr.takeError();
2820 DeclContext *DC = *DCOrErr;
2821
2822 FileScopeAsmDecl *ToD;
2823 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToAsmString,
2824 ToAsmLoc, ToRParenLoc))
2825 return ToD;
2826
2827 ToD->setLexicalDeclContext(DC);
2828 DC->addDeclInternal(ToD);
2829
2830 return ToD;
2831}
2832
2834 DeclContext *DC, *LexicalDC;
2835 DeclarationName Name;
2836 SourceLocation Loc;
2837 NamedDecl *ToND;
2838 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2839 return std::move(Err);
2840 if (ToND)
2841 return ToND;
2842
2843 BindingDecl *ToD;
2844 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2845 Name.getAsIdentifierInfo(), D->getType()))
2846 return ToD;
2847
2848 Error Err = Error::success();
2849 QualType ToType = importChecked(Err, D->getType());
2850 Expr *ToBinding = importChecked(Err, D->getBinding());
2851 DecompositionDecl *ToDecomposedDecl =
2853 if (Err)
2854 return std::move(Err);
2855
2856 ToD->setBinding(ToType, ToBinding);
2857 ToD->setDecomposedDecl(ToDecomposedDecl);
2858 addDeclToContexts(D, ToD);
2859
2860 return ToD;
2861}
2862
2864 ExpectedSLoc LocOrErr = import(D->getLocation());
2865 if (!LocOrErr)
2866 return LocOrErr.takeError();
2867 auto ColonLocOrErr = import(D->getColonLoc());
2868 if (!ColonLocOrErr)
2869 return ColonLocOrErr.takeError();
2870
2871 // Import the context of this declaration.
2872 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2873 if (!DCOrErr)
2874 return DCOrErr.takeError();
2875 DeclContext *DC = *DCOrErr;
2876
2877 AccessSpecDecl *ToD;
2878 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2879 DC, *LocOrErr, *ColonLocOrErr))
2880 return ToD;
2881
2882 // Lexical DeclContext and Semantic DeclContext
2883 // is always the same for the accessSpec.
2884 ToD->setLexicalDeclContext(DC);
2885 DC->addDeclInternal(ToD);
2886
2887 return ToD;
2888}
2889
2891 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2892 if (!DCOrErr)
2893 return DCOrErr.takeError();
2894 DeclContext *DC = *DCOrErr;
2895 DeclContext *LexicalDC = DC;
2896
2897 Error Err = Error::success();
2898 auto ToLocation = importChecked(Err, D->getLocation());
2899 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2900 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2901 auto ToMessage = importChecked(Err, D->getMessage());
2902 if (Err)
2903 return std::move(Err);
2904
2905 StaticAssertDecl *ToD;
2906 if (GetImportedOrCreateDecl(
2907 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2908 ToRParenLoc, D->isFailed()))
2909 return ToD;
2910
2911 ToD->setLexicalDeclContext(LexicalDC);
2912 LexicalDC->addDeclInternal(ToD);
2913 return ToD;
2914}
2915
2918 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2919 if (!DCOrErr)
2920 return DCOrErr.takeError();
2921 DeclContext *DC = *DCOrErr;
2922 DeclContext *LexicalDC = DC;
2923
2924 Error Err = Error::success();
2925 auto ToLocation = importChecked(Err, D->getLocation());
2926 auto ToExpansion = importChecked(Err, D->getExpansionPattern());
2927 auto ToIndex = importChecked(Err, D->getIndexTemplateParm());
2928 auto ToInstantiations = importChecked(Err, D->getInstantiations());
2929 if (Err)
2930 return std::move(Err);
2931
2933 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToLocation,
2934 ToIndex))
2935 return ToD;
2936
2937 ToD->setExpansionPattern(ToExpansion);
2938 ToD->setInstantiations(ToInstantiations);
2939 ToD->setLexicalDeclContext(LexicalDC);
2940 LexicalDC->addDeclInternal(ToD);
2941 return ToD;
2942}
2943
2945 // Import the major distinguishing characteristics of this namespace.
2946 DeclContext *DC, *LexicalDC;
2947 DeclarationName Name;
2948 SourceLocation Loc;
2949 NamedDecl *ToD;
2950 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2951 return std::move(Err);
2952 if (ToD)
2953 return ToD;
2954
2955 NamespaceDecl *MergeWithNamespace = nullptr;
2956 if (!Name) {
2957 // This is an anonymous namespace. Adopt an existing anonymous
2958 // namespace if we can.
2959 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2960 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2961 MergeWithNamespace = TU->getAnonymousNamespace();
2962 else
2963 MergeWithNamespace =
2964 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2965 } else {
2966 SmallVector<NamedDecl *, 4> ConflictingDecls;
2967 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2968 for (auto *FoundDecl : FoundDecls) {
2969 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2970 continue;
2971
2972 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2973 MergeWithNamespace = FoundNS;
2974 ConflictingDecls.clear();
2975 break;
2976 }
2977
2978 ConflictingDecls.push_back(FoundDecl);
2979 }
2980
2981 if (!ConflictingDecls.empty()) {
2982 ExpectedName NameOrErr = Importer.HandleNameConflict(
2983 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2984 ConflictingDecls.size());
2985 if (NameOrErr)
2986 Name = NameOrErr.get();
2987 else
2988 return NameOrErr.takeError();
2989 }
2990 }
2991
2992 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2993 if (!BeginLocOrErr)
2994 return BeginLocOrErr.takeError();
2995 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2996 if (!RBraceLocOrErr)
2997 return RBraceLocOrErr.takeError();
2998
2999 // Create the "to" namespace, if needed.
3000 NamespaceDecl *ToNamespace = MergeWithNamespace;
3001 if (!ToNamespace) {
3002 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
3003 D->isInline(), *BeginLocOrErr, Loc,
3004 Name.getAsIdentifierInfo(),
3005 /*PrevDecl=*/nullptr, D->isNested()))
3006 return ToNamespace;
3007 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
3008 ToNamespace->setLexicalDeclContext(LexicalDC);
3009 LexicalDC->addDeclInternal(ToNamespace);
3010
3011 // If this is an anonymous namespace, register it as the anonymous
3012 // namespace within its context.
3013 if (!Name) {
3014 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3015 TU->setAnonymousNamespace(ToNamespace);
3016 else
3017 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
3018 }
3019 }
3020 Importer.MapImported(D, ToNamespace);
3021
3022 if (Error Err = ImportDeclContext(D))
3023 return std::move(Err);
3024
3025 return ToNamespace;
3026}
3027
3029 // Import the major distinguishing characteristics of this namespace.
3030 DeclContext *DC, *LexicalDC;
3031 DeclarationName Name;
3032 SourceLocation Loc;
3033 NamedDecl *LookupD;
3034 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
3035 return std::move(Err);
3036 if (LookupD)
3037 return LookupD;
3038
3039 // NOTE: No conflict resolution is done for namespace aliases now.
3040
3041 Error Err = Error::success();
3042 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
3043 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
3044 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3045 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
3046 auto ToNamespace = importChecked(Err, D->getNamespace());
3047 if (Err)
3048 return std::move(Err);
3049
3050 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
3051
3052 NamespaceAliasDecl *ToD;
3053 if (GetImportedOrCreateDecl(
3054 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
3055 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
3056 return ToD;
3057
3058 ToD->setLexicalDeclContext(LexicalDC);
3059 LexicalDC->addDeclInternal(ToD);
3060
3061 return ToD;
3062}
3063
3066 // Import the major distinguishing characteristics of this typedef.
3067 DeclarationName Name;
3068 SourceLocation Loc;
3069 NamedDecl *ToD;
3070 // Do not import the DeclContext, we will import it once the TypedefNameDecl
3071 // is created.
3072 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
3073 return std::move(Err);
3074 if (ToD)
3075 return ToD;
3076
3077 DeclContext *DC = cast_or_null<DeclContext>(
3078 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
3079 DeclContext *LexicalDC =
3080 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
3082
3083 // If this typedef is not in block scope, determine whether we've
3084 // seen a typedef with the same name (that we can merge with) or any
3085 // other entity by that name (which name lookup could conflict with).
3086 // Note: Repeated typedefs are not valid in C99:
3087 // 'typedef int T; typedef int T;' is invalid
3088 // We do not care about this now.
3089 if (DC && !DC->isFunctionOrMethod()) {
3090 SmallVector<NamedDecl *, 4> ConflictingDecls;
3091 unsigned IDNS = Decl::IDNS_Ordinary;
3092 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3093 for (auto *FoundDecl : FoundDecls) {
3094 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3095 continue;
3096 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3097 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3098 continue;
3099
3100 QualType FromUT = D->getUnderlyingType();
3101 QualType FoundUT = FoundTypedef->getUnderlyingType();
3102 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3103 // If the underlying declarations are unnamed records these can be
3104 // imported as different types. We should create a distinct typedef
3105 // node in this case.
3106 // If we found an existing underlying type with a record in a
3107 // different context (than the imported), this is already reason for
3108 // having distinct typedef nodes for these.
3109 // Again this can create situation like
3110 // 'typedef int T; typedef int T;' but this is hard to avoid without
3111 // a rename strategy at import.
3112 if (!FromUT.isNull() && !FoundUT.isNull()) {
3113 RecordDecl *FromR = FromUT->getAsRecordDecl();
3114 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3115 if (FromR && FoundR &&
3116 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3117 continue;
3118 }
3119 // If the "From" context has a complete underlying type but we
3120 // already have a complete underlying type then return with that.
3121 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3122 return Importer.MapImported(D, FoundTypedef);
3123 // FIXME Handle redecl chain. When you do that make consistent changes
3124 // in ASTImporterLookupTable too.
3125 } else {
3126 ConflictingDecls.push_back(FoundDecl);
3127 }
3128 }
3129 }
3130
3131 if (!ConflictingDecls.empty()) {
3132 ExpectedName NameOrErr = Importer.HandleNameConflict(
3133 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3134 if (NameOrErr)
3135 Name = NameOrErr.get();
3136 else
3137 return NameOrErr.takeError();
3138 }
3139 }
3140
3141 Error Err = Error::success();
3143 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3144 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3145 if (Err)
3146 return std::move(Err);
3147
3148 // Create the new typedef node.
3149 // FIXME: ToUnderlyingType is not used.
3150 (void)ToUnderlyingType;
3151 TypedefNameDecl *ToTypedef;
3152 if (IsAlias) {
3153 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3154 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3155 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3156 return ToTypedef;
3157 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3158 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3159 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3160 return ToTypedef;
3161
3162 // Import the DeclContext and set it to the Typedef.
3163 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3164 return std::move(Err);
3165 ToTypedef->setDeclContext(DC);
3166 ToTypedef->setLexicalDeclContext(LexicalDC);
3167 // Add to the lookupTable because we could not do that in MapImported.
3168 Importer.AddToLookupTable(ToTypedef);
3169
3170 ToTypedef->setAccess(D->getAccess());
3171
3172 // Templated declarations should not appear in DeclContext.
3173 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3174 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3175 LexicalDC->addDeclInternal(ToTypedef);
3176
3177 return ToTypedef;
3178}
3179
3183
3187
3190 // Import the major distinguishing characteristics of this typedef.
3191 DeclContext *DC, *LexicalDC;
3192 DeclarationName Name;
3193 SourceLocation Loc;
3194 NamedDecl *FoundD;
3195 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3196 return std::move(Err);
3197 if (FoundD)
3198 return FoundD;
3199
3200 // If this typedef is not in block scope, determine whether we've
3201 // seen a typedef with the same name (that we can merge with) or any
3202 // other entity by that name (which name lookup could conflict with).
3203 if (!DC->isFunctionOrMethod()) {
3204 SmallVector<NamedDecl *, 4> ConflictingDecls;
3205 unsigned IDNS = Decl::IDNS_Ordinary;
3206 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3207 for (auto *FoundDecl : FoundDecls) {
3208 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3209 continue;
3210 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3211 if (IsStructuralMatch(D, FoundAlias))
3212 return Importer.MapImported(D, FoundAlias);
3213 ConflictingDecls.push_back(FoundDecl);
3214 }
3215 }
3216
3217 if (!ConflictingDecls.empty()) {
3218 ExpectedName NameOrErr = Importer.HandleNameConflict(
3219 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3220 if (NameOrErr)
3221 Name = NameOrErr.get();
3222 else
3223 return NameOrErr.takeError();
3224 }
3225 }
3226
3227 Error Err = Error::success();
3228 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3229 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3230 if (Err)
3231 return std::move(Err);
3232
3233 TypeAliasTemplateDecl *ToAlias;
3234 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3235 Name, ToTemplateParameters, ToTemplatedDecl))
3236 return ToAlias;
3237
3238 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3239
3240 ToAlias->setAccess(D->getAccess());
3241 ToAlias->setLexicalDeclContext(LexicalDC);
3242 LexicalDC->addDeclInternal(ToAlias);
3243 if (DC != Importer.getToContext().getTranslationUnitDecl())
3244 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3245 return ToAlias;
3246}
3247
3249 // Import the major distinguishing characteristics of this label.
3250 DeclContext *DC, *LexicalDC;
3251 DeclarationName Name;
3252 SourceLocation Loc;
3253 NamedDecl *ToD;
3254 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3255 return std::move(Err);
3256 if (ToD)
3257 return ToD;
3258
3259 assert(LexicalDC->isFunctionOrMethod());
3260
3261 LabelDecl *ToLabel;
3262 if (D->isGnuLocal()) {
3263 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3264 if (!BeginLocOrErr)
3265 return BeginLocOrErr.takeError();
3266 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3267 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3268 return ToLabel;
3269
3270 } else {
3271 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3272 Name.getAsIdentifierInfo()))
3273 return ToLabel;
3274
3275 }
3276
3277 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3278 if (!ToStmtOrErr)
3279 return ToStmtOrErr.takeError();
3280
3281 ToLabel->setStmt(*ToStmtOrErr);
3282 ToLabel->setLexicalDeclContext(LexicalDC);
3283 LexicalDC->addDeclInternal(ToLabel);
3284 return ToLabel;
3285}
3286
3288 // Import the major distinguishing characteristics of this enum.
3289 DeclContext *DC, *LexicalDC;
3290 DeclarationName Name;
3291 SourceLocation Loc;
3292 NamedDecl *ToD;
3293 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3294 return std::move(Err);
3295 if (ToD)
3296 return ToD;
3297
3298 // Figure out what enum name we're looking for.
3299 unsigned IDNS = Decl::IDNS_Tag;
3300 DeclarationName SearchName = Name;
3301 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3302 if (Error Err = importInto(
3303 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3304 return std::move(Err);
3305 IDNS = Decl::IDNS_Ordinary;
3306 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3307 IDNS |= Decl::IDNS_Ordinary;
3308
3309 // We may already have an enum of the same name; try to find and match it.
3310 EnumDecl *PrevDecl = nullptr;
3311 if (!DC->isFunctionOrMethod()) {
3312 SmallVector<NamedDecl *, 4> ConflictingDecls;
3313 auto FoundDecls =
3314 Importer.findDeclsInToCtx(DC, SearchName);
3315 for (auto *FoundDecl : FoundDecls) {
3316 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3317 continue;
3318
3319 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3320 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3321 FoundDecl = Tag->getDecl();
3322 }
3323
3324 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3325 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3326 continue;
3327 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3328 EnumDecl *FoundDef = FoundEnum->getDefinition();
3329 if (D->isThisDeclarationADefinition() && FoundDef)
3330 return Importer.MapImported(D, FoundDef);
3331 PrevDecl = FoundEnum->getMostRecentDecl();
3332 break;
3333 }
3334 ConflictingDecls.push_back(FoundDecl);
3335 }
3336 }
3337
3338 // In case of unnamed enums, we try to find an existing similar one, if none
3339 // was found, perform the import always.
3340 // Structural in-equivalence is not detected in this way here, but it may
3341 // be found when the parent decl is imported (if the enum is part of a
3342 // class). To make this totally exact a more difficult solution is needed.
3343 if (SearchName && !ConflictingDecls.empty()) {
3344 ExpectedName NameOrErr = Importer.HandleNameConflict(
3345 SearchName, DC, IDNS, ConflictingDecls.data(),
3346 ConflictingDecls.size());
3347 if (NameOrErr)
3348 Name = NameOrErr.get();
3349 else
3350 return NameOrErr.takeError();
3351 }
3352 }
3353
3354 Error Err = Error::success();
3355 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3356 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3357 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3358 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3359 if (Err)
3360 return std::move(Err);
3361
3362 // Create the enum declaration.
3363 EnumDecl *D2;
3364 if (GetImportedOrCreateDecl(
3365 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3366 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3367 D->isScopedUsingClassTag(), D->isFixed()))
3368 return D2;
3369
3370 D2->setQualifierInfo(ToQualifierLoc);
3371 D2->setIntegerType(ToIntegerType);
3372 D2->setBraceRange(ToBraceRange);
3373 D2->setAccess(D->getAccess());
3374 D2->setLexicalDeclContext(LexicalDC);
3375 addDeclToContexts(D, D2);
3376
3378 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3379 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3380 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3381 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3382 else
3383 return ToInstOrErr.takeError();
3384 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3386 else
3387 return POIOrErr.takeError();
3388 }
3389
3390 // Import the definition
3391 if (D->isCompleteDefinition())
3392 if (Error Err = ImportDefinition(D, D2))
3393 return std::move(Err);
3394
3395 return D2;
3396}
3397
3399 bool IsFriendTemplate = false;
3400 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3401 IsFriendTemplate =
3402 DCXX->getDescribedClassTemplate() &&
3403 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3405 }
3406
3407 // Import the major distinguishing characteristics of this record.
3408 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3409 DeclarationName Name;
3410 SourceLocation Loc;
3411 NamedDecl *ToD = nullptr;
3412 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3413 return std::move(Err);
3414 if (ToD)
3415 return ToD;
3416
3417 // Figure out what structure name we're looking for.
3418 unsigned IDNS = Decl::IDNS_Tag;
3419 DeclarationName SearchName = Name;
3420 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3421 if (Error Err = importInto(
3422 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3423 return std::move(Err);
3424 IDNS = Decl::IDNS_Ordinary;
3425 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3427
3428 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3429 : DC->isDependentContext();
3430 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3431
3432 // We may already have a record of the same name; try to find and match it.
3433 RecordDecl *PrevDecl = nullptr;
3434 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3435 SmallVector<NamedDecl *, 4> ConflictingDecls;
3436 auto FoundDecls =
3437 Importer.findDeclsInToCtx(DC, SearchName);
3438 if (!FoundDecls.empty()) {
3439 // We're going to have to compare D against potentially conflicting Decls,
3440 // so complete it.
3443 }
3444
3445 for (auto *FoundDecl : FoundDecls) {
3446 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3447 continue;
3448
3449 Decl *Found = FoundDecl;
3450 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3451 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3452 Found = Tag->getDecl();
3453 }
3454
3455 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3456 // Do not emit false positive diagnostic in case of unnamed
3457 // struct/union and in case of anonymous structs. Would be false
3458 // because there may be several anonymous/unnamed structs in a class.
3459 // E.g. these are both valid:
3460 // struct A { // unnamed structs
3461 // struct { struct A *next; } entry0;
3462 // struct { struct A *next; } entry1;
3463 // };
3464 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3465 if (!SearchName)
3466 if (!IsStructuralMatch(D, FoundRecord, false))
3467 continue;
3468
3469 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3470 continue;
3471
3472 if (IsStructuralMatch(D, FoundRecord)) {
3473 RecordDecl *FoundDef = FoundRecord->getDefinition();
3474 if (D->isThisDeclarationADefinition() && FoundDef) {
3475 // FIXME: Structural equivalence check should check for same
3476 // user-defined methods.
3477 Importer.MapImported(D, FoundDef);
3478 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3479 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3480 assert(FoundCXX && "Record type mismatch");
3481
3482 if (!Importer.isMinimalImport())
3483 // FoundDef may not have every implicit method that D has
3484 // because implicit methods are created only if they are used.
3485 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3486 return std::move(Err);
3487 }
3488 // FIXME: We can return FoundDef here.
3489 }
3490 PrevDecl = FoundRecord->getMostRecentDecl();
3491 break;
3492 }
3493 ConflictingDecls.push_back(FoundDecl);
3494 } // kind is RecordDecl
3495 } // for
3496
3497 if (!ConflictingDecls.empty() && SearchName) {
3498 ExpectedName NameOrErr = Importer.HandleNameConflict(
3499 SearchName, DC, IDNS, ConflictingDecls.data(),
3500 ConflictingDecls.size());
3501 if (NameOrErr)
3502 Name = NameOrErr.get();
3503 else
3504 return NameOrErr.takeError();
3505 }
3506 }
3507
3508 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3509 if (!BeginLocOrErr)
3510 return BeginLocOrErr.takeError();
3511
3512 // Create the record declaration.
3513 RecordDecl *D2 = nullptr;
3514 CXXRecordDecl *D2CXX = nullptr;
3515 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3516 if (DCXX->isLambda()) {
3517 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3518 if (!TInfoOrErr)
3519 return TInfoOrErr.takeError();
3520 if (GetImportedOrCreateSpecialDecl(
3521 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3522 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3523 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3524 return D2CXX;
3525 Decl *ContextDecl = DCXX->getLambdaContextDecl();
3526 ExpectedDecl CDeclOrErr = import(ContextDecl);
3527 if (!CDeclOrErr)
3528 return CDeclOrErr.takeError();
3529 if (ContextDecl != nullptr) {
3530 D2CXX->setLambdaContextDecl(*CDeclOrErr);
3531 }
3532 D2CXX->setLambdaNumbering(DCXX->getLambdaNumbering());
3533 } else {
3534 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3535 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3536 Name.getAsIdentifierInfo(),
3537 cast_or_null<CXXRecordDecl>(PrevDecl)))
3538 return D2CXX;
3539 }
3540
3541 D2 = D2CXX;
3542 D2->setAccess(D->getAccess());
3543 D2->setLexicalDeclContext(LexicalDC);
3544 addDeclToContexts(D, D2);
3545
3546 if (ClassTemplateDecl *FromDescribed =
3547 DCXX->getDescribedClassTemplate()) {
3548 ClassTemplateDecl *ToDescribed;
3549 if (Error Err = importInto(ToDescribed, FromDescribed))
3550 return std::move(Err);
3551 D2CXX->setDescribedClassTemplate(ToDescribed);
3552 } else if (MemberSpecializationInfo *MemberInfo =
3553 DCXX->getMemberSpecializationInfo()) {
3555 MemberInfo->getTemplateSpecializationKind();
3557
3558 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3559 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3560 else
3561 return ToInstOrErr.takeError();
3562
3563 if (ExpectedSLoc POIOrErr =
3564 import(MemberInfo->getPointOfInstantiation()))
3566 *POIOrErr);
3567 else
3568 return POIOrErr.takeError();
3569 }
3570
3571 } else {
3572 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3573 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3574 Name.getAsIdentifierInfo(), PrevDecl))
3575 return D2;
3576 D2->setLexicalDeclContext(LexicalDC);
3577 addDeclToContexts(D, D2);
3578 }
3579
3580 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3581 D2->setBraceRange(*BraceRangeOrErr);
3582 else
3583 return BraceRangeOrErr.takeError();
3584 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3585 D2->setQualifierInfo(*QualifierLocOrErr);
3586 else
3587 return QualifierLocOrErr.takeError();
3588
3589 if (D->isAnonymousStructOrUnion())
3590 D2->setAnonymousStructOrUnion(true);
3591
3592 if (D->isCompleteDefinition())
3593 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3594 return std::move(Err);
3595
3596 return D2;
3597}
3598
3600 // Import the major distinguishing characteristics of this enumerator.
3601 DeclContext *DC, *LexicalDC;
3602 DeclarationName Name;
3603 SourceLocation Loc;
3604 NamedDecl *ToD;
3605 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3606 return std::move(Err);
3607 if (ToD)
3608 return ToD;
3609
3610 // Determine whether there are any other declarations with the same name and
3611 // in the same context.
3612 if (!LexicalDC->isFunctionOrMethod()) {
3613 SmallVector<NamedDecl *, 4> ConflictingDecls;
3614 unsigned IDNS = Decl::IDNS_Ordinary;
3615 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3616 for (auto *FoundDecl : FoundDecls) {
3617 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3618 continue;
3619
3620 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3621 if (IsStructuralMatch(D, FoundEnumConstant))
3622 return Importer.MapImported(D, FoundEnumConstant);
3623 ConflictingDecls.push_back(FoundDecl);
3624 }
3625 }
3626
3627 if (!ConflictingDecls.empty()) {
3628 ExpectedName NameOrErr = Importer.HandleNameConflict(
3629 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3630 if (NameOrErr)
3631 Name = NameOrErr.get();
3632 else
3633 return NameOrErr.takeError();
3634 }
3635 }
3636
3637 ExpectedType TypeOrErr = import(D->getType());
3638 if (!TypeOrErr)
3639 return TypeOrErr.takeError();
3640
3641 ExpectedExpr InitOrErr = import(D->getInitExpr());
3642 if (!InitOrErr)
3643 return InitOrErr.takeError();
3644
3645 EnumConstantDecl *ToEnumerator;
3646 if (GetImportedOrCreateDecl(
3647 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3648 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3649 return ToEnumerator;
3650
3651 ToEnumerator->setAccess(D->getAccess());
3652 ToEnumerator->setLexicalDeclContext(LexicalDC);
3653 LexicalDC->addDeclInternal(ToEnumerator);
3654 return ToEnumerator;
3655}
3656
3657template <typename DeclTy>
3659 DeclTy *ToD) {
3661 FromD->getTemplateParameterLists();
3662 if (FromTPLs.empty())
3663 return Error::success();
3664 SmallVector<TemplateParameterList *, 2> ToTPLists(FromTPLs.size());
3665 for (unsigned int I = 0; I < FromTPLs.size(); ++I)
3666 if (Expected<TemplateParameterList *> ToTPListOrErr = import(FromTPLs[I]))
3667 ToTPLists[I] = *ToTPListOrErr;
3668 else
3669 return ToTPListOrErr.takeError();
3670 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3671 return Error::success();
3672}
3673
3675 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3676 switch (FromFD->getTemplatedKind()) {
3679 return Error::success();
3680
3682 if (Expected<FunctionDecl *> InstFDOrErr =
3683 import(FromFD->getInstantiatedFromDecl()))
3684 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3685 return Error::success();
3688
3689 if (Expected<FunctionDecl *> InstFDOrErr =
3690 import(FromFD->getInstantiatedFromMemberFunction()))
3691 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3692 else
3693 return InstFDOrErr.takeError();
3694
3695 if (ExpectedSLoc POIOrErr = import(
3698 else
3699 return POIOrErr.takeError();
3700
3701 return Error::success();
3702 }
3703
3705 auto FunctionAndArgsOrErr =
3707 if (!FunctionAndArgsOrErr)
3708 return FunctionAndArgsOrErr.takeError();
3709
3711 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3712
3713 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3714 TemplateArgumentListInfo ToTAInfo;
3715 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3716 if (FromTAArgsAsWritten)
3718 *FromTAArgsAsWritten, ToTAInfo))
3719 return Err;
3720
3721 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3722 if (!POIOrErr)
3723 return POIOrErr.takeError();
3724
3725 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3726 return Err;
3727
3728 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3729 ToFD->setFunctionTemplateSpecialization(
3730 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3731 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3732 return Error::success();
3733 }
3734
3736 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3737 UnresolvedSet<8> Candidates;
3738 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3739 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3740 Candidates.addDecl(*ToFTDOrErr);
3741 else
3742 return ToFTDOrErr.takeError();
3743 }
3744
3745 // Import TemplateArgumentListInfo.
3746 TemplateArgumentListInfo ToTAInfo;
3747 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3748 if (FromTAArgsAsWritten)
3749 if (Error Err =
3750 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3751 return Err;
3752
3754 Importer.getToContext(), Candidates,
3755 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3756 return Error::success();
3757 }
3758 }
3759 llvm_unreachable("All cases should be covered!");
3760}
3761
3764 auto FunctionAndArgsOrErr =
3766 if (!FunctionAndArgsOrErr)
3767 return FunctionAndArgsOrErr.takeError();
3768
3770 TemplateArgsTy ToTemplArgs;
3771 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3772 void *InsertPos = nullptr;
3773 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3774 return FoundSpec;
3775}
3776
3778 FunctionDecl *ToFD) {
3779 if (Stmt *FromBody = FromFD->getBody()) {
3780 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3781 ToFD->setBody(*ToBodyOrErr);
3782 else
3783 return ToBodyOrErr.takeError();
3784 }
3785 return Error::success();
3786}
3787
3789ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3790 Expr *ExplicitExpr = ESpec.getExpr();
3791 if (ExplicitExpr)
3792 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3793 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3794}
3795
3797
3799 auto RedeclIt = Redecls.begin();
3800 // Import the first part of the decl chain. I.e. import all previous
3801 // declarations starting from the canonical decl.
3802 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3803 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3804 if (!ToRedeclOrErr)
3805 return ToRedeclOrErr.takeError();
3806 }
3807 assert(*RedeclIt == D);
3808
3809 // Import the major distinguishing characteristics of this function.
3810 DeclContext *DC, *LexicalDC;
3811 DeclarationName Name;
3812 SourceLocation Loc;
3813 NamedDecl *ToD;
3814 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3815 return std::move(Err);
3816 if (ToD)
3817 return ToD;
3818
3819 FunctionDecl *FoundByLookup = nullptr;
3821
3822 // If this is a function template specialization, then try to find the same
3823 // existing specialization in the "to" context. The lookup below will not
3824 // find any specialization, but would find the primary template; thus, we
3825 // have to skip normal lookup in case of specializations.
3826 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3827 if (D->getTemplatedKind() ==
3829 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3830 if (!FoundFunctionOrErr)
3831 return FoundFunctionOrErr.takeError();
3832 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3833 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3834 return Def;
3835 FoundByLookup = FoundFunction;
3836 }
3837 }
3838 // Try to find a function in our own ("to") context with the same name, same
3839 // type, and in the same context as the function we're importing.
3840 else if (!LexicalDC->isFunctionOrMethod()) {
3841 SmallVector<NamedDecl *, 4> ConflictingDecls;
3843 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3844 for (auto *FoundDecl : FoundDecls) {
3845 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3846 continue;
3847
3848 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3849 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3850 continue;
3851
3852 if (IsStructuralMatch(D, FoundFunction)) {
3853 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3854 return Def;
3855 FoundByLookup = FoundFunction;
3856 break;
3857 }
3858 // FIXME: Check for overloading more carefully, e.g., by boosting
3859 // Sema::IsOverload out to the AST library.
3860
3861 // Function overloading is okay in C++.
3862 if (Importer.getToContext().getLangOpts().CPlusPlus)
3863 continue;
3864
3865 // Complain about inconsistent function types.
3866 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3867 << Name << D->getType() << FoundFunction->getType();
3868 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3869 << FoundFunction->getType();
3870 ConflictingDecls.push_back(FoundDecl);
3871 }
3872 }
3873
3874 if (!ConflictingDecls.empty()) {
3875 ExpectedName NameOrErr = Importer.HandleNameConflict(
3876 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3877 if (NameOrErr)
3878 Name = NameOrErr.get();
3879 else
3880 return NameOrErr.takeError();
3881 }
3882 }
3883
3884 // We do not allow more than one in-class declaration of a function. This is
3885 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3886 // assumes there is only one in-class declaration. Building a redecl
3887 // chain would result in more than one in-class declaration for
3888 // overrides (even if they are part of the same redecl chain inside the
3889 // derived class.)
3890 if (FoundByLookup) {
3891 if (isa<CXXMethodDecl>(FoundByLookup)) {
3892 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3893 if (!D->doesThisDeclarationHaveABody()) {
3894 if (FunctionTemplateDecl *DescribedD =
3896 // Handle a "templated" function together with its described
3897 // template. This avoids need for a similar check at import of the
3898 // described template.
3899 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3900 "Templated function mapped to non-templated?");
3901 Importer.MapImported(DescribedD,
3902 FoundByLookup->getDescribedFunctionTemplate());
3903 }
3904 return Importer.MapImported(D, FoundByLookup);
3905 } else {
3906 // Let's continue and build up the redecl chain in this case.
3907 // FIXME Merge the functions into one decl.
3908 }
3909 }
3910 }
3911 }
3912
3913 DeclarationNameInfo NameInfo(Name, Loc);
3914 // Import additional name location/type info.
3915 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3916 return std::move(Err);
3917
3918 QualType FromTy = D->getType();
3919 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3920 // Set to true if we do not import the type of the function as is. There are
3921 // cases when the original type would result in an infinite recursion during
3922 // the import. To avoid an infinite recursion when importing, we create the
3923 // FunctionDecl with a simplified function type and update it only after the
3924 // relevant AST nodes are already imported.
3925 // The type is related to TypeSourceInfo (it references the type), so we must
3926 // do the same with TypeSourceInfo.
3927 bool UsedDifferentProtoType = false;
3928 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3929 QualType FromReturnTy = FromFPT->getReturnType();
3930 // Functions with auto return type may define a struct inside their body
3931 // and the return type could refer to that struct.
3932 // E.g.: auto foo() { struct X{}; return X(); }
3933 // There are many more cases when types inside the function declaration
3934 // can appear in the return type, like types declared as typenames from
3935 // template params.
3936 // All such cases are tracked in FindFunctionDeclImportCycle.
3937 if (Importer.FindFunctionDeclImportCycle.isCycle(D)) {
3938 FromReturnTy = Importer.getFromContext().VoidTy;
3939 UsedDifferentProtoType = true;
3940 }
3941 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3942 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3943 // FunctionDecl that we are importing the FunctionProtoType for.
3944 // To avoid an infinite recursion when importing, create the FunctionDecl
3945 // with a simplified function type.
3946 if (FromEPI.ExceptionSpec.SourceDecl ||
3947 FromEPI.ExceptionSpec.SourceTemplate ||
3948 FromEPI.ExceptionSpec.NoexceptExpr) {
3950 FromEPI = DefaultEPI;
3951 UsedDifferentProtoType = true;
3952 }
3953 FromTy = Importer.getFromContext().getFunctionType(
3954 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3955 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3956 FromTy, D->getBeginLoc());
3957 }
3958
3959 Error Err = Error::success();
3960 auto ScopedReturnTypeDeclCycleDetector =
3961 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
3962 auto T = importChecked(Err, FromTy);
3963 auto TInfo = importChecked(Err, FromTSI);
3964 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3965 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3966 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3967 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3968 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
3969 TrailingRequiresClause.ConstraintExpr =
3970 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
3971 if (Err)
3972 return std::move(Err);
3973
3974 // Import the function parameters.
3976 for (auto *P : D->parameters()) {
3977 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3978 Parameters.push_back(*ToPOrErr);
3979 else
3980 return ToPOrErr.takeError();
3981 }
3982
3983 // Create the imported function.
3984 FunctionDecl *ToFunction = nullptr;
3985 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3986 ExplicitSpecifier ESpec =
3987 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3988 if (Err)
3989 return std::move(Err);
3990 auto ToInheritedConstructor = InheritedConstructor();
3991 if (FromConstructor->isInheritingConstructor()) {
3992 Expected<InheritedConstructor> ImportedInheritedCtor =
3993 import(FromConstructor->getInheritedConstructor());
3994 if (!ImportedInheritedCtor)
3995 return ImportedInheritedCtor.takeError();
3996 ToInheritedConstructor = *ImportedInheritedCtor;
3997 }
3998 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3999 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4000 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4002 ToInheritedConstructor, TrailingRequiresClause))
4003 return ToFunction;
4004 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4005
4006 Error Err = Error::success();
4007 auto ToOperatorDelete = importChecked(
4008 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4009 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4010 if (Err)
4011 return std::move(Err);
4012
4013 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4014 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4015 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4017 TrailingRequiresClause))
4018 return ToFunction;
4019
4020 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4021
4022 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4023 } else if (CXXConversionDecl *FromConversion =
4024 dyn_cast<CXXConversionDecl>(D)) {
4025 ExplicitSpecifier ESpec =
4026 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4027 if (Err)
4028 return std::move(Err);
4029 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4030 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4031 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4032 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4033 SourceLocation(), TrailingRequiresClause))
4034 return ToFunction;
4035 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4036 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4037 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4038 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4039 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4040 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4041 return ToFunction;
4042 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4043 ExplicitSpecifier ESpec =
4044 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4045 CXXConstructorDecl *Ctor =
4046 importChecked(Err, Guide->getCorrespondingConstructor());
4047 const CXXDeductionGuideDecl *SourceDG =
4048 importChecked(Err, Guide->getSourceDeductionGuide());
4049 if (Err)
4050 return std::move(Err);
4051 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4052 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4053 NameInfo, T, TInfo, ToEndLoc, Ctor,
4054 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4055 SourceDG, Guide->getSourceDeductionGuideKind()))
4056 return ToFunction;
4057 } else {
4058 if (GetImportedOrCreateDecl(
4059 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4060 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4062 D->getConstexprKind(), TrailingRequiresClause))
4063 return ToFunction;
4064 }
4065
4066 // Connect the redecl chain.
4067 if (FoundByLookup) {
4068 auto *Recent = const_cast<FunctionDecl *>(
4069 FoundByLookup->getMostRecentDecl());
4070 ToFunction->setPreviousDecl(Recent);
4071 // FIXME Probably we should merge exception specifications. E.g. In the
4072 // "To" context the existing function may have exception specification with
4073 // noexcept-unevaluated, while the newly imported function may have an
4074 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4075 // decl and its redeclarations may be required.
4076 }
4077
4078 // We will import DefaultedOrDeletedInfo later.
4079
4080 ToFunction->setQualifierInfo(ToQualifierLoc);
4081 ToFunction->setAccess(D->getAccess());
4082 ToFunction->setLexicalDeclContext(LexicalDC);
4083 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4084 ToFunction->setTrivial(D->isTrivial());
4085 ToFunction->setIsPureVirtual(D->isPureVirtual());
4086 ToFunction->setDefaulted(D->isDefaulted());
4088 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4094 ToFunction->setRangeEnd(ToEndLoc);
4095 ToFunction->setDefaultLoc(ToDefaultLoc);
4096
4097 if (auto *Info = D->getDefaultedOrDeletedInfo()) {
4098 StringLiteral *Msg = nullptr;
4099 if (StringLiteral *M = Info->getDeletedMessage()) {
4100 auto Imported = import(M);
4101 if (!Imported)
4102 return Imported.takeError();
4103 Msg = *Imported;
4104 }
4105
4107 for (DeclAccessPair P : Info->getUnqualifiedLookups()) {
4108 auto Imported = import(P.getDecl());
4109 if (!Imported)
4110 return Imported.takeError();
4111 Lookups.push_back(
4113 }
4114
4115 ToFunction->setDefaultedOrDeletedInfo(
4117 Importer.getToContext(), Lookups, Info->getFPFeatures(), Msg));
4118 }
4119
4120 // Set the parameters.
4121 for (auto *Param : Parameters) {
4122 Param->setOwningFunction(ToFunction);
4123 ToFunction->addDeclInternal(Param);
4124 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4125 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4126 }
4127 ToFunction->setParams(Parameters);
4128
4129 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4130 // params it refers to.
4131 if (TInfo) {
4132 if (auto ProtoLoc =
4133 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4134 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4135 ProtoLoc.setParam(I, Parameters[I]);
4136 }
4137 }
4138
4139 // Import the describing template function, if any.
4140 if (FromFT) {
4141 auto ToFTOrErr = import(FromFT);
4142 if (!ToFTOrErr)
4143 return ToFTOrErr.takeError();
4144 }
4145
4146 // Import Ctor initializers.
4147 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4148 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4149 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4150 // Import first, then allocate memory and copy if there was no error.
4151 if (Error Err = ImportContainerChecked(
4152 FromConstructor->inits(), CtorInitializers))
4153 return std::move(Err);
4154 auto **Memory =
4155 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4156 llvm::copy(CtorInitializers, Memory);
4157 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4158 ToCtor->setCtorInitializers(Memory);
4159 ToCtor->setNumCtorInitializers(NumInitializers);
4160 }
4161 }
4162
4163 // If it is a template, import all related things.
4164 if (Error Err = ImportTemplateInformation(D, ToFunction))
4165 return std::move(Err);
4166
4167 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4169 FromCXXMethod))
4170 return std::move(Err);
4171
4173 Error Err = ImportFunctionDeclBody(D, ToFunction);
4174
4175 if (Err)
4176 return std::move(Err);
4177 }
4178
4179 // Import and set the original type in case we used another type.
4180 if (UsedDifferentProtoType) {
4181 if (ExpectedType TyOrErr = import(D->getType()))
4182 ToFunction->setType(*TyOrErr);
4183 else
4184 return TyOrErr.takeError();
4185 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4186 ToFunction->setTypeSourceInfo(*TSIOrErr);
4187 else
4188 return TSIOrErr.takeError();
4189 }
4190
4191 // FIXME: Other bits to merge?
4192
4193 addDeclToContexts(D, ToFunction);
4194
4195 // Import the rest of the chain. I.e. import all subsequent declarations.
4196 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4197 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4198 if (!ToRedeclOrErr)
4199 return ToRedeclOrErr.takeError();
4200 }
4201
4202 return ToFunction;
4203}
4204
4208
4212
4216
4220
4225
4227 // Import the major distinguishing characteristics of a variable.
4228 DeclContext *DC, *LexicalDC;
4229 DeclarationName Name;
4230 SourceLocation Loc;
4231 NamedDecl *ToD;
4232 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4233 return std::move(Err);
4234 if (ToD)
4235 return ToD;
4236
4237 // Determine whether we've already imported this field.
4238 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4239 for (auto *FoundDecl : FoundDecls) {
4240 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4241 // For anonymous fields, match up by index.
4242 if (!Name &&
4244 ASTImporter::getFieldIndex(FoundField))
4245 continue;
4246
4247 if (Importer.IsStructurallyEquivalent(D->getType(),
4248 FoundField->getType())) {
4249 Importer.MapImported(D, FoundField);
4250 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4251 // initializer of a FieldDecl might not had been instantiated in the
4252 // "To" context. However, the "From" context might instantiated that,
4253 // thus we have to merge that.
4254 // Note: `hasInClassInitializer()` is not the same as non-null
4255 // `getInClassInitializer()` value.
4256 if (Expr *FromInitializer = D->getInClassInitializer()) {
4257 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4258 // Import of the FromInitializer may result in the setting of
4259 // InClassInitializer. If not, set it here.
4260 assert(FoundField->hasInClassInitializer() &&
4261 "Field should have an in-class initializer if it has an "
4262 "expression for it.");
4263 if (!FoundField->getInClassInitializer())
4264 FoundField->setInClassInitializer(*ToInitializerOrErr);
4265 } else {
4266 return ToInitializerOrErr.takeError();
4267 }
4268 }
4269 return FoundField;
4270 }
4271
4272 // FIXME: Why is this case not handled with calling HandleNameConflict?
4273 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4274 << Name << D->getType() << FoundField->getType();
4275 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4276 << FoundField->getType();
4277
4278 return make_error<ASTImportError>(ASTImportError::NameConflict);
4279 }
4280 }
4281
4282 Error Err = Error::success();
4283 auto ToType = importChecked(Err, D->getType());
4284 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4285 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4286 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4287 if (Err)
4288 return std::move(Err);
4289 const Type *ToCapturedVLAType = nullptr;
4290 if (Error Err = Importer.importInto(
4291 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4292 return std::move(Err);
4293
4294 FieldDecl *ToField;
4295 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4296 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4297 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4298 D->getInClassInitStyle()))
4299 return ToField;
4300
4301 ToField->setAccess(D->getAccess());
4302 ToField->setLexicalDeclContext(LexicalDC);
4303 ToField->setImplicit(D->isImplicit());
4304 if (ToCapturedVLAType)
4305 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4306 LexicalDC->addDeclInternal(ToField);
4307 // Import initializer only after the field was created, it may have recursive
4308 // reference to the field.
4309 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4310 if (Err)
4311 return std::move(Err);
4312 if (ToInitializer) {
4313 auto *AlreadyImported = ToField->getInClassInitializer();
4314 if (AlreadyImported)
4315 assert(ToInitializer == AlreadyImported &&
4316 "Duplicate import of in-class initializer.");
4317 else
4318 ToField->setInClassInitializer(ToInitializer);
4319 }
4320
4321 return ToField;
4322}
4323
4325 // Import the major distinguishing characteristics of a variable.
4326 DeclContext *DC, *LexicalDC;
4327 DeclarationName Name;
4328 SourceLocation Loc;
4329 NamedDecl *ToD;
4330 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4331 return std::move(Err);
4332 if (ToD)
4333 return ToD;
4334
4335 // Determine whether we've already imported this field.
4336 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4337 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4338 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4339 // For anonymous indirect fields, match up by index.
4340 if (!Name &&
4342 ASTImporter::getFieldIndex(FoundField))
4343 continue;
4344
4345 if (Importer.IsStructurallyEquivalent(D->getType(),
4346 FoundField->getType(),
4347 !Name.isEmpty())) {
4348 Importer.MapImported(D, FoundField);
4349 return FoundField;
4350 }
4351
4352 // If there are more anonymous fields to check, continue.
4353 if (!Name && I < N-1)
4354 continue;
4355
4356 // FIXME: Why is this case not handled with calling HandleNameConflict?
4357 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4358 << Name << D->getType() << FoundField->getType();
4359 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4360 << FoundField->getType();
4361
4362 return make_error<ASTImportError>(ASTImportError::NameConflict);
4363 }
4364 }
4365
4366 // Import the type.
4367 auto TypeOrErr = import(D->getType());
4368 if (!TypeOrErr)
4369 return TypeOrErr.takeError();
4370
4371 auto **NamedChain =
4372 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4373
4374 unsigned i = 0;
4375 for (auto *PI : D->chain())
4376 if (Expected<NamedDecl *> ToD = import(PI))
4377 NamedChain[i++] = *ToD;
4378 else
4379 return ToD.takeError();
4380
4381 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4382 IndirectFieldDecl *ToIndirectField;
4383 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4384 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4385 // FIXME here we leak `NamedChain` which is allocated before
4386 return ToIndirectField;
4387
4388 ToIndirectField->setAccess(D->getAccess());
4389 ToIndirectField->setLexicalDeclContext(LexicalDC);
4390 LexicalDC->addDeclInternal(ToIndirectField);
4391 return ToIndirectField;
4392}
4393
4394/// Used as return type of getFriendCountAndPosition.
4396 /// Number of similar looking friends.
4397 unsigned int TotalCount;
4398 /// Index of the specific FriendDecl.
4399 unsigned int IndexOfDecl;
4400};
4401
4402static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4403 FriendDecl *FD2) {
4404 if (FD1->getKind() != FD2->getKind())
4405 return false;
4406
4407 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4409 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4410 FD2->getASTContext(), NonEquivalentDecls,
4412 /*StrictTypeSpelling=*/false, /*Complain=*/false);
4413 return Ctx.IsEquivalent(FD1, FD2);
4414}
4415
4417 FriendDecl *FD) {
4418 unsigned int FriendCount = 0;
4419 UnsignedOrNone FriendPosition = std::nullopt;
4420 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4421
4422 for (FriendDecl *FoundFriend : RD->friends()) {
4423 if (FoundFriend == FD) {
4424 FriendPosition = FriendCount;
4425 ++FriendCount;
4426 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4427 ++FriendCount;
4428 }
4429 }
4430
4431 assert(FriendPosition && "Friend decl not found in own parent.");
4432 return {FriendCount, *FriendPosition};
4433}
4434
4435Expected<FriendDecl::FriendUnion>
4436ASTNodeImporter::importFriendUnion(FriendDecl *D) {
4437 if (NamedDecl *FriendD = D->getFriendDecl()) {
4438 NamedDecl *ToFriendD;
4439 if (Error Err = importInto(ToFriendD, FriendD))
4440 return std::move(Err);
4441
4442 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4443 !FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))
4444 ToFriendD->setObjectOfFriendDecl(false);
4445
4446 return ToFriendD;
4447 }
4448
4449 // The friend is a type, not a decl.
4450 auto TSIOrErr = import(D->getFriendType());
4451 if (TSIOrErr)
4452 return *TSIOrErr;
4453 return TSIOrErr.takeError();
4454}
4455
4457 // Import the major distinguishing characteristics of a declaration.
4458 DeclContext *DC, *LexicalDC;
4459 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4460 return std::move(Err);
4461
4462 // Determine whether we've already imported this decl.
4463 // FriendDecl is not a NamedDecl so we cannot use lookup.
4464 // We try to maintain order and count of redundant friend declarations.
4465 const auto *RD = cast<CXXRecordDecl>(DC);
4466 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4467 for (FriendDecl *ImportedFriend : RD->friends())
4468 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4469 ImportedEquivalentFriends.push_back(ImportedFriend);
4470
4471 FriendCountAndPosition CountAndPosition =
4472 getFriendCountAndPosition(Importer, D);
4473
4474 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4475 "Class with non-matching friends is imported, ODR check wrong?");
4476 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4477 return Importer.MapImported(
4478 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4479
4480 // Not found. Create it.
4481 // The declarations will be put into order later by ImportDeclContext.
4482 auto ToFUOrErr = importFriendUnion(D);
4483 if (!ToFUOrErr)
4484 return ToFUOrErr.takeError();
4485 FriendDecl::FriendUnion ToFU = *ToFUOrErr;
4486
4487 auto LocationOrErr = import(D->getLocation());
4488 if (!LocationOrErr)
4489 return LocationOrErr.takeError();
4490 auto FriendLocOrErr = import(D->getFriendLoc());
4491 if (!FriendLocOrErr)
4492 return FriendLocOrErr.takeError();
4493 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4494 if (!EllipsisLocOrErr)
4495 return EllipsisLocOrErr.takeError();
4496
4497 FriendDecl *FrD;
4498 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4499 *LocationOrErr, ToFU, *FriendLocOrErr,
4500 *EllipsisLocOrErr))
4501 return FrD;
4502
4503 FrD->setAccess(D->getAccess());
4504 FrD->setLexicalDeclContext(LexicalDC);
4505 LexicalDC->addDeclInternal(FrD);
4506 return FrD;
4507}
4508
4510 DeclContext *DC, *LexicalDC;
4511 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4512 return std::move(Err);
4513
4514 const auto *RD = cast<CXXRecordDecl>(DC);
4515 SmallVector<FriendTemplateDecl *, 2> ImportedEquivalentFriends;
4516 for (FriendDecl *ImportedFriend : RD->friends()) {
4517 auto *ImportedFriendTemplate = dyn_cast<FriendTemplateDecl>(ImportedFriend);
4518 if (ImportedFriendTemplate &&
4519 IsEquivalentFriend(Importer, D, ImportedFriendTemplate))
4520 ImportedEquivalentFriends.push_back(ImportedFriendTemplate);
4521 }
4522
4523 FriendCountAndPosition CountAndPosition =
4524 getFriendCountAndPosition(Importer, D);
4525 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4526 "Class with non-matching friends is imported, ODR check wrong?");
4527
4528 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4529 return Importer.MapImported(
4530 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4531
4533 if (D->getFriendKind() !=
4535 auto ToFUOrErr = importFriendUnion(D);
4536 if (!ToFUOrErr)
4537 return ToFUOrErr.takeError();
4538 ToFU = *ToFUOrErr;
4539 }
4540
4541 TemplateName ToTemplate;
4542 const TemplateName FromTemplate = D->getFriendTemplateName();
4543 if (!FromTemplate.isNull()) {
4544 if (Error Err = importInto(ToTemplate, FromTemplate))
4545 return std::move(Err);
4546 }
4547
4549 SmallVector<TemplateParameterList *, 1> ToTPLs(FromTPLs.size());
4550 if (Error Err = ImportContainerChecked(FromTPLs, ToTPLs))
4551 return std::move(Err);
4552
4553 auto LocationOrErr = import(D->getLocation());
4554 if (!LocationOrErr)
4555 return LocationOrErr.takeError();
4556
4557 auto FriendLocOrErr = import(D->getFriendLoc());
4558 if (!FriendLocOrErr)
4559 return FriendLocOrErr.takeError();
4560
4561 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4562 if (!EllipsisLocOrErr)
4563 return EllipsisLocOrErr.takeError();
4564
4565 FriendTemplateDecl *FTD;
4566 if (GetImportedOrCreateDecl(FTD, D, Importer.getToContext(), DC,
4567 *LocationOrErr, ToFU, *FriendLocOrErr, ToTPLs,
4568 *EllipsisLocOrErr, ToTemplate))
4569 return FTD;
4570
4571 FTD->setAccess(D->getAccess());
4572 FTD->setLexicalDeclContext(LexicalDC);
4573 LexicalDC->addDeclInternal(FTD);
4574 return FTD;
4575}
4576
4578 // Import the major distinguishing characteristics of an ivar.
4579 DeclContext *DC, *LexicalDC;
4580 DeclarationName Name;
4581 SourceLocation Loc;
4582 NamedDecl *ToD;
4583 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4584 return std::move(Err);
4585 if (ToD)
4586 return ToD;
4587
4588 // Determine whether we've already imported this ivar
4589 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4590 for (auto *FoundDecl : FoundDecls) {
4591 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4592 if (Importer.IsStructurallyEquivalent(D->getType(),
4593 FoundIvar->getType())) {
4594 Importer.MapImported(D, FoundIvar);
4595 return FoundIvar;
4596 }
4597
4598 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4599 << Name << D->getType() << FoundIvar->getType();
4600 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4601 << FoundIvar->getType();
4602
4603 return make_error<ASTImportError>(ASTImportError::NameConflict);
4604 }
4605 }
4606
4607 Error Err = Error::success();
4608 auto ToType = importChecked(Err, D->getType());
4609 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4610 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4611 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4612 if (Err)
4613 return std::move(Err);
4614
4615 ObjCIvarDecl *ToIvar;
4616 if (GetImportedOrCreateDecl(
4617 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4618 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4619 ToType, ToTypeSourceInfo,
4620 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4621 return ToIvar;
4622
4623 ToIvar->setLexicalDeclContext(LexicalDC);
4624 LexicalDC->addDeclInternal(ToIvar);
4625 return ToIvar;
4626}
4627
4629
4631 auto RedeclIt = Redecls.begin();
4632 // Import the first part of the decl chain. I.e. import all previous
4633 // declarations starting from the canonical decl.
4634 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4635 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4636 if (!RedeclOrErr)
4637 return RedeclOrErr.takeError();
4638 }
4639 assert(*RedeclIt == D);
4640
4641 // Import the major distinguishing characteristics of a variable.
4642 DeclContext *DC, *LexicalDC;
4643 DeclarationName Name;
4644 SourceLocation Loc;
4645 NamedDecl *ToD;
4646 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4647 return std::move(Err);
4648 if (ToD)
4649 return ToD;
4650
4651 // Try to find a variable in our own ("to") context with the same name and
4652 // in the same context as the variable we're importing.
4653 VarDecl *FoundByLookup = nullptr;
4654 if (D->isFileVarDecl()) {
4655 SmallVector<NamedDecl *, 4> ConflictingDecls;
4656 unsigned IDNS = Decl::IDNS_Ordinary;
4657 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4658 for (auto *FoundDecl : FoundDecls) {
4659 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4660 continue;
4661
4662 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4663 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4664 continue;
4665 if (Importer.IsStructurallyEquivalent(D->getType(),
4666 FoundVar->getType())) {
4667
4668 // The VarDecl in the "From" context has a definition, but in the
4669 // "To" context we already have a definition.
4670 VarDecl *FoundDef = FoundVar->getDefinition();
4671 if (D->isThisDeclarationADefinition() && FoundDef)
4672 // FIXME Check for ODR error if the two definitions have
4673 // different initializers?
4674 return Importer.MapImported(D, FoundDef);
4675
4676 // The VarDecl in the "From" context has an initializer, but in the
4677 // "To" context we already have an initializer.
4678 const VarDecl *FoundDInit = nullptr;
4679 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4680 // FIXME Diagnose ODR error if the two initializers are different?
4681 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4682
4683 FoundByLookup = FoundVar;
4684 break;
4685 }
4686
4687 const ArrayType *FoundArray
4688 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4689 const ArrayType *TArray
4690 = Importer.getToContext().getAsArrayType(D->getType());
4691 if (FoundArray && TArray) {
4692 if (isa<IncompleteArrayType>(FoundArray) &&
4693 isa<ConstantArrayType>(TArray)) {
4694 // Import the type.
4695 if (auto TyOrErr = import(D->getType()))
4696 FoundVar->setType(*TyOrErr);
4697 else
4698 return TyOrErr.takeError();
4699
4700 FoundByLookup = FoundVar;
4701 break;
4702 } else if (isa<IncompleteArrayType>(TArray) &&
4703 isa<ConstantArrayType>(FoundArray)) {
4704 FoundByLookup = FoundVar;
4705 break;
4706 }
4707 }
4708
4709 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4710 << Name << D->getType() << FoundVar->getType();
4711 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4712 << FoundVar->getType();
4713 ConflictingDecls.push_back(FoundDecl);
4714 }
4715 }
4716
4717 if (!ConflictingDecls.empty()) {
4718 ExpectedName NameOrErr = Importer.HandleNameConflict(
4719 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4720 if (NameOrErr)
4721 Name = NameOrErr.get();
4722 else
4723 return NameOrErr.takeError();
4724 }
4725 }
4726
4727 Error Err = Error::success();
4728 auto ToType = importChecked(Err, D->getType());
4729 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4730 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4731 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4732 if (Err)
4733 return std::move(Err);
4734
4735 VarDecl *ToVar;
4736 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4737 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4738 if (Error Err =
4739 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4740 return std::move(Err);
4741 DecompositionDecl *ToDecomp;
4742 if (GetImportedOrCreateDecl(
4743 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4744 Loc, FromDecomp->getRSquareLoc(), ToType, ToTypeSourceInfo,
4746 return ToDecomp;
4747 ToVar = ToDecomp;
4748 } else {
4749 // Create the imported variable.
4750 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4751 ToInnerLocStart, Loc,
4752 Name.getAsIdentifierInfo(), ToType,
4753 ToTypeSourceInfo, D->getStorageClass()))
4754 return ToVar;
4755 }
4756
4757 ToVar->setTSCSpec(D->getTSCSpec());
4758 ToVar->setQualifierInfo(ToQualifierLoc);
4759 ToVar->setAccess(D->getAccess());
4760 ToVar->setLexicalDeclContext(LexicalDC);
4761 if (D->isInlineSpecified())
4762 ToVar->setInlineSpecified();
4763 if (D->isInline())
4764 ToVar->setImplicitlyInline();
4765
4766 if (FoundByLookup) {
4767 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4768 ToVar->setPreviousDecl(Recent);
4769 }
4770
4771 // Import the described template, if any.
4772 if (D->getDescribedVarTemplate()) {
4773 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4774 if (!ToVTOrErr)
4775 return ToVTOrErr.takeError();
4777 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4779 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4780 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4781 else
4782 return ToInstOrErr.takeError();
4783 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4785 else
4786 return POIOrErr.takeError();
4787 }
4788
4789 if (Error Err = ImportInitializer(D, ToVar))
4790 return std::move(Err);
4791
4792 if (D->isConstexpr())
4793 ToVar->setConstexpr(true);
4794
4795 addDeclToContexts(D, ToVar);
4796
4797 // Import the rest of the chain. I.e. import all subsequent declarations.
4798 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4799 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4800 if (!RedeclOrErr)
4801 return RedeclOrErr.takeError();
4802 }
4803
4804 return ToVar;
4805}
4806
4808 // Parameters are created in the translation unit's context, then moved
4809 // into the function declaration's context afterward.
4810 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4811
4812 Error Err = Error::success();
4813 auto ToDeclName = importChecked(Err, D->getDeclName());
4814 auto ToLocation = importChecked(Err, D->getLocation());
4815 auto ToType = importChecked(Err, D->getType());
4816 if (Err)
4817 return std::move(Err);
4818
4819 // Create the imported parameter.
4820 ImplicitParamDecl *ToParm = nullptr;
4821 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4822 ToLocation, ToDeclName.getAsIdentifierInfo(),
4823 ToType, D->getParameterKind()))
4824 return ToParm;
4825 return ToParm;
4826}
4827
4829 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4830
4831 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4832 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4833 else
4834 return LocOrErr.takeError();
4835
4837 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4838
4839 if (FromParam->hasUninstantiatedDefaultArg()) {
4840 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4841 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4842 else
4843 return ToDefArgOrErr.takeError();
4844 } else if (FromParam->hasUnparsedDefaultArg()) {
4845 ToParam->setUnparsedDefaultArg();
4846 } else if (FromParam->hasDefaultArg()) {
4847 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4848 ToParam->setDefaultArg(*ToDefArgOrErr);
4849 else
4850 return ToDefArgOrErr.takeError();
4851 }
4852
4853 return Error::success();
4854}
4855
4858 Error Err = Error::success();
4859 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4860 ConstructorUsingShadowDecl *ToShadow =
4861 importChecked(Err, From.getShadowDecl());
4862 if (Err)
4863 return std::move(Err);
4864 return InheritedConstructor(ToShadow, ToBaseCtor);
4865}
4866
4868 // Parameters are created in the translation unit's context, then moved
4869 // into the function declaration's context afterward.
4870 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4871
4872 Error Err = Error::success();
4873 auto ToDeclName = importChecked(Err, D->getDeclName());
4874 auto ToLocation = importChecked(Err, D->getLocation());
4875 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4876 auto ToType = importChecked(Err, D->getType());
4877 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4878 if (Err)
4879 return std::move(Err);
4880
4881 ParmVarDecl *ToParm;
4882 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4883 ToInnerLocStart, ToLocation,
4884 ToDeclName.getAsIdentifierInfo(), ToType,
4885 ToTypeSourceInfo, D->getStorageClass(),
4886 /*DefaultArg*/ nullptr))
4887 return ToParm;
4888
4889 // Set the default argument. It should be no problem if it was already done.
4890 // Do not import the default expression before GetImportedOrCreateDecl call
4891 // to avoid possible infinite import loop because circular dependency.
4892 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4893 return std::move(Err);
4894
4895 if (D->isObjCMethodParameter()) {
4898 } else {
4901 }
4902
4903 return ToParm;
4904}
4905
4907 // Import the major distinguishing characteristics of a method.
4908 DeclContext *DC, *LexicalDC;
4909 DeclarationName Name;
4910 SourceLocation Loc;
4911 NamedDecl *ToD;
4912 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4913 return std::move(Err);
4914 if (ToD)
4915 return ToD;
4916
4917 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4918 for (auto *FoundDecl : FoundDecls) {
4919 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4920 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4921 continue;
4922
4923 // Check return types.
4924 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4925 FoundMethod->getReturnType())) {
4926 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4927 << D->isInstanceMethod() << Name << D->getReturnType()
4928 << FoundMethod->getReturnType();
4929 Importer.ToDiag(FoundMethod->getLocation(),
4930 diag::note_odr_objc_method_here)
4931 << D->isInstanceMethod() << Name;
4932
4933 return make_error<ASTImportError>(ASTImportError::NameConflict);
4934 }
4935
4936 // Check the number of parameters.
4937 if (D->param_size() != FoundMethod->param_size()) {
4938 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4939 << D->isInstanceMethod() << Name
4940 << D->param_size() << FoundMethod->param_size();
4941 Importer.ToDiag(FoundMethod->getLocation(),
4942 diag::note_odr_objc_method_here)
4943 << D->isInstanceMethod() << Name;
4944
4945 return make_error<ASTImportError>(ASTImportError::NameConflict);
4946 }
4947
4948 // Check parameter types.
4950 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4951 P != PEnd; ++P, ++FoundP) {
4952 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4953 (*FoundP)->getType())) {
4954 Importer.FromDiag((*P)->getLocation(),
4955 diag::warn_odr_objc_method_param_type_inconsistent)
4956 << D->isInstanceMethod() << Name
4957 << (*P)->getType() << (*FoundP)->getType();
4958 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4959 << (*FoundP)->getType();
4960
4961 return make_error<ASTImportError>(ASTImportError::NameConflict);
4962 }
4963 }
4964
4965 // Check variadic/non-variadic.
4966 // Check the number of parameters.
4967 if (D->isVariadic() != FoundMethod->isVariadic()) {
4968 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4969 << D->isInstanceMethod() << Name;
4970 Importer.ToDiag(FoundMethod->getLocation(),
4971 diag::note_odr_objc_method_here)
4972 << D->isInstanceMethod() << Name;
4973
4974 return make_error<ASTImportError>(ASTImportError::NameConflict);
4975 }
4976
4977 // FIXME: Any other bits we need to merge?
4978 return Importer.MapImported(D, FoundMethod);
4979 }
4980 }
4981
4982 Error Err = Error::success();
4983 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4984 auto ToReturnType = importChecked(Err, D->getReturnType());
4985 auto ToReturnTypeSourceInfo =
4987 if (Err)
4988 return std::move(Err);
4989
4990 ObjCMethodDecl *ToMethod;
4991 if (GetImportedOrCreateDecl(
4992 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4993 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4997 return ToMethod;
4998
4999 // FIXME: When we decide to merge method definitions, we'll need to
5000 // deal with implicit parameters.
5001
5002 // Import the parameters
5004 for (auto *FromP : D->parameters()) {
5005 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5006 ToParams.push_back(*ToPOrErr);
5007 else
5008 return ToPOrErr.takeError();
5009 }
5010
5011 // Set the parameters.
5012 for (auto *ToParam : ToParams) {
5013 ToParam->setOwningFunction(ToMethod);
5014 ToMethod->addDeclInternal(ToParam);
5015 }
5016
5018 D->getSelectorLocs(FromSelLocs);
5019 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5020 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5021 return std::move(Err);
5022
5023 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5024
5025 ToMethod->setLexicalDeclContext(LexicalDC);
5026 LexicalDC->addDeclInternal(ToMethod);
5027
5028 // Implicit params are declared when Sema encounters the definition but this
5029 // never happens when the method is imported. Manually declare the implicit
5030 // params now that the MethodDecl knows its class interface.
5031 if (D->getSelfDecl())
5032 ToMethod->createImplicitParams(Importer.getToContext(),
5033 ToMethod->getClassInterface());
5034
5035 return ToMethod;
5036}
5037
5039 // Import the major distinguishing characteristics of a category.
5040 DeclContext *DC, *LexicalDC;
5041 DeclarationName Name;
5042 SourceLocation Loc;
5043 NamedDecl *ToD;
5044 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5045 return std::move(Err);
5046 if (ToD)
5047 return ToD;
5048
5049 Error Err = Error::success();
5050 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5051 auto ToLocation = importChecked(Err, D->getLocation());
5052 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5053 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5054 if (Err)
5055 return std::move(Err);
5056
5058 if (GetImportedOrCreateDecl(
5059 Result, D, Importer.getToContext(), DC, D->getVariance(),
5060 ToVarianceLoc, D->getIndex(),
5061 ToLocation, Name.getAsIdentifierInfo(),
5062 ToColonLoc, ToTypeSourceInfo))
5063 return Result;
5064
5065 // Only import 'ObjCTypeParamType' after the decl is created.
5066 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5067 if (Err)
5068 return std::move(Err);
5069 Result->setTypeForDecl(ToTypeForDecl);
5070 Result->setLexicalDeclContext(LexicalDC);
5071 return Result;
5072}
5073
5075 // Import the major distinguishing characteristics of a category.
5076 DeclContext *DC, *LexicalDC;
5077 DeclarationName Name;
5078 SourceLocation Loc;
5079 NamedDecl *ToD;
5080 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5081 return std::move(Err);
5082 if (ToD)
5083 return ToD;
5084
5085 ObjCInterfaceDecl *ToInterface;
5086 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5087 return std::move(Err);
5088
5089 // Determine if we've already encountered this category.
5090 ObjCCategoryDecl *MergeWithCategory
5091 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5092 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5093 if (!ToCategory) {
5094
5095 Error Err = Error::success();
5096 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5097 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5098 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5099 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5100 if (Err)
5101 return std::move(Err);
5102
5103 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5104 ToAtStartLoc, Loc,
5105 ToCategoryNameLoc,
5106 Name.getAsIdentifierInfo(), ToInterface,
5107 /*TypeParamList=*/nullptr,
5108 ToIvarLBraceLoc,
5109 ToIvarRBraceLoc))
5110 return ToCategory;
5111
5112 ToCategory->setLexicalDeclContext(LexicalDC);
5113 LexicalDC->addDeclInternal(ToCategory);
5114 // Import the type parameter list after MapImported, to avoid
5115 // loops when bringing in their DeclContext.
5116 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5117 ToCategory->setTypeParamList(*PListOrErr);
5118 else
5119 return PListOrErr.takeError();
5120
5121 // Import protocols
5123 SmallVector<SourceLocation, 4> ProtocolLocs;
5125 = D->protocol_loc_begin();
5127 FromProtoEnd = D->protocol_end();
5128 FromProto != FromProtoEnd;
5129 ++FromProto, ++FromProtoLoc) {
5130 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5131 Protocols.push_back(*ToProtoOrErr);
5132 else
5133 return ToProtoOrErr.takeError();
5134
5135 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5136 ProtocolLocs.push_back(*ToProtoLocOrErr);
5137 else
5138 return ToProtoLocOrErr.takeError();
5139 }
5140
5141 // FIXME: If we're merging, make sure that the protocol list is the same.
5142 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5143 ProtocolLocs.data(), Importer.getToContext());
5144
5145 } else {
5146 Importer.MapImported(D, ToCategory);
5147 }
5148
5149 // Import all of the members of this category.
5150 if (Error Err = ImportDeclContext(D))
5151 return std::move(Err);
5152
5153 // If we have an implementation, import it as well.
5154 if (D->getImplementation()) {
5155 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5156 import(D->getImplementation()))
5157 ToCategory->setImplementation(*ToImplOrErr);
5158 else
5159 return ToImplOrErr.takeError();
5160 }
5161
5162 return ToCategory;
5163}
5164
5167 if (To->getDefinition()) {
5169 if (Error Err = ImportDeclContext(From))
5170 return Err;
5171 return Error::success();
5172 }
5173
5174 // Start the protocol definition
5175 To->startDefinition();
5176
5177 // Import protocols
5179 SmallVector<SourceLocation, 4> ProtocolLocs;
5181 From->protocol_loc_begin();
5182 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5183 FromProtoEnd = From->protocol_end();
5184 FromProto != FromProtoEnd;
5185 ++FromProto, ++FromProtoLoc) {
5186 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5187 Protocols.push_back(*ToProtoOrErr);
5188 else
5189 return ToProtoOrErr.takeError();
5190
5191 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5192 ProtocolLocs.push_back(*ToProtoLocOrErr);
5193 else
5194 return ToProtoLocOrErr.takeError();
5195
5196 }
5197
5198 // FIXME: If we're merging, make sure that the protocol list is the same.
5199 To->setProtocolList(Protocols.data(), Protocols.size(),
5200 ProtocolLocs.data(), Importer.getToContext());
5201
5202 if (shouldForceImportDeclContext(Kind)) {
5203 // Import all of the members of this protocol.
5204 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5205 return Err;
5206 }
5207 return Error::success();
5208}
5209
5211 // If this protocol has a definition in the translation unit we're coming
5212 // from, but this particular declaration is not that definition, import the
5213 // definition and map to that.
5215 if (Definition && Definition != D) {
5216 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5217 return Importer.MapImported(D, *ImportedDefOrErr);
5218 else
5219 return ImportedDefOrErr.takeError();
5220 }
5221
5222 // Import the major distinguishing characteristics of a protocol.
5223 DeclContext *DC, *LexicalDC;
5224 DeclarationName Name;
5225 SourceLocation Loc;
5226 NamedDecl *ToD;
5227 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5228 return std::move(Err);
5229 if (ToD)
5230 return ToD;
5231
5232 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5233 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5234 for (auto *FoundDecl : FoundDecls) {
5235 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5236 continue;
5237
5238 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5239 break;
5240 }
5241
5242 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5243 if (!ToProto) {
5244 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5245 if (!ToAtBeginLocOrErr)
5246 return ToAtBeginLocOrErr.takeError();
5247
5248 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5249 Name.getAsIdentifierInfo(), Loc,
5250 *ToAtBeginLocOrErr,
5251 /*PrevDecl=*/nullptr))
5252 return ToProto;
5253 ToProto->setLexicalDeclContext(LexicalDC);
5254 LexicalDC->addDeclInternal(ToProto);
5255 }
5256
5257 Importer.MapImported(D, ToProto);
5258
5260 if (Error Err = ImportDefinition(D, ToProto))
5261 return std::move(Err);
5262
5263 return ToProto;
5264}
5265
5267 DeclContext *DC, *LexicalDC;
5268 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5269 return std::move(Err);
5270
5271 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5272 if (!ExternLocOrErr)
5273 return ExternLocOrErr.takeError();
5274
5275 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5276 if (!LangLocOrErr)
5277 return LangLocOrErr.takeError();
5278
5279 bool HasBraces = D->hasBraces();
5280
5281 LinkageSpecDecl *ToLinkageSpec;
5282 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5283 *ExternLocOrErr, *LangLocOrErr,
5284 D->getLanguage(), HasBraces))
5285 return ToLinkageSpec;
5286
5287 if (HasBraces) {
5288 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5289 if (!RBraceLocOrErr)
5290 return RBraceLocOrErr.takeError();
5291 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5292 }
5293
5294 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5295 LexicalDC->addDeclInternal(ToLinkageSpec);
5296
5297 return ToLinkageSpec;
5298}
5299
5301 BaseUsingDecl *ToSI) {
5302 for (UsingShadowDecl *FromShadow : D->shadows()) {
5303 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5304 ToSI->addShadowDecl(*ToShadowOrErr);
5305 else
5306 // FIXME: We return error here but the definition is already created
5307 // and available with lookups. How to fix this?..
5308 return ToShadowOrErr.takeError();
5309 }
5310 return ToSI;
5311}
5312
5314 DeclContext *DC, *LexicalDC;
5315 DeclarationName Name;
5316 SourceLocation Loc;
5317 NamedDecl *ToD = nullptr;
5318 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5319 return std::move(Err);
5320 if (ToD)
5321 return ToD;
5322
5323 Error Err = Error::success();
5324 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5325 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5326 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5327 if (Err)
5328 return std::move(Err);
5329
5330 DeclarationNameInfo NameInfo(Name, ToLoc);
5331 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5332 return std::move(Err);
5333
5334 UsingDecl *ToUsing;
5335 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5336 ToUsingLoc, ToQualifierLoc, NameInfo,
5337 D->hasTypename()))
5338 return ToUsing;
5339
5340 ToUsing->setLexicalDeclContext(LexicalDC);
5341 LexicalDC->addDeclInternal(ToUsing);
5342
5343 if (NamedDecl *FromPattern =
5344 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5345 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5346 Importer.getToContext().setInstantiatedFromUsingDecl(
5347 ToUsing, *ToPatternOrErr);
5348 else
5349 return ToPatternOrErr.takeError();
5350 }
5351
5352 return ImportUsingShadowDecls(D, ToUsing);
5353}
5354
5356 DeclContext *DC, *LexicalDC;
5357 DeclarationName Name;
5358 SourceLocation Loc;
5359 NamedDecl *ToD = nullptr;
5360 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5361 return std::move(Err);
5362 if (ToD)
5363 return ToD;
5364
5365 Error Err = Error::success();
5366 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5367 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5368 auto ToNameLoc = importChecked(Err, D->getLocation());
5369 auto *ToEnumType = importChecked(Err, D->getEnumType());
5370 if (Err)
5371 return std::move(Err);
5372
5373 UsingEnumDecl *ToUsingEnum;
5374 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5375 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5376 return ToUsingEnum;
5377
5378 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5379 LexicalDC->addDeclInternal(ToUsingEnum);
5380
5381 if (UsingEnumDecl *FromPattern =
5382 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5383 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5384 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5385 *ToPatternOrErr);
5386 else
5387 return ToPatternOrErr.takeError();
5388 }
5389
5390 return ImportUsingShadowDecls(D, ToUsingEnum);
5391}
5392
5394 DeclContext *DC, *LexicalDC;
5395 DeclarationName Name;
5396 SourceLocation Loc;
5397 NamedDecl *ToD = nullptr;
5398 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5399 return std::move(Err);
5400 if (ToD)
5401 return ToD;
5402
5403 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5404 if (!ToIntroducerOrErr)
5405 return ToIntroducerOrErr.takeError();
5406
5407 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5408 if (!ToTargetOrErr)
5409 return ToTargetOrErr.takeError();
5410
5411 UsingShadowDecl *ToShadow;
5412 if (auto *FromConstructorUsingShadow =
5413 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5414 Error Err = Error::success();
5416 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5417 if (Err)
5418 return std::move(Err);
5419 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5420 // is really the "NominatedBaseClassShadowDecl" value if it exists
5421 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5422 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5423 // get the correct values.
5424 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5425 ToShadow, D, Importer.getToContext(), DC, Loc,
5426 cast<UsingDecl>(*ToIntroducerOrErr),
5427 Nominated ? Nominated : *ToTargetOrErr,
5428 FromConstructorUsingShadow->constructsVirtualBase()))
5429 return ToShadow;
5430 } else {
5431 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5432 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5433 return ToShadow;
5434 }
5435
5436 ToShadow->setLexicalDeclContext(LexicalDC);
5437 ToShadow->setAccess(D->getAccess());
5438
5439 if (UsingShadowDecl *FromPattern =
5440 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5441 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5442 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5443 ToShadow, *ToPatternOrErr);
5444 else
5445 // FIXME: We return error here but the definition is already created
5446 // and available with lookups. How to fix this?..
5447 return ToPatternOrErr.takeError();
5448 }
5449
5450 LexicalDC->addDeclInternal(ToShadow);
5451
5452 return ToShadow;
5453}
5454
5456 DeclContext *DC, *LexicalDC;
5457 DeclarationName Name;
5458 SourceLocation Loc;
5459 NamedDecl *ToD = nullptr;
5460 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5461 return std::move(Err);
5462 if (ToD)
5463 return ToD;
5464
5465 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5466 if (!ToComAncestorOrErr)
5467 return ToComAncestorOrErr.takeError();
5468
5469 Error Err = Error::success();
5470 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5471 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5472 auto ToNamespaceKeyLocation =
5474 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5475 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5476 if (Err)
5477 return std::move(Err);
5478
5479 UsingDirectiveDecl *ToUsingDir;
5480 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5481 ToUsingLoc,
5482 ToNamespaceKeyLocation,
5483 ToQualifierLoc,
5484 ToIdentLocation,
5485 ToNominatedNamespace, *ToComAncestorOrErr))
5486 return ToUsingDir;
5487
5488 ToUsingDir->setLexicalDeclContext(LexicalDC);
5489 LexicalDC->addDeclInternal(ToUsingDir);
5490
5491 return ToUsingDir;
5492}
5493
5495 DeclContext *DC, *LexicalDC;
5496 DeclarationName Name;
5497 SourceLocation Loc;
5498 NamedDecl *ToD = nullptr;
5499 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5500 return std::move(Err);
5501 if (ToD)
5502 return ToD;
5503
5504 auto ToInstantiatedFromUsingOrErr =
5505 Importer.Import(D->getInstantiatedFromUsingDecl());
5506 if (!ToInstantiatedFromUsingOrErr)
5507 return ToInstantiatedFromUsingOrErr.takeError();
5508 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5509 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5510 return std::move(Err);
5511
5512 UsingPackDecl *ToUsingPack;
5513 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5514 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5515 Expansions))
5516 return ToUsingPack;
5517
5518 addDeclToContexts(D, ToUsingPack);
5519
5520 return ToUsingPack;
5521}
5522
5525 DeclContext *DC, *LexicalDC;
5526 DeclarationName Name;
5527 SourceLocation Loc;
5528 NamedDecl *ToD = nullptr;
5529 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5530 return std::move(Err);
5531 if (ToD)
5532 return ToD;
5533
5534 Error Err = Error::success();
5535 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5536 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5537 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5538 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5539 if (Err)
5540 return std::move(Err);
5541
5542 DeclarationNameInfo NameInfo(Name, ToLoc);
5543 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5544 return std::move(Err);
5545
5546 UnresolvedUsingValueDecl *ToUsingValue;
5547 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5548 ToUsingLoc, ToQualifierLoc, NameInfo,
5549 ToEllipsisLoc))
5550 return ToUsingValue;
5551
5552 ToUsingValue->setAccess(D->getAccess());
5553 ToUsingValue->setLexicalDeclContext(LexicalDC);
5554 LexicalDC->addDeclInternal(ToUsingValue);
5555
5556 return ToUsingValue;
5557}
5558
5561 DeclContext *DC, *LexicalDC;
5562 DeclarationName Name;
5563 SourceLocation Loc;
5564 NamedDecl *ToD = nullptr;
5565 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5566 return std::move(Err);
5567 if (ToD)
5568 return ToD;
5569
5570 Error Err = Error::success();
5571 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5572 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5573 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5574 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5575 if (Err)
5576 return std::move(Err);
5577
5579 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5580 ToUsingLoc, ToTypenameLoc,
5581 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5582 return ToUsing;
5583
5584 ToUsing->setAccess(D->getAccess());
5585 ToUsing->setLexicalDeclContext(LexicalDC);
5586 LexicalDC->addDeclInternal(ToUsing);
5587
5588 return ToUsing;
5589}
5590
5592 Decl* ToD = nullptr;
5593 switch (D->getBuiltinTemplateKind()) {
5594#define BuiltinTemplate(BTName) \
5595 case BuiltinTemplateKind::BTK##BTName: \
5596 ToD = Importer.getToContext().get##BTName##Decl(); \
5597 break;
5598#include "clang/Basic/BuiltinTemplates.inc"
5599 }
5600 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5601 Importer.MapImported(D, ToD);
5602 return ToD;
5603}
5604
5607 if (To->getDefinition()) {
5608 // Check consistency of superclass.
5609 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5610 if (FromSuper) {
5611 if (auto FromSuperOrErr = import(FromSuper))
5612 FromSuper = *FromSuperOrErr;
5613 else
5614 return FromSuperOrErr.takeError();
5615 }
5616
5617 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5618 if ((bool)FromSuper != (bool)ToSuper ||
5619 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5620 Importer.ToDiag(To->getLocation(),
5621 diag::warn_odr_objc_superclass_inconsistent)
5622 << To->getDeclName();
5623 if (ToSuper)
5624 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5625 << To->getSuperClass()->getDeclName();
5626 else
5627 Importer.ToDiag(To->getLocation(),
5628 diag::note_odr_objc_missing_superclass);
5629 if (From->getSuperClass())
5630 Importer.FromDiag(From->getSuperClassLoc(),
5631 diag::note_odr_objc_superclass)
5632 << From->getSuperClass()->getDeclName();
5633 else
5634 Importer.FromDiag(From->getLocation(),
5635 diag::note_odr_objc_missing_superclass);
5636 }
5637
5639 if (Error Err = ImportDeclContext(From))
5640 return Err;
5641 return Error::success();
5642 }
5643
5644 // Start the definition.
5645 To->startDefinition();
5646
5647 // If this class has a superclass, import it.
5648 if (From->getSuperClass()) {
5649 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5650 To->setSuperClass(*SuperTInfoOrErr);
5651 else
5652 return SuperTInfoOrErr.takeError();
5653 }
5654
5655 // Import protocols
5657 SmallVector<SourceLocation, 4> ProtocolLocs;
5659 From->protocol_loc_begin();
5660
5662 FromProtoEnd = From->protocol_end();
5663 FromProto != FromProtoEnd;
5664 ++FromProto, ++FromProtoLoc) {
5665 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5666 Protocols.push_back(*ToProtoOrErr);
5667 else
5668 return ToProtoOrErr.takeError();
5669
5670 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5671 ProtocolLocs.push_back(*ToProtoLocOrErr);
5672 else
5673 return ToProtoLocOrErr.takeError();
5674
5675 }
5676
5677 // FIXME: If we're merging, make sure that the protocol list is the same.
5678 To->setProtocolList(Protocols.data(), Protocols.size(),
5679 ProtocolLocs.data(), Importer.getToContext());
5680
5681 // Import categories. When the categories themselves are imported, they'll
5682 // hook themselves into this interface.
5683 for (auto *Cat : From->known_categories()) {
5684 auto ToCatOrErr = import(Cat);
5685 if (!ToCatOrErr)
5686 return ToCatOrErr.takeError();
5687 }
5688
5689 // If we have an @implementation, import it as well.
5690 if (From->getImplementation()) {
5691 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5692 import(From->getImplementation()))
5693 To->setImplementation(*ToImplOrErr);
5694 else
5695 return ToImplOrErr.takeError();
5696 }
5697
5698 // Import all of the members of this class.
5699 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5700 return Err;
5701
5702 return Error::success();
5703}
5704
5707 if (!list)
5708 return nullptr;
5709
5711 for (auto *fromTypeParam : *list) {
5712 if (auto toTypeParamOrErr = import(fromTypeParam))
5713 toTypeParams.push_back(*toTypeParamOrErr);
5714 else
5715 return toTypeParamOrErr.takeError();
5716 }
5717
5718 auto LAngleLocOrErr = import(list->getLAngleLoc());
5719 if (!LAngleLocOrErr)
5720 return LAngleLocOrErr.takeError();
5721
5722 auto RAngleLocOrErr = import(list->getRAngleLoc());
5723 if (!RAngleLocOrErr)
5724 return RAngleLocOrErr.takeError();
5725
5726 return ObjCTypeParamList::create(Importer.getToContext(),
5727 *LAngleLocOrErr,
5728 toTypeParams,
5729 *RAngleLocOrErr);
5730}
5731
5733 // If this class has a definition in the translation unit we're coming from,
5734 // but this particular declaration is not that definition, import the
5735 // definition and map to that.
5737 if (Definition && Definition != D) {
5738 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5739 return Importer.MapImported(D, *ImportedDefOrErr);
5740 else
5741 return ImportedDefOrErr.takeError();
5742 }
5743
5744 // Import the major distinguishing characteristics of an @interface.
5745 DeclContext *DC, *LexicalDC;
5746 DeclarationName Name;
5747 SourceLocation Loc;
5748 NamedDecl *ToD;
5749 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5750 return std::move(Err);
5751 if (ToD)
5752 return ToD;
5753
5754 // Look for an existing interface with the same name.
5755 ObjCInterfaceDecl *MergeWithIface = nullptr;
5756 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5757 for (auto *FoundDecl : FoundDecls) {
5758 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5759 continue;
5760
5761 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5762 break;
5763 }
5764
5765 // Create an interface declaration, if one does not already exist.
5766 ObjCInterfaceDecl *ToIface = MergeWithIface;
5767 if (!ToIface) {
5768 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5769 if (!AtBeginLocOrErr)
5770 return AtBeginLocOrErr.takeError();
5771
5772 if (GetImportedOrCreateDecl(
5773 ToIface, D, Importer.getToContext(), DC,
5774 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5775 /*TypeParamList=*/nullptr,
5776 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5777 return ToIface;
5778 ToIface->setLexicalDeclContext(LexicalDC);
5779 LexicalDC->addDeclInternal(ToIface);
5780 }
5781 Importer.MapImported(D, ToIface);
5782 // Import the type parameter list after MapImported, to avoid
5783 // loops when bringing in their DeclContext.
5784 if (auto ToPListOrErr =
5786 ToIface->setTypeParamList(*ToPListOrErr);
5787 else
5788 return ToPListOrErr.takeError();
5789
5791 if (Error Err = ImportDefinition(D, ToIface))
5792 return std::move(Err);
5793
5794 return ToIface;
5795}
5796
5799 ObjCCategoryDecl *Category;
5800 if (Error Err = importInto(Category, D->getCategoryDecl()))
5801 return std::move(Err);
5802
5803 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5804 if (!ToImpl) {
5805 DeclContext *DC, *LexicalDC;
5806 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5807 return std::move(Err);
5808
5809 Error Err = Error::success();
5810 auto ToLocation = importChecked(Err, D->getLocation());
5811 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5812 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5813 if (Err)
5814 return std::move(Err);
5815
5816 if (GetImportedOrCreateDecl(
5817 ToImpl, D, Importer.getToContext(), DC,
5818 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5819 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5820 return ToImpl;
5821
5822 ToImpl->setLexicalDeclContext(LexicalDC);
5823 LexicalDC->addDeclInternal(ToImpl);
5824 Category->setImplementation(ToImpl);
5825 }
5826
5827 Importer.MapImported(D, ToImpl);
5828 if (Error Err = ImportDeclContext(D))
5829 return std::move(Err);
5830
5831 return ToImpl;
5832}
5833
5836 // Find the corresponding interface.
5837 ObjCInterfaceDecl *Iface;
5838 if (Error Err = importInto(Iface, D->getClassInterface()))
5839 return std::move(Err);
5840
5841 // Import the superclass, if any.
5842 ObjCInterfaceDecl *Super;
5843 if (Error Err = importInto(Super, D->getSuperClass()))
5844 return std::move(Err);
5845
5847 if (!Impl) {
5848 // We haven't imported an implementation yet. Create a new @implementation
5849 // now.
5850 DeclContext *DC, *LexicalDC;
5851 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5852 return std::move(Err);
5853
5854 Error Err = Error::success();
5855 auto ToLocation = importChecked(Err, D->getLocation());
5856 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5857 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5858 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5859 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5860 if (Err)
5861 return std::move(Err);
5862
5863 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5864 DC, Iface, Super,
5865 ToLocation,
5866 ToAtStartLoc,
5867 ToSuperClassLoc,
5868 ToIvarLBraceLoc,
5869 ToIvarRBraceLoc))
5870 return Impl;
5871
5872 Impl->setLexicalDeclContext(LexicalDC);
5873
5874 // Associate the implementation with the class it implements.
5875 Iface->setImplementation(Impl);
5876 Importer.MapImported(D, Iface->getImplementation());
5877 } else {
5878 Importer.MapImported(D, Iface->getImplementation());
5879
5880 // Verify that the existing @implementation has the same superclass.
5881 if ((Super && !Impl->getSuperClass()) ||
5882 (!Super && Impl->getSuperClass()) ||
5883 (Super && Impl->getSuperClass() &&
5885 Impl->getSuperClass()))) {
5886 Importer.ToDiag(Impl->getLocation(),
5887 diag::warn_odr_objc_superclass_inconsistent)
5888 << Iface->getDeclName();
5889 // FIXME: It would be nice to have the location of the superclass
5890 // below.
5891 if (Impl->getSuperClass())
5892 Importer.ToDiag(Impl->getLocation(),
5893 diag::note_odr_objc_superclass)
5894 << Impl->getSuperClass()->getDeclName();
5895 else
5896 Importer.ToDiag(Impl->getLocation(),
5897 diag::note_odr_objc_missing_superclass);
5898 if (D->getSuperClass())
5899 Importer.FromDiag(D->getLocation(),
5900 diag::note_odr_objc_superclass)
5901 << D->getSuperClass()->getDeclName();
5902 else
5903 Importer.FromDiag(D->getLocation(),
5904 diag::note_odr_objc_missing_superclass);
5905
5906 return make_error<ASTImportError>(ASTImportError::NameConflict);
5907 }
5908 }
5909
5910 // Import all of the members of this @implementation.
5911 if (Error Err = ImportDeclContext(D))
5912 return std::move(Err);
5913
5914 return Impl;
5915}
5916
5918 // Import the major distinguishing characteristics of an @property.
5919 DeclContext *DC, *LexicalDC;
5920 DeclarationName Name;
5921 SourceLocation Loc;
5922 NamedDecl *ToD;
5923 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5924 return std::move(Err);
5925 if (ToD)
5926 return ToD;
5927
5928 // Check whether we have already imported this property.
5929 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5930 for (auto *FoundDecl : FoundDecls) {
5931 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5932 // Instance and class properties can share the same name but are different
5933 // declarations.
5934 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5935 continue;
5936
5937 // Check property types.
5938 if (!Importer.IsStructurallyEquivalent(D->getType(),
5939 FoundProp->getType())) {
5940 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5941 << Name << D->getType() << FoundProp->getType();
5942 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5943 << FoundProp->getType();
5944
5945 return make_error<ASTImportError>(ASTImportError::NameConflict);
5946 }
5947
5948 // FIXME: Check property attributes, getters, setters, etc.?
5949
5950 // Consider these properties to be equivalent.
5951 Importer.MapImported(D, FoundProp);
5952 return FoundProp;
5953 }
5954 }
5955
5956 Error Err = Error::success();
5957 auto ToType = importChecked(Err, D->getType());
5958 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5959 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5960 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5961 if (Err)
5962 return std::move(Err);
5963
5964 // Create the new property.
5965 ObjCPropertyDecl *ToProperty;
5966 if (GetImportedOrCreateDecl(
5967 ToProperty, D, Importer.getToContext(), DC, Loc,
5968 Name.getAsIdentifierInfo(), ToAtLoc,
5969 ToLParenLoc, ToType,
5970 ToTypeSourceInfo, D->getPropertyImplementation()))
5971 return ToProperty;
5972
5973 auto ToGetterName = importChecked(Err, D->getGetterName());
5974 auto ToSetterName = importChecked(Err, D->getSetterName());
5975 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5976 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5977 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5978 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5979 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5980 if (Err)
5981 return std::move(Err);
5982
5983 ToProperty->setLexicalDeclContext(LexicalDC);
5984 LexicalDC->addDeclInternal(ToProperty);
5985
5989 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5990 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5991 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5992 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5993 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5994 return ToProperty;
5995}
5996
6000 if (Error Err = importInto(Property, D->getPropertyDecl()))
6001 return std::move(Err);
6002
6003 DeclContext *DC, *LexicalDC;
6004 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6005 return std::move(Err);
6006
6007 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6008
6009 // Import the ivar (for an @synthesize).
6010 ObjCIvarDecl *Ivar = nullptr;
6011 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6012 return std::move(Err);
6013
6014 ObjCPropertyImplDecl *ToImpl
6015 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6016 Property->getQueryKind());
6017 if (!ToImpl) {
6018
6019 Error Err = Error::success();
6020 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6021 auto ToLocation = importChecked(Err, D->getLocation());
6022 auto ToPropertyIvarDeclLoc =
6024 if (Err)
6025 return std::move(Err);
6026
6027 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6028 ToBeginLoc,
6029 ToLocation, Property,
6030 D->getPropertyImplementation(), Ivar,
6031 ToPropertyIvarDeclLoc))
6032 return ToImpl;
6033
6034 ToImpl->setLexicalDeclContext(LexicalDC);
6035 LexicalDC->addDeclInternal(ToImpl);
6036 } else {
6037 // Check that we have the same kind of property implementation (@synthesize
6038 // vs. @dynamic).
6040 Importer.ToDiag(ToImpl->getLocation(),
6041 diag::warn_odr_objc_property_impl_kind_inconsistent)
6042 << Property->getDeclName()
6043 << (ToImpl->getPropertyImplementation()
6045 Importer.FromDiag(D->getLocation(),
6046 diag::note_odr_objc_property_impl_kind)
6047 << D->getPropertyDecl()->getDeclName()
6049
6050 return make_error<ASTImportError>(ASTImportError::NameConflict);
6051 }
6052
6053 // For @synthesize, check that we have the same
6055 Ivar != ToImpl->getPropertyIvarDecl()) {
6056 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6057 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6058 << Property->getDeclName()
6059 << ToImpl->getPropertyIvarDecl()->getDeclName()
6060 << Ivar->getDeclName();
6061 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6062 diag::note_odr_objc_synthesize_ivar_here)
6064
6065 return make_error<ASTImportError>(ASTImportError::NameConflict);
6066 }
6067
6068 // Merge the existing implementation with the new implementation.
6069 Importer.MapImported(D, ToImpl);
6070 }
6071
6072 return ToImpl;
6073}
6074
6077 Error Err = Error::success();
6078 auto ToType = importChecked(Err, D->getType());
6079 auto ToValue = importChecked(Err, D->getValue());
6080 if (Err)
6081 return std::move(Err);
6082
6084 auto Create = [this](QualType T, const APValue &V) {
6085 return Importer.ToContext.getTemplateParamObjectDecl(T, V);
6086 };
6087 (void)GetImportedOrCreateSpecialDecl(ToD, Create, D, ToType, ToValue);
6088 return ToD;
6089}
6090
6093 // For template arguments, we adopt the translation unit as our declaration
6094 // context. This context will be fixed when (during) the actual template
6095 // declaration is created.
6096
6097 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6098 if (!BeginLocOrErr)
6099 return BeginLocOrErr.takeError();
6100
6101 ExpectedSLoc LocationOrErr = import(D->getLocation());
6102 if (!LocationOrErr)
6103 return LocationOrErr.takeError();
6104
6105 TemplateTypeParmDecl *ToD = nullptr;
6106 if (GetImportedOrCreateDecl(
6107 ToD, D, Importer.getToContext(),
6108 Importer.getToContext().getTranslationUnitDecl(),
6109 *BeginLocOrErr, *LocationOrErr,
6110 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6112 D->hasTypeConstraint()))
6113 return ToD;
6114
6115 // Import the type-constraint
6116 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6117
6118 Error Err = Error::success();
6119 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6120 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6121 if (Err)
6122 return std::move(Err);
6123
6124 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6125 }
6126
6127 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6128 return Err;
6129
6130 return ToD;
6131}
6132
6135
6136 Error Err = Error::success();
6137 auto ToDeclName = importChecked(Err, D->getDeclName());
6138 auto ToLocation = importChecked(Err, D->getLocation());
6139 auto ToType = importChecked(Err, D->getType());
6140 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6141 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6142 if (Err)
6143 return std::move(Err);
6144
6145 NonTypeTemplateParmDecl *ToD = nullptr;
6146 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6147 Importer.getToContext().getTranslationUnitDecl(),
6148 ToInnerLocStart, ToLocation, D->getDepth(),
6149 D->getPosition(),
6150 ToDeclName.getAsIdentifierInfo(), ToType,
6151 D->isParameterPack(), ToTypeSourceInfo))
6152 return ToD;
6153
6154 Err = importTemplateParameterDefaultArgument(D, ToD);
6155 if (Err)
6156 return Err;
6157
6158 return ToD;
6159}
6160
6163 bool IsCanonical = false;
6164 if (auto *CanonD = Importer.getFromContext()
6165 .findCanonicalTemplateTemplateParmDeclInternal(D);
6166 CanonD == D)
6167 IsCanonical = true;
6168
6169 // Import the name of this declaration.
6170 auto NameOrErr = import(D->getDeclName());
6171 if (!NameOrErr)
6172 return NameOrErr.takeError();
6173
6174 // Import the location of this declaration.
6175 ExpectedSLoc LocationOrErr = import(D->getLocation());
6176 if (!LocationOrErr)
6177 return LocationOrErr.takeError();
6178
6179 // Import template parameters.
6180 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6181 if (!TemplateParamsOrErr)
6182 return TemplateParamsOrErr.takeError();
6183
6184 TemplateTemplateParmDecl *ToD = nullptr;
6185 if (GetImportedOrCreateDecl(
6186 ToD, D, Importer.getToContext(),
6187 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6188 D->getDepth(), D->getPosition(), D->isParameterPack(),
6189 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6190 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6191 return ToD;
6192
6193 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6194 return Err;
6195
6196 if (IsCanonical)
6197 return Importer.getToContext()
6198 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6199
6200 return ToD;
6201}
6202
6203// Returns the definition for a (forward) declaration of a TemplateDecl, if
6204// it has any definition in the redecl chain.
6205template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6206 assert(D->getTemplatedDecl() && "Should be called on templates only");
6207 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6208 if (!ToTemplatedDef)
6209 return nullptr;
6210 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6211 return cast_or_null<T>(TemplateWithDef);
6212}
6213
6215
6216 // Import the major distinguishing characteristics of this class template.
6217 DeclContext *DC, *LexicalDC;
6218 DeclarationName Name;
6219 SourceLocation Loc;
6220 NamedDecl *ToD;
6221 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6222 return std::move(Err);
6223 if (ToD)
6224 return ToD;
6225
6226 // Should check if a declaration is friend in a dependent context.
6227 // Such templates are not linked together in a declaration chain.
6228 // The ASTImporter strategy is to map existing forward declarations to
6229 // imported ones only if strictly necessary, otherwise import these as new
6230 // forward declarations. In case of the "dependent friend" declarations, new
6231 // declarations are created, but not linked in a declaration chain.
6232 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6233 return TD->getFriendObjectKind() != Decl::FOK_None &&
6234 TD->getLexicalDeclContext()->isDependentContext();
6235 };
6236 bool DependentFriend = IsDependentFriend(D);
6237
6238 ClassTemplateDecl *FoundByLookup = nullptr;
6239
6240 // We may already have a template of the same name; try to find and match it.
6241 if (!DC->isFunctionOrMethod()) {
6242 SmallVector<NamedDecl *, 4> ConflictingDecls;
6243 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6244 for (auto *FoundDecl : FoundDecls) {
6245 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6247 continue;
6248
6249 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6250 if (FoundTemplate) {
6251 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6252 continue;
6253
6254 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6255 bool IgnoreTemplateParmDepth =
6256 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6258 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6259 IgnoreTemplateParmDepth)) {
6260 if (DependentFriend || IsDependentFriend(FoundTemplate))
6261 continue;
6262
6263 ClassTemplateDecl *TemplateWithDef =
6264 getTemplateDefinition(FoundTemplate);
6265 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6266 return Importer.MapImported(D, TemplateWithDef);
6267 if (!FoundByLookup)
6268 FoundByLookup = FoundTemplate;
6269 // Search in all matches because there may be multiple decl chains,
6270 // see ASTTests test ImportExistingFriendClassTemplateDef.
6271 continue;
6272 }
6273 // When importing a friend, it is possible that multiple declarations
6274 // with same name can co-exist in specific cases (if a template contains
6275 // a friend template and has a specialization). For this case the
6276 // declarations should match, except that the "template depth" is
6277 // different. No linking of previous declaration is needed in this case.
6278 // FIXME: This condition may need refinement.
6279 if (D->getFriendObjectKind() != Decl::FOK_None &&
6280 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6281 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6282 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6283 /*IgnoreTemplateParmDepth=*/true))
6284 continue;
6285
6286 ConflictingDecls.push_back(FoundDecl);
6287 }
6288 }
6289
6290 if (!ConflictingDecls.empty()) {
6291 ExpectedName NameOrErr = Importer.HandleNameConflict(
6292 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6293 ConflictingDecls.size());
6294 if (NameOrErr)
6295 Name = NameOrErr.get();
6296 else
6297 return NameOrErr.takeError();
6298 }
6299 }
6300
6301 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6302
6303 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6304 if (!TemplateParamsOrErr)
6305 return TemplateParamsOrErr.takeError();
6306
6307 // Create the declaration that is being templated.
6308 CXXRecordDecl *ToTemplated;
6309 if (Error Err = importInto(ToTemplated, FromTemplated))
6310 return std::move(Err);
6311
6312 // Create the class template declaration itself.
6314 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6315 *TemplateParamsOrErr, ToTemplated))
6316 return D2;
6317
6318 ToTemplated->setDescribedClassTemplate(D2);
6319
6320 D2->setAccess(D->getAccess());
6321 D2->setLexicalDeclContext(LexicalDC);
6322
6323 addDeclToContexts(D, D2);
6324 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6325
6326 if (FoundByLookup) {
6327 auto *Recent =
6328 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6329
6330 // It is possible that during the import of the class template definition
6331 // we start the import of a fwd friend decl of the very same class template
6332 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6333 // had been created earlier and by that time the lookup could not find
6334 // anything existing, so it has no previous decl. Later, (still during the
6335 // import of the fwd friend decl) we start to import the definition again
6336 // and this time the lookup finds the previous fwd friend class template.
6337 // In this case we must set up the previous decl for the templated decl.
6338 if (!ToTemplated->getPreviousDecl()) {
6339 assert(FoundByLookup->getTemplatedDecl() &&
6340 "Found decl must have its templated decl set");
6341 CXXRecordDecl *PrevTemplated =
6342 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6343 if (ToTemplated != PrevTemplated)
6344 ToTemplated->setPreviousDecl(PrevTemplated);
6345 }
6346
6347 D2->setPreviousDecl(Recent);
6348 }
6349
6350 return D2;
6351}
6352
6355 ClassTemplateDecl *ClassTemplate;
6356 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6357 return std::move(Err);
6358
6359 // Import the context of this declaration.
6360 DeclContext *DC, *LexicalDC;
6361 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6362 return std::move(Err);
6363
6364 // Import template arguments.
6366 if (Error Err =
6367 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6368 return std::move(Err);
6369 // Try to find an existing specialization with these template arguments and
6370 // template parameter list.
6371 void *InsertPos = nullptr;
6372 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6374 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6375
6376 // Import template parameters.
6377 TemplateParameterList *ToTPList = nullptr;
6378
6379 if (PartialSpec) {
6380 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6381 if (!ToTPListOrErr)
6382 return ToTPListOrErr.takeError();
6383 ToTPList = *ToTPListOrErr;
6384 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6385 *ToTPListOrErr,
6386 InsertPos);
6387 } else
6388 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6389
6390 if (PrevDecl) {
6391 if (IsStructuralMatch(D, PrevDecl)) {
6392 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6393 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6394 Importer.MapImported(D, PrevDefinition);
6395 // Import those default field initializers which have been
6396 // instantiated in the "From" context, but not in the "To" context.
6397 for (auto *FromField : D->fields()) {
6398 auto ToOrErr = import(FromField);
6399 if (!ToOrErr)
6400 return ToOrErr.takeError();
6401 }
6402
6403 // Import those methods which have been instantiated in the
6404 // "From" context, but not in the "To" context.
6405 for (CXXMethodDecl *FromM : D->methods()) {
6406 auto ToOrErr = import(FromM);
6407 if (!ToOrErr)
6408 return ToOrErr.takeError();
6409 }
6410
6411 // TODO Import instantiated default arguments.
6412 // TODO Import instantiated exception specifications.
6413 //
6414 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6415 // what else could be fused during an AST merge.
6416 return PrevDefinition;
6417 }
6418 } else { // ODR violation.
6419 // FIXME HandleNameConflict
6420 return make_error<ASTImportError>(ASTImportError::NameConflict);
6421 }
6422 }
6423
6424 // Import the location of this declaration.
6425 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6426 if (!BeginLocOrErr)
6427 return BeginLocOrErr.takeError();
6428 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6429 if (!IdLocOrErr)
6430 return IdLocOrErr.takeError();
6431
6432 // Import TemplateArgumentListInfo.
6433 TemplateArgumentListInfo ToTAInfo;
6434 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6435 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6436 return std::move(Err);
6437 }
6438
6439 // Create the specialization.
6440 ClassTemplateSpecializationDecl *D2 = nullptr;
6441 if (PartialSpec) {
6442 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6443 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6444 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6445 /*CanonInjectedTST=*/CanQualType(),
6446 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6447 return D2;
6448
6449 // Update InsertPos, because preceding import calls may have invalidated
6450 // it by adding new specializations.
6452 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6453 InsertPos))
6454 // Add this partial specialization to the class template.
6455 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6457 import(PartialSpec->getInstantiatedFromMember()))
6458 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6459 else
6460 return ToInstOrErr.takeError();
6461
6462 updateLookupTableForTemplateParameters(*ToTPList);
6463 } else { // Not a partial specialization.
6464 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6465 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6466 TemplateArgs, D->hasStrictPackMatch(),
6467 PrevDecl))
6468 return D2;
6469
6470 // Update InsertPos, because preceding import calls may have invalidated
6471 // it by adding new specializations.
6472 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6473 // Add this specialization to the class template.
6474 ClassTemplate->AddSpecialization(D2, InsertPos);
6475 }
6476
6478
6479 // Set the context of this specialization/instantiation.
6480 D2->setLexicalDeclContext(LexicalDC);
6481
6482 // Add to the DC only if it was an explicit specialization/instantiation.
6484 LexicalDC->addDeclInternal(D2);
6485 }
6486
6487 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6488 D2->setBraceRange(*BraceRangeOrErr);
6489 else
6490 return BraceRangeOrErr.takeError();
6491
6492 if (Error Err = ImportTemplateParameterLists(D, D2))
6493 return std::move(Err);
6494
6495 // Import the qualifier, if any.
6496 if (auto LocOrErr = import(D->getQualifierLoc()))
6497 D2->setQualifierInfo(*LocOrErr);
6498 else
6499 return LocOrErr.takeError();
6500
6501 if (D->getTemplateArgsAsWritten())
6502 D2->setTemplateArgsAsWritten(ToTAInfo);
6503
6504 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6505 D2->setTemplateKeywordLoc(*LocOrErr);
6506 else
6507 return LocOrErr.takeError();
6508
6509 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6510 D2->setExternKeywordLoc(*LocOrErr);
6511 else
6512 return LocOrErr.takeError();
6513
6514 if (D->getPointOfInstantiation().isValid()) {
6515 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6516 D2->setPointOfInstantiation(*POIOrErr);
6517 else
6518 return POIOrErr.takeError();
6519 }
6520
6522
6523 if (auto P = D->getInstantiatedFrom()) {
6524 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6525 if (auto CTDorErr = import(CTD))
6526 D2->setInstantiationOf(*CTDorErr);
6527 } else {
6529 auto CTPSDOrErr = import(CTPSD);
6530 if (!CTPSDOrErr)
6531 return CTPSDOrErr.takeError();
6533 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6534 for (unsigned I = 0; I < DArgs.size(); ++I) {
6535 const TemplateArgument &DArg = DArgs[I];
6536 if (auto ArgOrErr = import(DArg))
6537 D2ArgsVec[I] = *ArgOrErr;
6538 else
6539 return ArgOrErr.takeError();
6540 }
6542 *CTPSDOrErr,
6543 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6544 }
6545 }
6546
6547 if (D->isCompleteDefinition())
6548 if (Error Err = ImportDefinition(D, D2))
6549 return std::move(Err);
6550
6551 return D2;
6552}
6553
6555 // Import the major distinguishing characteristics of this variable template.
6556 DeclContext *DC, *LexicalDC;
6557 DeclarationName Name;
6558 SourceLocation Loc;
6559 NamedDecl *ToD;
6560 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6561 return std::move(Err);
6562 if (ToD)
6563 return ToD;
6564
6565 // We may already have a template of the same name; try to find and match it.
6566 assert(!DC->isFunctionOrMethod() &&
6567 "Variable templates cannot be declared at function scope");
6568
6569 SmallVector<NamedDecl *, 4> ConflictingDecls;
6570 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6571 VarTemplateDecl *FoundByLookup = nullptr;
6572 for (auto *FoundDecl : FoundDecls) {
6573 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6574 continue;
6575
6576 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6577 // Use the templated decl, some linkage flags are set only there.
6578 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6579 D->getTemplatedDecl()))
6580 continue;
6581 if (IsStructuralMatch(D, FoundTemplate)) {
6582 // FIXME Check for ODR error if the two definitions have
6583 // different initializers?
6584 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6585 if (D->getDeclContext()->isRecord()) {
6586 assert(FoundTemplate->getDeclContext()->isRecord() &&
6587 "Member variable template imported as non-member, "
6588 "inconsistent imported AST?");
6589 if (FoundDef)
6590 return Importer.MapImported(D, FoundDef);
6592 return Importer.MapImported(D, FoundTemplate);
6593 } else {
6594 if (FoundDef && D->isThisDeclarationADefinition())
6595 return Importer.MapImported(D, FoundDef);
6596 }
6597 FoundByLookup = FoundTemplate;
6598 break;
6599 }
6600 ConflictingDecls.push_back(FoundDecl);
6601 }
6602 }
6603
6604 if (!ConflictingDecls.empty()) {
6605 ExpectedName NameOrErr = Importer.HandleNameConflict(
6606 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6607 ConflictingDecls.size());
6608 if (NameOrErr)
6609 Name = NameOrErr.get();
6610 else
6611 return NameOrErr.takeError();
6612 }
6613
6614 VarDecl *DTemplated = D->getTemplatedDecl();
6615
6616 // Import the type.
6617 // FIXME: Value not used?
6618 ExpectedType TypeOrErr = import(DTemplated->getType());
6619 if (!TypeOrErr)
6620 return TypeOrErr.takeError();
6621
6622 // Create the declaration that is being templated.
6623 VarDecl *ToTemplated;
6624 if (Error Err = importInto(ToTemplated, DTemplated))
6625 return std::move(Err);
6626
6627 // Create the variable template declaration itself.
6628 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6629 if (!TemplateParamsOrErr)
6630 return TemplateParamsOrErr.takeError();
6631
6632 VarTemplateDecl *ToVarTD;
6633 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6634 Name, *TemplateParamsOrErr, ToTemplated))
6635 return ToVarTD;
6636
6637 ToTemplated->setDescribedVarTemplate(ToVarTD);
6638
6639 ToVarTD->setAccess(D->getAccess());
6640 ToVarTD->setLexicalDeclContext(LexicalDC);
6641 LexicalDC->addDeclInternal(ToVarTD);
6642 if (DC != Importer.getToContext().getTranslationUnitDecl())
6643 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6644
6645 if (FoundByLookup) {
6646 auto *Recent =
6647 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6648 if (!ToTemplated->getPreviousDecl()) {
6649 auto *PrevTemplated =
6650 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6651 if (ToTemplated != PrevTemplated)
6652 ToTemplated->setPreviousDecl(PrevTemplated);
6653 }
6654 ToVarTD->setPreviousDecl(Recent);
6655 }
6656
6657 return ToVarTD;
6658}
6659
6662 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6663 // in an analog way (but specialized for this case).
6664
6666 auto RedeclIt = Redecls.begin();
6667 // Import the first part of the decl chain. I.e. import all previous
6668 // declarations starting from the canonical decl.
6669 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6670 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6671 if (!RedeclOrErr)
6672 return RedeclOrErr.takeError();
6673 }
6674 assert(*RedeclIt == D);
6675
6676 VarTemplateDecl *VarTemplate = nullptr;
6678 return std::move(Err);
6679
6680 // Import the context of this declaration.
6681 DeclContext *DC, *LexicalDC;
6682 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6683 return std::move(Err);
6684
6685 // Import the location of this declaration.
6686 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6687 if (!BeginLocOrErr)
6688 return BeginLocOrErr.takeError();
6689
6690 auto IdLocOrErr = import(D->getLocation());
6691 if (!IdLocOrErr)
6692 return IdLocOrErr.takeError();
6693
6694 // Import template arguments.
6696 if (Error Err =
6697 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6698 return std::move(Err);
6699
6700 // Try to find an existing specialization with these template arguments.
6701 void *InsertPos = nullptr;
6702 VarTemplateSpecializationDecl *FoundSpecialization =
6703 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6704 if (FoundSpecialization) {
6705 if (IsStructuralMatch(D, FoundSpecialization)) {
6706 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6707 if (D->getDeclContext()->isRecord()) {
6708 // In a record, it is allowed only to have one optional declaration and
6709 // one definition of the (static or constexpr) variable template.
6710 assert(
6711 FoundSpecialization->getDeclContext()->isRecord() &&
6712 "Member variable template specialization imported as non-member, "
6713 "inconsistent imported AST?");
6714 if (FoundDef)
6715 return Importer.MapImported(D, FoundDef);
6717 return Importer.MapImported(D, FoundSpecialization);
6718 } else {
6719 // If definition is imported and there is already one, map to it.
6720 // Otherwise create a new variable and link it to the existing.
6721 if (FoundDef && D->isThisDeclarationADefinition())
6722 return Importer.MapImported(D, FoundDef);
6723 }
6724 } else {
6725 return make_error<ASTImportError>(ASTImportError::NameConflict);
6726 }
6727 }
6728
6729 VarTemplateSpecializationDecl *D2 = nullptr;
6730
6731 TemplateArgumentListInfo ToTAInfo;
6732 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6733 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6734 return std::move(Err);
6735 }
6736
6737 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6738 // Create a new specialization.
6739 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6740 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6741 if (!ToTPListOrErr)
6742 return ToTPListOrErr.takeError();
6743
6744 PartVarSpecDecl *ToPartial;
6745 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6746 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6747 VarTemplate, QualType(), nullptr,
6748 D->getStorageClass(), TemplateArgs))
6749 return ToPartial;
6750
6751 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6752 import(FromPartial->getInstantiatedFromMember()))
6753 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6754 else
6755 return ToInstOrErr.takeError();
6756
6757 if (FromPartial->isMemberSpecialization())
6758 ToPartial->setMemberSpecialization();
6759
6760 D2 = ToPartial;
6761
6762 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6763 // to adopt template parameters.
6764 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6765 } else { // Full specialization
6766 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6767 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6768 QualType(), nullptr, D->getStorageClass(),
6769 TemplateArgs))
6770 return D2;
6771 }
6772
6773 // Update InsertPos, because preceding import calls may have invalidated
6774 // it by adding new specializations.
6775 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6776 VarTemplate->AddSpecialization(D2, InsertPos);
6777
6778 QualType T;
6779 if (Error Err = importInto(T, D->getType()))
6780 return std::move(Err);
6781 D2->setType(T);
6782
6783 auto TInfoOrErr = import(D->getTypeSourceInfo());
6784 if (!TInfoOrErr)
6785 return TInfoOrErr.takeError();
6786 D2->setTypeSourceInfo(*TInfoOrErr);
6787
6788 if (D->getPointOfInstantiation().isValid()) {
6789 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6790 D2->setPointOfInstantiation(*POIOrErr);
6791 else
6792 return POIOrErr.takeError();
6793 }
6794
6796
6797 if (D->getTemplateArgsAsWritten())
6798 D2->setTemplateArgsAsWritten(ToTAInfo);
6799
6800 if (auto LocOrErr = import(D->getQualifierLoc()))
6801 D2->setQualifierInfo(*LocOrErr);
6802 else
6803 return LocOrErr.takeError();
6804
6805 if (D->isConstexpr())
6806 D2->setConstexpr(true);
6807
6808 D2->setAccess(D->getAccess());
6809
6810 if (Error Err = ImportInitializer(D, D2))
6811 return std::move(Err);
6812
6813 if (FoundSpecialization)
6814 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6815
6816 addDeclToContexts(D, D2);
6817
6818 // Import the rest of the chain. I.e. import all subsequent declarations.
6819 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6820 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6821 if (!RedeclOrErr)
6822 return RedeclOrErr.takeError();
6823 }
6824
6825 return D2;
6826}
6827
6830 DeclContext *DC, *LexicalDC;
6831 DeclarationName Name;
6832 SourceLocation Loc;
6833 NamedDecl *ToD;
6834
6835 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6836 return std::move(Err);
6837
6838 if (ToD)
6839 return ToD;
6840
6841 const FunctionTemplateDecl *FoundByLookup = nullptr;
6842
6843 // Try to find a function in our own ("to") context with the same name, same
6844 // type, and in the same context as the function we're importing.
6845 // FIXME Split this into a separate function.
6846 if (!LexicalDC->isFunctionOrMethod()) {
6848 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6849 for (auto *FoundDecl : FoundDecls) {
6850 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6851 continue;
6852
6853 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6854 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6855 continue;
6856 if (IsStructuralMatch(D, FoundTemplate)) {
6857 FunctionTemplateDecl *TemplateWithDef =
6858 getTemplateDefinition(FoundTemplate);
6859 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6860 return Importer.MapImported(D, TemplateWithDef);
6861
6862 FoundByLookup = FoundTemplate;
6863 break;
6864 // TODO: handle conflicting names
6865 }
6866 }
6867 }
6868 }
6869
6870 auto ParamsOrErr = import(D->getTemplateParameters());
6871 if (!ParamsOrErr)
6872 return ParamsOrErr.takeError();
6873 TemplateParameterList *Params = *ParamsOrErr;
6874
6875 FunctionDecl *TemplatedFD;
6876 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6877 return std::move(Err);
6878
6879 // At creation of the template the template parameters are "adopted"
6880 // (DeclContext is changed). After this possible change the lookup table
6881 // must be updated.
6882 // At deduction guides the DeclContext of the template parameters may be
6883 // different from what we would expect, it may be the class template, or a
6884 // probably different CXXDeductionGuideDecl. This may come from the fact that
6885 // the template parameter objects may be shared between deduction guides or
6886 // the class template, and at creation of multiple FunctionTemplateDecl
6887 // objects (for deduction guides) the same parameters are re-used. The
6888 // "adoption" happens multiple times with different parent, even recursively
6889 // for TemplateTemplateParmDecl. The same happens at import when the
6890 // FunctionTemplateDecl objects are created, but in different order.
6891 // In this way the DeclContext of these template parameters is not necessarily
6892 // the same as in the "from" context.
6894 OldParamDC.reserve(Params->size());
6895 llvm::transform(*Params, std::back_inserter(OldParamDC),
6896 [](NamedDecl *ND) { return ND->getDeclContext(); });
6897
6898 FunctionTemplateDecl *ToFunc;
6899 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6900 Params, TemplatedFD))
6901 return ToFunc;
6902
6903 // Fail if TemplatedFD is already part of a template.
6904 // The template should have been found by structural equivalence check before,
6905 // or ToFunc should be already imported.
6906 // If not, there is AST incompatibility that can be caused by previous import
6907 // errors. (NameConflict is not exact here.)
6908 if (TemplatedFD->getDescribedTemplate())
6909 return make_error<ASTImportError>(ASTImportError::NameConflict);
6910
6911 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6912
6913 ToFunc->setAccess(D->getAccess());
6914 ToFunc->setLexicalDeclContext(LexicalDC);
6915 addDeclToContexts(D, ToFunc);
6916
6917 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6918 if (LT && !OldParamDC.empty()) {
6919 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6920 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6921 }
6922
6923 if (FoundByLookup) {
6924 auto *Recent =
6925 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6926 if (!TemplatedFD->getPreviousDecl()) {
6927 assert(FoundByLookup->getTemplatedDecl() &&
6928 "Found decl must have its templated decl set");
6929 auto *PrevTemplated =
6930 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6931 if (TemplatedFD != PrevTemplated)
6932 TemplatedFD->setPreviousDecl(PrevTemplated);
6933 }
6934 ToFunc->setPreviousDecl(Recent);
6935 }
6936
6937 return ToFunc;
6938}
6939
6941 DeclContext *DC, *LexicalDC;
6942 Error Err = ImportDeclContext(D, DC, LexicalDC);
6943 auto LocationOrErr = importChecked(Err, D->getLocation());
6944 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6945 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6946 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6947 if (Err)
6948 return std::move(Err);
6949
6950 ConceptDecl *To;
6951 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6952 NameDeclOrErr, ToTemplateParameters,
6953 ConstraintExpr))
6954 return To;
6955 To->setLexicalDeclContext(LexicalDC);
6956 LexicalDC->addDeclInternal(To);
6957 return To;
6958}
6959
6962 DeclContext *DC, *LexicalDC;
6963 Error Err = ImportDeclContext(D, DC, LexicalDC);
6964 auto RequiresLoc = importChecked(Err, D->getLocation());
6965 if (Err)
6966 return std::move(Err);
6967
6969 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
6970 return To;
6971 To->setLexicalDeclContext(LexicalDC);
6972 LexicalDC->addDeclInternal(To);
6973 return To;
6974}
6975
6978 DeclContext *DC, *LexicalDC;
6979 Error Err = ImportDeclContext(D, DC, LexicalDC);
6980 auto ToSL = importChecked(Err, D->getLocation());
6981 if (Err)
6982 return std::move(Err);
6983
6985 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
6986 return std::move(Err);
6987
6989 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
6990 return To;
6991 To->setLexicalDeclContext(LexicalDC);
6992 LexicalDC->addDeclInternal(To);
6993 return To;
6994}
6995
6996//----------------------------------------------------------------------------
6997// Import Statements
6998//----------------------------------------------------------------------------
6999
7001 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7002 << S->getStmtClassName();
7003 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7004}
7005
7006
7008 if (Importer.returnWithErrorInTest())
7009 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7011 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7012 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7013 // ToII is nullptr when no symbolic name is given for output operand
7014 // see ParseStmtAsm::ParseAsmOperandsOpt
7015 Names.push_back(ToII);
7016 }
7017
7018 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7019 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7020 // ToII is nullptr when no symbolic name is given for input operand
7021 // see ParseStmtAsm::ParseAsmOperandsOpt
7022 Names.push_back(ToII);
7023 }
7024
7025 SmallVector<Expr *, 4> Clobbers;
7026 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7027 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7028 Clobbers.push_back(*ClobberOrErr);
7029 else
7030 return ClobberOrErr.takeError();
7031
7032 }
7033
7034 SmallVector<Expr *, 4> Constraints;
7035 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7036 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7037 Constraints.push_back(*OutputOrErr);
7038 else
7039 return OutputOrErr.takeError();
7040 }
7041
7042 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7043 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7044 Constraints.push_back(*InputOrErr);
7045 else
7046 return InputOrErr.takeError();
7047 }
7048
7050 S->getNumLabels());
7051 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7052 return std::move(Err);
7053
7054 if (Error Err =
7055 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7056 return std::move(Err);
7057
7058 if (Error Err = ImportArrayChecked(
7059 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7060 return std::move(Err);
7061
7062 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7063 if (!AsmLocOrErr)
7064 return AsmLocOrErr.takeError();
7065 auto AsmStrOrErr = import(S->getAsmStringExpr());
7066 if (!AsmStrOrErr)
7067 return AsmStrOrErr.takeError();
7068 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7069 if (!RParenLocOrErr)
7070 return RParenLocOrErr.takeError();
7071
7072 return new (Importer.getToContext()) GCCAsmStmt(
7073 Importer.getToContext(),
7074 *AsmLocOrErr,
7075 S->isSimple(),
7076 S->isVolatile(),
7077 S->getNumOutputs(),
7078 S->getNumInputs(),
7079 Names.data(),
7080 Constraints.data(),
7081 Exprs.data(),
7082 *AsmStrOrErr,
7083 S->getNumClobbers(),
7084 Clobbers.data(),
7085 S->getNumLabels(),
7086 *RParenLocOrErr);
7087}
7088
7090
7091 Error Err = Error::success();
7092 auto ToDG = importChecked(Err, S->getDeclGroup());
7093 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7094 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7095 if (Err)
7096 return std::move(Err);
7097 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7098}
7099
7101 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7102 if (!ToSemiLocOrErr)
7103 return ToSemiLocOrErr.takeError();
7104 return new (Importer.getToContext()) NullStmt(
7105 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7106}
7107
7109 SmallVector<Stmt *, 8> ToStmts(S->size());
7110
7111 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7112 return std::move(Err);
7113
7114 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7115 if (!ToLBracLocOrErr)
7116 return ToLBracLocOrErr.takeError();
7117
7118 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7119 if (!ToRBracLocOrErr)
7120 return ToRBracLocOrErr.takeError();
7121
7122 FPOptionsOverride FPO =
7124 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7125 *ToLBracLocOrErr, *ToRBracLocOrErr);
7126}
7127
7129
7130 Error Err = Error::success();
7131 auto ToLHS = importChecked(Err, S->getLHS());
7132 auto ToRHS = importChecked(Err, S->getRHS());
7133 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7134 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7135 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7136 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7137 if (Err)
7138 return std::move(Err);
7139
7140 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7141 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7142 ToStmt->setSubStmt(ToSubStmt);
7143
7144 return ToStmt;
7145}
7146
7148
7149 Error Err = Error::success();
7150 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7151 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7152 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7153 if (Err)
7154 return std::move(Err);
7155
7156 return new (Importer.getToContext()) DefaultStmt(
7157 ToDefaultLoc, ToColonLoc, ToSubStmt);
7158}
7159
7161
7162 Error Err = Error::success();
7163 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7164 auto ToLabelDecl = importChecked(Err, S->getDecl());
7165 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7166 if (Err)
7167 return std::move(Err);
7168
7169 return new (Importer.getToContext()) LabelStmt(
7170 ToIdentLoc, ToLabelDecl, ToSubStmt);
7171}
7172
7174 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7175 if (!ToAttrLocOrErr)
7176 return ToAttrLocOrErr.takeError();
7177 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7178 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7179 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7180 return std::move(Err);
7181 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7182 if (!ToSubStmtOrErr)
7183 return ToSubStmtOrErr.takeError();
7184
7186 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7187}
7188
7190
7191 Error Err = Error::success();
7192 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7193 auto ToInit = importChecked(Err, S->getInit());
7194 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7195 auto ToCond = importChecked(Err, S->getCond());
7196 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7197 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7198 auto ToThen = importChecked(Err, S->getThen());
7199 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7200 auto ToElse = importChecked(Err, S->getElse());
7201 if (Err)
7202 return std::move(Err);
7203
7204 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7205 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7206 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7207}
7208
7210
7211 Error Err = Error::success();
7212 auto ToInit = importChecked(Err, S->getInit());
7213 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7214 auto ToCond = importChecked(Err, S->getCond());
7215 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7216 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7217 auto ToBody = importChecked(Err, S->getBody());
7218 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7219 if (Err)
7220 return std::move(Err);
7221
7222 auto *ToStmt =
7223 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7224 ToCond, ToLParenLoc, ToRParenLoc);
7225 ToStmt->setBody(ToBody);
7226 ToStmt->setSwitchLoc(ToSwitchLoc);
7227
7228 // Now we have to re-chain the cases.
7229 SwitchCase *LastChainedSwitchCase = nullptr;
7230 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7231 SC = SC->getNextSwitchCase()) {
7232 Expected<SwitchCase *> ToSCOrErr = import(SC);
7233 if (!ToSCOrErr)
7234 return ToSCOrErr.takeError();
7235 if (LastChainedSwitchCase)
7236 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7237 else
7238 ToStmt->setSwitchCaseList(*ToSCOrErr);
7239 LastChainedSwitchCase = *ToSCOrErr;
7240 }
7241
7242 return ToStmt;
7243}
7244
7246
7247 Error Err = Error::success();
7248 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7249 auto ToCond = importChecked(Err, S->getCond());
7250 auto ToBody = importChecked(Err, S->getBody());
7251 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7252 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7253 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7254 if (Err)
7255 return std::move(Err);
7256
7257 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7258 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7259}
7260
7262
7263 Error Err = Error::success();
7264 auto ToBody = importChecked(Err, S->getBody());
7265 auto ToCond = importChecked(Err, S->getCond());
7266 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7267 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7268 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7269 if (Err)
7270 return std::move(Err);
7271
7272 return new (Importer.getToContext()) DoStmt(
7273 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7274}
7275
7277
7278 Error Err = Error::success();
7279 auto ToInit = importChecked(Err, S->getInit());
7280 auto ToCond = importChecked(Err, S->getCond());
7281 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7282 auto ToInc = importChecked(Err, S->getInc());
7283 auto ToBody = importChecked(Err, S->getBody());
7284 auto ToForLoc = importChecked(Err, S->getForLoc());
7285 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7286 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7287 if (Err)
7288 return std::move(Err);
7289
7290 return new (Importer.getToContext()) ForStmt(
7291 Importer.getToContext(),
7292 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7293 ToRParenLoc);
7294}
7295
7297
7298 Error Err = Error::success();
7299 auto ToLabel = importChecked(Err, S->getLabel());
7300 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7301 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7302 if (Err)
7303 return std::move(Err);
7304
7305 return new (Importer.getToContext()) GotoStmt(
7306 ToLabel, ToGotoLoc, ToLabelLoc);
7307}
7308
7310
7311 Error Err = Error::success();
7312 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7313 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7314 auto ToTarget = importChecked(Err, S->getTarget());
7315 if (Err)
7316 return std::move(Err);
7317
7318 return new (Importer.getToContext()) IndirectGotoStmt(
7319 ToGotoLoc, ToStarLoc, ToTarget);
7320}
7321
7322template <typename StmtClass>
7324 ASTImporter &Importer, StmtClass *S) {
7325 Error Err = Error::success();
7326 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7327 auto ToLabelLoc = S->hasLabelTarget()
7328 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7329 : SourceLocation();
7330 auto ToDecl = S->hasLabelTarget()
7331 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7332 : nullptr;
7333 if (Err)
7334 return std::move(Err);
7335 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7336}
7337
7341
7345
7347
7348 Error Err = Error::success();
7349 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7350 auto ToRetValue = importChecked(Err, S->getRetValue());
7351 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7352 if (Err)
7353 return std::move(Err);
7354
7355 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7356 ToNRVOCandidate);
7357}
7358
7360
7361 Error Err = Error::success();
7362 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7363 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7364 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7365 if (Err)
7366 return std::move(Err);
7367
7368 return new (Importer.getToContext()) CXXCatchStmt (
7369 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7370}
7371
7373 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7374 if (!ToTryLocOrErr)
7375 return ToTryLocOrErr.takeError();
7376
7377 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7378 if (!ToTryBlockOrErr)
7379 return ToTryBlockOrErr.takeError();
7380
7381 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7382 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7383 CXXCatchStmt *FromHandler = S->getHandler(HI);
7384 if (auto ToHandlerOrErr = import(FromHandler))
7385 ToHandlers[HI] = *ToHandlerOrErr;
7386 else
7387 return ToHandlerOrErr.takeError();
7388 }
7389
7390 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7391 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7392}
7393
7395
7396 Error Err = Error::success();
7397 auto ToInit = importChecked(Err, S->getInit());
7398 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7399 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7400 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7401 auto ToCond = importChecked(Err, S->getCond());
7402 auto ToInc = importChecked(Err, S->getInc());
7403 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7404 auto ToBody = importChecked(Err, S->getBody());
7405 auto ToForLoc = importChecked(Err, S->getForLoc());
7406 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7407 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7408 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7409 if (Err)
7410 return std::move(Err);
7411
7412 return new (Importer.getToContext()) CXXForRangeStmt(
7413 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7414 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7415}
7416
7419 Error Err = Error::success();
7420 auto ToESD = importChecked(Err, S->getDecl());
7421 auto ToInit = importChecked(Err, S->getInit());
7422 auto ToExpansionVar = importChecked(Err, S->getExpansionVarStmt());
7423 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7424 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7425 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7426 if (Err)
7427 return std::move(Err);
7428
7429 switch (S->getKind()) {
7432 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToLParenLoc,
7433 ToColonLoc, ToRParenLoc);
7434
7436 auto ToRange = importChecked(Err, S->getRangeVarStmt());
7437 auto ToBegin = importChecked(Err, S->getBeginVarStmt());
7438 auto ToIter = importChecked(Err, S->getIterVarStmt());
7439 if (Err)
7440 return std::move(Err);
7441
7443 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToRange,
7444 ToBegin, ToIter, ToLParenLoc, ToColonLoc, ToRParenLoc);
7445 }
7446
7448 auto ToDecompositionDeclStmt =
7450 if (Err)
7451 return std::move(Err);
7452
7454 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7455 ToDecompositionDeclStmt, ToLParenLoc, ToColonLoc, ToRParenLoc);
7456 }
7457
7459 auto ToExpansionInitializer =
7461 if (Err)
7462 return std::move(Err);
7464 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7465 ToExpansionInitializer, ToLParenLoc, ToColonLoc, ToRParenLoc);
7466 }
7467 }
7468
7469 llvm_unreachable("invalid pattern kind");
7470}
7471
7474 Error Err = Error::success();
7475 SmallVector<Stmt *> ToInstantiations;
7476 SmallVector<Stmt *> ToSharedStmts;
7477 auto ToParent = importChecked(Err, S->getParent());
7478 for (Stmt *FromInst : S->getInstantiations())
7479 ToInstantiations.push_back(importChecked(Err, FromInst));
7480 for (Stmt *FromShared : S->getPreambleStmts())
7481 ToSharedStmts.push_back(importChecked(Err, FromShared));
7482
7483 if (Err)
7484 return std::move(Err);
7485
7487 Importer.getToContext(), ToParent, ToInstantiations, ToSharedStmts,
7489}
7490
7493 Error Err = Error::success();
7494 auto ToElement = importChecked(Err, S->getElement());
7495 auto ToCollection = importChecked(Err, S->getCollection());
7496 auto ToBody = importChecked(Err, S->getBody());
7497 auto ToForLoc = importChecked(Err, S->getForLoc());
7498 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7499 if (Err)
7500 return std::move(Err);
7501
7502 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7503 ToCollection,
7504 ToBody,
7505 ToForLoc,
7506 ToRParenLoc);
7507}
7508
7510
7511 Error Err = Error::success();
7512 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7513 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7514 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7515 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7516 if (Err)
7517 return std::move(Err);
7518
7519 return new (Importer.getToContext()) ObjCAtCatchStmt (
7520 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7521}
7522
7524 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7525 if (!ToAtFinallyLocOrErr)
7526 return ToAtFinallyLocOrErr.takeError();
7527 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7528 if (!ToAtFinallyStmtOrErr)
7529 return ToAtFinallyStmtOrErr.takeError();
7530 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7531 *ToAtFinallyStmtOrErr);
7532}
7533
7535
7536 Error Err = Error::success();
7537 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7538 auto ToTryBody = importChecked(Err, S->getTryBody());
7539 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7540 if (Err)
7541 return std::move(Err);
7542
7543 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7544 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7545 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7546 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7547 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7548 else
7549 return ToCatchStmtOrErr.takeError();
7550 }
7551
7552 return ObjCAtTryStmt::Create(Importer.getToContext(),
7553 ToAtTryLoc, ToTryBody,
7554 ToCatchStmts.begin(), ToCatchStmts.size(),
7555 ToFinallyStmt);
7556}
7557
7560
7561 Error Err = Error::success();
7562 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7563 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7564 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7565 if (Err)
7566 return std::move(Err);
7567
7568 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7569 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7570}
7571
7573 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7574 if (!ToThrowLocOrErr)
7575 return ToThrowLocOrErr.takeError();
7576 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7577 if (!ToThrowExprOrErr)
7578 return ToThrowExprOrErr.takeError();
7579 return new (Importer.getToContext()) ObjCAtThrowStmt(
7580 *ToThrowLocOrErr, *ToThrowExprOrErr);
7581}
7582
7585 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7586 if (!ToAtLocOrErr)
7587 return ToAtLocOrErr.takeError();
7588 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7589 if (!ToSubStmtOrErr)
7590 return ToSubStmtOrErr.takeError();
7591 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7592 *ToSubStmtOrErr);
7593}
7594
7595//----------------------------------------------------------------------------
7596// Import Expressions
7597//----------------------------------------------------------------------------
7599 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7600 << E->getStmtClassName();
7601 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7602}
7603
7605 Error Err = Error::success();
7606 auto ToType = importChecked(Err, E->getType());
7607 auto BLoc = importChecked(Err, E->getBeginLoc());
7608 auto RParenLoc = importChecked(Err, E->getEndLoc());
7609 if (Err)
7610 return std::move(Err);
7611 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7612 if (!ParentContextOrErr)
7613 return ParentContextOrErr.takeError();
7614
7615 return new (Importer.getToContext())
7616 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7617 RParenLoc, *ParentContextOrErr);
7618}
7619
7621
7622 Error Err = Error::success();
7623 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7624 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7625 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7626 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7627 auto ToType = importChecked(Err, E->getType());
7628 if (Err)
7629 return std::move(Err);
7630
7631 return new (Importer.getToContext())
7632 VAArgExpr(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7633 E->getVarargABI());
7634}
7635
7637
7638 Error Err = Error::success();
7639 auto ToCond = importChecked(Err, E->getCond());
7640 auto ToLHS = importChecked(Err, E->getLHS());
7641 auto ToRHS = importChecked(Err, E->getRHS());
7642 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7643 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7644 auto ToType = importChecked(Err, E->getType());
7645 if (Err)
7646 return std::move(Err);
7647
7649 ExprObjectKind OK = E->getObjectKind();
7650
7651 // The value of CondIsTrue only matters if the value is not
7652 // condition-dependent.
7653 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7654
7655 return new (Importer.getToContext())
7656 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7657 ToRParenLoc, CondIsTrue);
7658}
7659
7661 Error Err = Error::success();
7662 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7663 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7664 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7665 auto ToType = importChecked(Err, E->getType());
7666 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7667 if (Err)
7668 return std::move(Err);
7669
7671 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7672 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7674}
7675
7677 Error Err = Error::success();
7678 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7679 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7680 auto ToType = importChecked(Err, E->getType());
7681 const unsigned NumSubExprs = E->getNumSubExprs();
7682
7684 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7685 ToSubExprs.resize(NumSubExprs);
7686
7687 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7688 return std::move(Err);
7689
7690 return new (Importer.getToContext()) ShuffleVectorExpr(
7691 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7692}
7693
7695 ExpectedType TypeOrErr = import(E->getType());
7696 if (!TypeOrErr)
7697 return TypeOrErr.takeError();
7698
7699 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7700 if (!BeginLocOrErr)
7701 return BeginLocOrErr.takeError();
7702
7703 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7704}
7705
7708 Error Err = Error::success();
7709 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7710 Expr *ToControllingExpr = nullptr;
7711 TypeSourceInfo *ToControllingType = nullptr;
7712 if (E->isExprPredicate())
7713 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7714 else
7715 ToControllingType = importChecked(Err, E->getControllingType());
7716 assert((ToControllingExpr || ToControllingType) &&
7717 "Either the controlling expr or type must be nonnull");
7718 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7719 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7720 if (Err)
7721 return std::move(Err);
7722
7724 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7725 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7726 return std::move(Err);
7727
7728 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7729 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7730 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7731 return std::move(Err);
7732
7733 const ASTContext &ToCtx = Importer.getToContext();
7734 if (E->isResultDependent()) {
7735 if (ToControllingExpr) {
7737 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7738 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7740 }
7742 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7743 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7745 }
7746
7747 if (ToControllingExpr) {
7749 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7750 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7752 }
7754 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7755 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7757}
7758
7760
7761 Error Err = Error::success();
7762 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7763 auto ToType = importChecked(Err, E->getType());
7764 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7765 if (Err)
7766 return std::move(Err);
7767
7768 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7769 E->getIdentKind(), E->isTransparent(),
7770 ToFunctionName);
7771}
7772
7774
7775 Error Err = Error::success();
7776 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7777 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7778 auto ToDecl = importChecked(Err, E->getDecl());
7779 auto ToLocation = importChecked(Err, E->getLocation());
7780 auto ToType = importChecked(Err, E->getType());
7781 if (Err)
7782 return std::move(Err);
7783
7784 NamedDecl *ToFoundD = nullptr;
7785 if (E->getDecl() != E->getFoundDecl()) {
7786 auto FoundDOrErr = import(E->getFoundDecl());
7787 if (!FoundDOrErr)
7788 return FoundDOrErr.takeError();
7789 ToFoundD = *FoundDOrErr;
7790 }
7791
7792 TemplateArgumentListInfo ToTAInfo;
7793 TemplateArgumentListInfo *ToResInfo = nullptr;
7794 if (E->hasExplicitTemplateArgs()) {
7795 if (Error Err =
7797 E->template_arguments(), ToTAInfo))
7798 return std::move(Err);
7799 ToResInfo = &ToTAInfo;
7800 }
7801
7802 auto *ToE = DeclRefExpr::Create(
7803 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7804 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7805 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7806 if (E->hadMultipleCandidates())
7807 ToE->setHadMultipleCandidates(true);
7808 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7809 return ToE;
7810}
7811
7813 ExpectedType TypeOrErr = import(E->getType());
7814 if (!TypeOrErr)
7815 return TypeOrErr.takeError();
7816
7817 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7818}
7819
7821 ExpectedExpr ToInitOrErr = import(E->getInit());
7822 if (!ToInitOrErr)
7823 return ToInitOrErr.takeError();
7824
7825 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7826 if (!ToEqualOrColonLocOrErr)
7827 return ToEqualOrColonLocOrErr.takeError();
7828
7829 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7830 // List elements from the second, the first is Init itself
7831 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7832 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7833 ToIndexExprs[I - 1] = *ToArgOrErr;
7834 else
7835 return ToArgOrErr.takeError();
7836 }
7837
7838 SmallVector<Designator, 4> ToDesignators(E->size());
7839 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7840 return std::move(Err);
7841
7843 Importer.getToContext(), ToDesignators,
7844 ToIndexExprs, *ToEqualOrColonLocOrErr,
7845 E->usesGNUSyntax(), *ToInitOrErr);
7846}
7847
7850 ExpectedType ToTypeOrErr = import(E->getType());
7851 if (!ToTypeOrErr)
7852 return ToTypeOrErr.takeError();
7853
7854 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7855 if (!ToLocationOrErr)
7856 return ToLocationOrErr.takeError();
7857
7858 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7859 *ToTypeOrErr, *ToLocationOrErr);
7860}
7861
7863 ExpectedType ToTypeOrErr = import(E->getType());
7864 if (!ToTypeOrErr)
7865 return ToTypeOrErr.takeError();
7866
7867 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7868 if (!ToLocationOrErr)
7869 return ToLocationOrErr.takeError();
7870
7872 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7873}
7874
7875
7877 ExpectedType ToTypeOrErr = import(E->getType());
7878 if (!ToTypeOrErr)
7879 return ToTypeOrErr.takeError();
7880
7881 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7882 if (!ToLocationOrErr)
7883 return ToLocationOrErr.takeError();
7884
7886 Importer.getToContext(), E->getValue(), E->isExact(),
7887 *ToTypeOrErr, *ToLocationOrErr);
7888}
7889
7891 auto ToTypeOrErr = import(E->getType());
7892 if (!ToTypeOrErr)
7893 return ToTypeOrErr.takeError();
7894
7895 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7896 if (!ToSubExprOrErr)
7897 return ToSubExprOrErr.takeError();
7898
7899 return new (Importer.getToContext()) ImaginaryLiteral(
7900 *ToSubExprOrErr, *ToTypeOrErr);
7901}
7902
7904 auto ToTypeOrErr = import(E->getType());
7905 if (!ToTypeOrErr)
7906 return ToTypeOrErr.takeError();
7907
7908 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7909 if (!ToLocationOrErr)
7910 return ToLocationOrErr.takeError();
7911
7912 return new (Importer.getToContext()) FixedPointLiteral(
7913 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7914 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7915}
7916
7918 ExpectedType ToTypeOrErr = import(E->getType());
7919 if (!ToTypeOrErr)
7920 return ToTypeOrErr.takeError();
7921
7922 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7923 if (!ToLocationOrErr)
7924 return ToLocationOrErr.takeError();
7925
7926 return new (Importer.getToContext()) CharacterLiteral(
7927 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7928}
7929
7931 ExpectedType ToTypeOrErr = import(E->getType());
7932 if (!ToTypeOrErr)
7933 return ToTypeOrErr.takeError();
7934
7936 if (Error Err = ImportArrayChecked(
7937 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7938 return std::move(Err);
7939
7940 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7941 E->getKind(), E->isPascal(), *ToTypeOrErr,
7942 ToLocations);
7943}
7944
7946
7947 Error Err = Error::success();
7948 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7949 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7950 auto ToType = importChecked(Err, E->getType());
7951 auto ToInitializer = importChecked(Err, E->getInitializer());
7952 if (Err)
7953 return std::move(Err);
7954
7955 return new (Importer.getToContext()) CompoundLiteralExpr(
7956 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7957 ToInitializer, E->isFileScope());
7958}
7959
7961
7962 Error Err = Error::success();
7963 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7964 auto ToType = importChecked(Err, E->getType());
7965 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7966 if (Err)
7967 return std::move(Err);
7968
7970 if (Error Err = ImportArrayChecked(
7971 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7972 ToExprs.begin()))
7973 return std::move(Err);
7974
7975 return new (Importer.getToContext()) AtomicExpr(
7976
7977 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7978}
7979
7981 Error Err = Error::success();
7982 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7983 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7984 auto ToLabel = importChecked(Err, E->getLabel());
7985 auto ToType = importChecked(Err, E->getType());
7986 if (Err)
7987 return std::move(Err);
7988
7989 return new (Importer.getToContext()) AddrLabelExpr(
7990 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7991}
7993 Error Err = Error::success();
7994 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7995 auto ToResult = importChecked(Err, E->getAPValueResult());
7996 if (Err)
7997 return std::move(Err);
7998
7999 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
8000}
8002 Error Err = Error::success();
8003 auto ToLParen = importChecked(Err, E->getLParen());
8004 auto ToRParen = importChecked(Err, E->getRParen());
8005 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8006 if (Err)
8007 return std::move(Err);
8008
8009 return new (Importer.getToContext())
8010 ParenExpr(ToLParen, ToRParen, ToSubExpr);
8011}
8012
8014 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
8015 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
8016 return std::move(Err);
8017
8018 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
8019 if (!ToLParenLocOrErr)
8020 return ToLParenLocOrErr.takeError();
8021
8022 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
8023 if (!ToRParenLocOrErr)
8024 return ToRParenLocOrErr.takeError();
8025
8026 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
8027 ToExprs, *ToRParenLocOrErr);
8028}
8029
8031 Error Err = Error::success();
8032 auto ToSubStmt = importChecked(Err, E->getSubStmt());
8033 auto ToType = importChecked(Err, E->getType());
8034 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8035 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8036 if (Err)
8037 return std::move(Err);
8038
8039 return new (Importer.getToContext())
8040 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8041 E->getTemplateDepth());
8042}
8043
8045 Error Err = Error::success();
8046 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8047 auto ToType = importChecked(Err, E->getType());
8048 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8049 if (Err)
8050 return std::move(Err);
8051
8052 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8053 E->hasStoredFPFeatures());
8054 UO->setType(ToType);
8055 UO->setSubExpr(ToSubExpr);
8056 UO->setOpcode(E->getOpcode());
8057 UO->setOperatorLoc(ToOperatorLoc);
8058 UO->setCanOverflow(E->canOverflow());
8059 if (E->hasStoredFPFeatures())
8060 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8061
8062 return UO;
8063}
8064
8066
8068 Error Err = Error::success();
8069 auto ToType = importChecked(Err, E->getType());
8070 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8071 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8072 if (Err)
8073 return std::move(Err);
8074
8075 if (E->isArgumentType()) {
8076 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8077 import(E->getArgumentTypeInfo());
8078 if (!ToArgumentTypeInfoOrErr)
8079 return ToArgumentTypeInfoOrErr.takeError();
8080
8081 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8082 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8083 ToRParenLoc);
8084 }
8085
8086 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8087 if (!ToArgumentExprOrErr)
8088 return ToArgumentExprOrErr.takeError();
8089
8090 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8091 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8092}
8093
8095 Error Err = Error::success();
8096 auto ToLHS = importChecked(Err, E->getLHS());
8097 auto ToRHS = importChecked(Err, E->getRHS());
8098 auto ToType = importChecked(Err, E->getType());
8099 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8100 if (Err)
8101 return std::move(Err);
8102
8104 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8105 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8106 E->getFPFeatures());
8107}
8108
8110 Error Err = Error::success();
8111 auto ToCond = importChecked(Err, E->getCond());
8112 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8113 auto ToLHS = importChecked(Err, E->getLHS());
8114 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8115 auto ToRHS = importChecked(Err, E->getRHS());
8116 auto ToType = importChecked(Err, E->getType());
8117 if (Err)
8118 return std::move(Err);
8119
8120 return new (Importer.getToContext()) ConditionalOperator(
8121 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8122 E->getValueKind(), E->getObjectKind());
8123}
8124
8127 Error Err = Error::success();
8128 auto ToCommon = importChecked(Err, E->getCommon());
8129 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8130 auto ToCond = importChecked(Err, E->getCond());
8131 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8132 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8133 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8134 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8135 auto ToType = importChecked(Err, E->getType());
8136 if (Err)
8137 return std::move(Err);
8138
8139 return new (Importer.getToContext()) BinaryConditionalOperator(
8140 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8141 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8142 E->getObjectKind());
8143}
8144
8147 Error Err = Error::success();
8148 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8149 if (Err)
8150 return std::move(Err);
8151
8152 return new (Importer.getToContext())
8153 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8154}
8155
8157 Error Err = Error::success();
8158 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8159 auto ToQueriedTypeSourceInfo =
8161 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8162 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8163 auto ToType = importChecked(Err, E->getType());
8164 if (Err)
8165 return std::move(Err);
8166
8167 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8168 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8169 ToDimensionExpression, ToEndLoc, ToType);
8170}
8171
8173 Error Err = Error::success();
8174 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8175 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8176 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8177 auto ToType = importChecked(Err, E->getType());
8178 if (Err)
8179 return std::move(Err);
8180
8181 return new (Importer.getToContext()) ExpressionTraitExpr(
8182 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8183 ToEndLoc, ToType);
8184}
8185
8187 Error Err = Error::success();
8188 auto ToLocation = importChecked(Err, E->getLocation());
8189 auto ToType = importChecked(Err, E->getType());
8190 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8191 if (Err)
8192 return std::move(Err);
8193
8194 return new (Importer.getToContext()) OpaqueValueExpr(
8195 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8196}
8197
8199 Error Err = Error::success();
8200 auto ToLHS = importChecked(Err, E->getLHS());
8201 auto ToRHS = importChecked(Err, E->getRHS());
8202 auto ToType = importChecked(Err, E->getType());
8203 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8204 if (Err)
8205 return std::move(Err);
8206
8207 return new (Importer.getToContext()) ArraySubscriptExpr(
8208 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8209 ToRBracketLoc);
8210}
8211
8214 Error Err = Error::success();
8215 auto ToLHS = importChecked(Err, E->getLHS());
8216 auto ToRHS = importChecked(Err, E->getRHS());
8217 auto ToType = importChecked(Err, E->getType());
8218 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8219 auto ToComputationResultType =
8221 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8222 if (Err)
8223 return std::move(Err);
8224
8226 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8227 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8228 E->getFPFeatures(),
8229 ToComputationLHSType, ToComputationResultType);
8230}
8231
8234 CXXCastPath Path;
8235 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8236 if (auto SpecOrErr = import(*I))
8237 Path.push_back(*SpecOrErr);
8238 else
8239 return SpecOrErr.takeError();
8240 }
8241 return Path;
8242}
8243
8245 ExpectedType ToTypeOrErr = import(E->getType());
8246 if (!ToTypeOrErr)
8247 return ToTypeOrErr.takeError();
8248
8249 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8250 if (!ToSubExprOrErr)
8251 return ToSubExprOrErr.takeError();
8252
8253 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8254 if (!ToBasePathOrErr)
8255 return ToBasePathOrErr.takeError();
8256
8258 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8259 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8260}
8261
8263 Error Err = Error::success();
8264 auto ToType = importChecked(Err, E->getType());
8265 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8266 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8267 if (Err)
8268 return std::move(Err);
8269
8270 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8271 if (!ToBasePathOrErr)
8272 return ToBasePathOrErr.takeError();
8273 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8274
8275 switch (E->getStmtClass()) {
8276 case Stmt::CStyleCastExprClass: {
8277 auto *CCE = cast<CStyleCastExpr>(E);
8278 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8279 if (!ToLParenLocOrErr)
8280 return ToLParenLocOrErr.takeError();
8281 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8282 if (!ToRParenLocOrErr)
8283 return ToRParenLocOrErr.takeError();
8285 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8286 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8287 *ToLParenLocOrErr, *ToRParenLocOrErr);
8288 }
8289
8290 case Stmt::CXXFunctionalCastExprClass: {
8291 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8292 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8293 if (!ToLParenLocOrErr)
8294 return ToLParenLocOrErr.takeError();
8295 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8296 if (!ToRParenLocOrErr)
8297 return ToRParenLocOrErr.takeError();
8299 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8300 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8301 *ToLParenLocOrErr, *ToRParenLocOrErr);
8302 }
8303
8304 case Stmt::ObjCBridgedCastExprClass: {
8305 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8306 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8307 if (!ToLParenLocOrErr)
8308 return ToLParenLocOrErr.takeError();
8309 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8310 if (!ToBridgeKeywordLocOrErr)
8311 return ToBridgeKeywordLocOrErr.takeError();
8312 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8313 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8314 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8315 }
8316 case Stmt::BuiltinBitCastExprClass: {
8317 auto *BBC = cast<BuiltinBitCastExpr>(E);
8318 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8319 if (!ToKWLocOrErr)
8320 return ToKWLocOrErr.takeError();
8321 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8322 if (!ToRParenLocOrErr)
8323 return ToRParenLocOrErr.takeError();
8324 return new (Importer.getToContext()) BuiltinBitCastExpr(
8325 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8326 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8327 }
8328 default:
8329 llvm_unreachable("Cast expression of unsupported type!");
8330 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8331 }
8332}
8333
8336 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8337 const OffsetOfNode &FromNode = E->getComponent(I);
8338
8339 SourceLocation ToBeginLoc, ToEndLoc;
8340
8341 if (FromNode.getKind() != OffsetOfNode::Base) {
8342 Error Err = Error::success();
8343 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8344 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8345 if (Err)
8346 return std::move(Err);
8347 }
8348
8349 switch (FromNode.getKind()) {
8351 ToNodes.push_back(
8352 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8353 break;
8354 case OffsetOfNode::Base: {
8355 auto ToBSOrErr = import(FromNode.getBase());
8356 if (!ToBSOrErr)
8357 return ToBSOrErr.takeError();
8358 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8359 break;
8360 }
8361 case OffsetOfNode::Field: {
8362 auto ToFieldOrErr = import(FromNode.getField());
8363 if (!ToFieldOrErr)
8364 return ToFieldOrErr.takeError();
8365 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8366 break;
8367 }
8369 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8370 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8371 break;
8372 }
8373 }
8374 }
8375
8377 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8378 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8379 if (!ToIndexExprOrErr)
8380 return ToIndexExprOrErr.takeError();
8381 ToExprs[I] = *ToIndexExprOrErr;
8382 }
8383
8384 Error Err = Error::success();
8385 auto ToType = importChecked(Err, E->getType());
8386 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8387 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8388 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8389 if (Err)
8390 return std::move(Err);
8391
8392 return OffsetOfExpr::Create(
8393 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8394 ToExprs, ToRParenLoc);
8395}
8396
8398 Error Err = Error::success();
8399 auto ToType = importChecked(Err, E->getType());
8400 auto ToOperand = importChecked(Err, E->getOperand());
8401 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8402 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8403 if (Err)
8404 return std::move(Err);
8405
8406 CanThrowResult ToCanThrow;
8407 if (E->isValueDependent())
8408 ToCanThrow = CT_Dependent;
8409 else
8410 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8411
8412 return new (Importer.getToContext()) CXXNoexceptExpr(
8413 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8414}
8415
8417 Error Err = Error::success();
8418 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8419 auto ToType = importChecked(Err, E->getType());
8420 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8421 if (Err)
8422 return std::move(Err);
8423
8424 return new (Importer.getToContext()) CXXThrowExpr(
8425 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8426}
8427
8429 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8430 if (!ToUsedLocOrErr)
8431 return ToUsedLocOrErr.takeError();
8432
8433 auto ToParamOrErr = import(E->getParam());
8434 if (!ToParamOrErr)
8435 return ToParamOrErr.takeError();
8436
8437 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8438 if (!UsedContextOrErr)
8439 return UsedContextOrErr.takeError();
8440
8441 // Import the default arg if it was not imported yet.
8442 // This is needed because it can happen that during the import of the
8443 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8444 // encountered here. The default argument for a ParmVarDecl is set in the
8445 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8446 // see VisitParmVarDecl).
8447 ParmVarDecl *ToParam = *ToParamOrErr;
8448 if (!ToParam->getDefaultArg()) {
8449 std::optional<ParmVarDecl *> FromParam =
8450 Importer.getImportedFromDecl(ToParam);
8451 assert(FromParam && "ParmVarDecl was not imported?");
8452
8453 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8454 return std::move(Err);
8455 }
8456 Expr *RewrittenInit = nullptr;
8457 if (E->hasRewrittenInit()) {
8458 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8459 if (!ExprOrErr)
8460 return ExprOrErr.takeError();
8461 RewrittenInit = ExprOrErr.get();
8462 }
8463 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8464 *ToParamOrErr, RewrittenInit,
8465 *UsedContextOrErr);
8466}
8467
8470 Error Err = Error::success();
8471 auto ToType = importChecked(Err, E->getType());
8472 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8473 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8474 if (Err)
8475 return std::move(Err);
8476
8477 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8478 ToType, ToTypeSourceInfo, ToRParenLoc);
8479}
8480
8483 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8484 if (!ToSubExprOrErr)
8485 return ToSubExprOrErr.takeError();
8486
8487 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8488 if (!ToDtorOrErr)
8489 return ToDtorOrErr.takeError();
8490
8491 ASTContext &ToCtx = Importer.getToContext();
8492 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8493 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8494}
8495
8497
8499 Error Err = Error::success();
8500 auto ToConstructor = importChecked(Err, E->getConstructor());
8501 auto ToType = importChecked(Err, E->getType());
8502 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8503 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8504 if (Err)
8505 return std::move(Err);
8506
8508 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8509 return std::move(Err);
8510
8512 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8513 ToParenOrBraceRange, E->hadMultipleCandidates(),
8516}
8517
8520 DeclContext *DC, *LexicalDC;
8521 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8522 return std::move(Err);
8523
8524 Error Err = Error::success();
8525 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8526 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8527 if (Err)
8528 return std::move(Err);
8529 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8530
8532 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8533 D->getManglingNumber()))
8534 return To;
8535
8536 To->setLexicalDeclContext(LexicalDC);
8537 LexicalDC->addDeclInternal(To);
8538 return To;
8539}
8540
8543 Error Err = Error::success();
8544 auto ToType = importChecked(Err, E->getType());
8545 Expr *ToTemporaryExpr = importChecked(
8546 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8547 auto ToMaterializedDecl =
8549 if (Err)
8550 return std::move(Err);
8551
8552 if (!ToTemporaryExpr)
8553 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8554
8555 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8556 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8557 ToMaterializedDecl);
8558
8559 return ToMTE;
8560}
8561
8563 Error Err = Error::success();
8564 auto *ToPattern = importChecked(Err, E->getPattern());
8565 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8566 if (Err)
8567 return std::move(Err);
8568
8569 return new (Importer.getToContext())
8570 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8571}
8572
8574 Error Err = Error::success();
8575 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8576 auto ToPack = importChecked(Err, E->getPack());
8577 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8578 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8579 if (Err)
8580 return std::move(Err);
8581
8582 UnsignedOrNone Length = std::nullopt;
8583 if (!E->isValueDependent())
8584 Length = E->getPackLength();
8585
8586 SmallVector<TemplateArgument, 8> ToPartialArguments;
8587 if (E->isPartiallySubstituted()) {
8589 ToPartialArguments))
8590 return std::move(Err);
8591 }
8592
8594 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8595 Length, ToPartialArguments);
8596}
8597
8598
8600 Error Err = Error::success();
8601 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8602 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8603 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8604 auto ToArraySize = importChecked(Err, E->getArraySize());
8605 auto ToInitializer = importChecked(Err, E->getInitializer());
8606 auto ToType = importChecked(Err, E->getType());
8607 auto ToAllocatedTypeSourceInfo =
8609 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8610 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8611 if (Err)
8612 return std::move(Err);
8613
8614 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8615 if (Error Err =
8616 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8617 return std::move(Err);
8618
8619 return CXXNewExpr::Create(
8620 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8621 ToOperatorDelete, E->implicitAllocationParameters(),
8622 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8623 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8624 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8625}
8626
8628 Error Err = Error::success();
8629 auto ToType = importChecked(Err, E->getType());
8630 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8631 auto ToArgument = importChecked(Err, E->getArgument());
8632 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8633 if (Err)
8634 return std::move(Err);
8635
8636 return new (Importer.getToContext()) CXXDeleteExpr(
8637 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8638 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8639 ToBeginLoc);
8640}
8641
8643 Error Err = Error::success();
8644 auto ToType = importChecked(Err, E->getType());
8645 auto ToLocation = importChecked(Err, E->getLocation());
8646 auto ToConstructor = importChecked(Err, E->getConstructor());
8647 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8648 if (Err)
8649 return std::move(Err);
8650
8652 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8653 return std::move(Err);
8654
8656 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8657 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8660 ToParenOrBraceRange);
8662 return ToE;
8663}
8664
8666 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8667 if (!ToSubExprOrErr)
8668 return ToSubExprOrErr.takeError();
8669
8671 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8672 return std::move(Err);
8673
8675 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8676 ToObjects);
8677}
8678
8680 Error Err = Error::success();
8681 auto ToCallee = importChecked(Err, E->getCallee());
8682 auto ToType = importChecked(Err, E->getType());
8683 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8684 if (Err)
8685 return std::move(Err);
8686
8688 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8689 return std::move(Err);
8690
8691 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8692 ToType, E->getValueKind(), ToRParenLoc,
8693 E->getFPFeatures());
8694}
8695
8697 ExpectedType ToTypeOrErr = import(E->getType());
8698 if (!ToTypeOrErr)
8699 return ToTypeOrErr.takeError();
8700
8701 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8702 if (!ToLocationOrErr)
8703 return ToLocationOrErr.takeError();
8704
8705 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8706 *ToTypeOrErr, E->isImplicit());
8707}
8708
8710 ExpectedType ToTypeOrErr = import(E->getType());
8711 if (!ToTypeOrErr)
8712 return ToTypeOrErr.takeError();
8713
8714 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8715 if (!ToLocationOrErr)
8716 return ToLocationOrErr.takeError();
8717
8718 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8719 *ToTypeOrErr, *ToLocationOrErr);
8720}
8721
8723 Error Err = Error::success();
8724 auto ToBase = importChecked(Err, E->getBase());
8725 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8726 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8727 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8728 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8729 auto ToType = importChecked(Err, E->getType());
8730 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8731 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8732 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8733 if (Err)
8734 return std::move(Err);
8735
8736 DeclAccessPair ToFoundDecl =
8738
8739 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8740
8741 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8742 if (E->hasExplicitTemplateArgs()) {
8743 if (Error Err =
8745 E->template_arguments(), ToTAInfo))
8746 return std::move(Err);
8747 ResInfo = &ToTAInfo;
8748 }
8749
8750 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8751 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8752 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8753 ResInfo, ToType, E->getValueKind(),
8754 E->getObjectKind(), E->isNonOdrUse());
8755}
8756
8759 Error Err = Error::success();
8760 auto ToBase = importChecked(Err, E->getBase());
8761 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8762 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8763 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8764 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8765 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8766 if (Err)
8767 return std::move(Err);
8768
8770 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8771 const IdentifierInfo *ToII = Importer.Import(FromII);
8772 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8773 if (!ToDestroyedTypeLocOrErr)
8774 return ToDestroyedTypeLocOrErr.takeError();
8775 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8776 } else {
8777 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8778 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8779 else
8780 return ToTIOrErr.takeError();
8781 }
8782
8783 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8784 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8785 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8786}
8787
8790 Error Err = Error::success();
8791 auto ToType = importChecked(Err, E->getType());
8792 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8793 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8794 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8795 auto ToFirstQualifierFoundInScope =
8797 if (Err)
8798 return std::move(Err);
8799
8800 Expr *ToBase = nullptr;
8801 if (!E->isImplicitAccess()) {
8802 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8803 ToBase = *ToBaseOrErr;
8804 else
8805 return ToBaseOrErr.takeError();
8806 }
8807
8808 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8809
8810 if (E->hasExplicitTemplateArgs()) {
8811 if (Error Err =
8813 E->template_arguments(), ToTAInfo))
8814 return std::move(Err);
8815 ResInfo = &ToTAInfo;
8816 }
8817 auto ToMember = importChecked(Err, E->getMember());
8818 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8819 if (Err)
8820 return std::move(Err);
8821 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8822
8823 // Import additional name location/type info.
8824 if (Error Err =
8825 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8826 return std::move(Err);
8827
8829 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8830 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8831 ToMemberNameInfo, ResInfo);
8832}
8833
8836 Error Err = Error::success();
8837 auto ToName = importChecked(Err, E->getTemplateName());
8838 auto ToDeclName = importChecked(Err, E->getName());
8839 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8840 if (Err)
8841 return std::move(Err);
8842
8843 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8844 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8845 return std::move(Err);
8846
8847 TemplateArgumentListInfo ToTAInfo;
8848 if (Error Err =
8850 E->template_arguments(), ToTAInfo))
8851 return std::move(Err);
8852
8853 return DependentTemplateIdExpr::Create(Importer.getToContext(), ToNameInfo,
8854 ToName, ToTAInfo);
8855}
8856
8859 Error Err = Error::success();
8860 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8861 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8862 auto ToDeclName = importChecked(Err, E->getDeclName());
8863 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8864 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8865 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8866 if (Err)
8867 return std::move(Err);
8868
8869 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8870 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8871 return std::move(Err);
8872
8873 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8874 TemplateArgumentListInfo *ResInfo = nullptr;
8875 if (E->hasExplicitTemplateArgs()) {
8876 if (Error Err =
8878 return std::move(Err);
8879 ResInfo = &ToTAInfo;
8880 }
8881
8883 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8884 ToNameInfo, ResInfo);
8885}
8886
8889 Error Err = Error::success();
8890 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8891 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8892 auto ToType = importChecked(Err, E->getType());
8893 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8894 if (Err)
8895 return std::move(Err);
8896
8898 if (Error Err =
8899 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8900 return std::move(Err);
8901
8903 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8904 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8905}
8906
8909 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8910 if (!ToNamingClassOrErr)
8911 return ToNamingClassOrErr.takeError();
8912
8913 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8914 if (!ToQualifierLocOrErr)
8915 return ToQualifierLocOrErr.takeError();
8916
8917 Error Err = Error::success();
8918 auto ToName = importChecked(Err, E->getName());
8919 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8920 if (Err)
8921 return std::move(Err);
8922 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8923
8924 // Import additional name location/type info.
8925 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8926 return std::move(Err);
8927
8928 UnresolvedSet<8> ToDecls;
8929 for (auto *D : E->decls())
8930 if (auto ToDOrErr = import(D))
8931 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8932 else
8933 return ToDOrErr.takeError();
8934
8935 if (E->hasExplicitTemplateArgs()) {
8936 TemplateArgumentListInfo ToTAInfo;
8939 ToTAInfo))
8940 return std::move(Err);
8941
8942 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8943 if (!ToTemplateKeywordLocOrErr)
8944 return ToTemplateKeywordLocOrErr.takeError();
8945
8946 const bool KnownDependent =
8947 (E->getDependence() & ExprDependence::TypeValue) ==
8948 ExprDependence::TypeValue;
8950 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8951 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8952 ToDecls.begin(), ToDecls.end(), KnownDependent,
8953 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8954 }
8955
8957 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8958 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8959 /*KnownDependent=*/E->isTypeDependent(),
8960 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8961}
8962
8965 Error Err = Error::success();
8966 auto ToType = importChecked(Err, E->getType());
8967 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8968 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8969 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8970 auto ToName = importChecked(Err, E->getName());
8971 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8972 if (Err)
8973 return std::move(Err);
8974
8975 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8976 // Import additional name location/type info.
8977 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8978 return std::move(Err);
8979
8980 UnresolvedSet<8> ToDecls;
8981 for (Decl *D : E->decls())
8982 if (auto ToDOrErr = import(D))
8983 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8984 else
8985 return ToDOrErr.takeError();
8986
8987 TemplateArgumentListInfo ToTAInfo;
8988 TemplateArgumentListInfo *ResInfo = nullptr;
8989 if (E->hasExplicitTemplateArgs()) {
8990 TemplateArgumentListInfo FromTAInfo;
8991 E->copyTemplateArgumentsInto(FromTAInfo);
8992 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8993 return std::move(Err);
8994 ResInfo = &ToTAInfo;
8995 }
8996
8997 Expr *ToBase = nullptr;
8998 if (!E->isImplicitAccess()) {
8999 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
9000 ToBase = *ToBaseOrErr;
9001 else
9002 return ToBaseOrErr.takeError();
9003 }
9004
9006 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
9007 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
9008 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
9009}
9010
9012 Error Err = Error::success();
9013 auto ToCallee = importChecked(Err, E->getCallee());
9014 auto ToType = importChecked(Err, E->getType());
9015 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9016 if (Err)
9017 return std::move(Err);
9018
9019 unsigned NumArgs = E->getNumArgs();
9020 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
9021 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
9022 return std::move(Err);
9023
9024 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
9026 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
9027 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
9028 OCE->getADLCallKind());
9029 }
9030
9031 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
9032 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
9033 /*MinNumArgs=*/0, E->getADLCallKind());
9034}
9035
9037 CXXRecordDecl *FromClass = E->getLambdaClass();
9038 auto ToClassOrErr = import(FromClass);
9039 if (!ToClassOrErr)
9040 return ToClassOrErr.takeError();
9041 CXXRecordDecl *ToClass = *ToClassOrErr;
9042
9043 auto ToCallOpOrErr = import(E->getCallOperator());
9044 if (!ToCallOpOrErr)
9045 return ToCallOpOrErr.takeError();
9046
9047 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
9048 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
9049 return std::move(Err);
9050
9051 Error Err = Error::success();
9052 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
9053 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
9054 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9055 if (Err)
9056 return std::move(Err);
9057
9058 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
9059 E->getCaptureDefault(), ToCaptureDefaultLoc,
9061 E->hasExplicitResultType(), ToCaptureInits,
9062 ToEndLoc, E->containsUnexpandedParameterPack());
9063}
9064
9065
9067 Error Err = Error::success();
9068 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9069 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9070 auto ToType = importChecked(Err, E->getType());
9071 if (Err)
9072 return std::move(Err);
9073
9074 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9075 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9076 return std::move(Err);
9077
9078 ASTContext &ToCtx = Importer.getToContext();
9079 InitListExpr *To = new (ToCtx)
9080 InitListExpr(ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc, E->isExplicit());
9081 To->setType(ToType);
9082
9083 if (E->hasArrayFiller()) {
9084 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9085 To->setArrayFiller(*ToFillerOrErr);
9086 else
9087 return ToFillerOrErr.takeError();
9088 }
9089
9090 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9091 if (auto ToFDOrErr = import(FromFD))
9092 To->setInitializedFieldInUnion(*ToFDOrErr);
9093 else
9094 return ToFDOrErr.takeError();
9095 }
9096
9097 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9098 if (auto ToSyntFormOrErr = import(SyntForm))
9099 To->setSyntacticForm(*ToSyntFormOrErr);
9100 else
9101 return ToSyntFormOrErr.takeError();
9102 }
9103
9104 // Copy InitListExprBitfields, which are not handled in the ctor of
9105 // InitListExpr.
9107
9108 return To;
9109}
9110
9113 ExpectedType ToTypeOrErr = import(E->getType());
9114 if (!ToTypeOrErr)
9115 return ToTypeOrErr.takeError();
9116
9117 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9118 if (!ToSubExprOrErr)
9119 return ToSubExprOrErr.takeError();
9120
9121 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9122 *ToTypeOrErr, *ToSubExprOrErr);
9123}
9124
9127 Error Err = Error::success();
9128 auto ToLocation = importChecked(Err, E->getLocation());
9129 auto ToType = importChecked(Err, E->getType());
9130 auto ToConstructor = importChecked(Err, E->getConstructor());
9131 if (Err)
9132 return std::move(Err);
9133
9134 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9135 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9136 E->inheritedFromVBase());
9137}
9138
9140 Error Err = Error::success();
9141 auto ToType = importChecked(Err, E->getType());
9142 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9143 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9144 if (Err)
9145 return std::move(Err);
9146
9147 return new (Importer.getToContext()) ArrayInitLoopExpr(
9148 ToType, ToCommonExpr, ToSubExpr);
9149}
9150
9152 ExpectedType ToTypeOrErr = import(E->getType());
9153 if (!ToTypeOrErr)
9154 return ToTypeOrErr.takeError();
9155 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9156}
9157
9159 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9160 if (!ToBeginLocOrErr)
9161 return ToBeginLocOrErr.takeError();
9162
9163 auto ToFieldOrErr = import(E->getField());
9164 if (!ToFieldOrErr)
9165 return ToFieldOrErr.takeError();
9166
9167 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9168 if (!UsedContextOrErr)
9169 return UsedContextOrErr.takeError();
9170
9171 FieldDecl *ToField = *ToFieldOrErr;
9172 assert(ToField->hasInClassInitializer() &&
9173 "Field should have in-class initializer if there is a default init "
9174 "expression that uses it.");
9175 if (!ToField->getInClassInitializer()) {
9176 // The in-class initializer may be not yet set in "To" AST even if the
9177 // field is already there. This must be set here to make construction of
9178 // CXXDefaultInitExpr work.
9179 auto ToInClassInitializerOrErr =
9180 import(E->getField()->getInClassInitializer());
9181 if (!ToInClassInitializerOrErr)
9182 return ToInClassInitializerOrErr.takeError();
9183 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9184 }
9185
9186 Expr *RewrittenInit = nullptr;
9187 if (E->hasRewrittenInit()) {
9188 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9189 if (!ExprOrErr)
9190 return ExprOrErr.takeError();
9191 RewrittenInit = ExprOrErr.get();
9192 }
9193
9194 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9195 ToField, *UsedContextOrErr, RewrittenInit);
9196}
9197
9199 Error Err = Error::success();
9200 auto ToType = importChecked(Err, E->getType());
9201 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9202 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9203 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9204 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9205 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9206 if (Err)
9207 return std::move(Err);
9208
9210 CastKind CK = E->getCastKind();
9211 auto ToBasePathOrErr = ImportCastPath(E);
9212 if (!ToBasePathOrErr)
9213 return ToBasePathOrErr.takeError();
9214
9215 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9217 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9218 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9219 ToAngleBrackets);
9220 } else if (isa<CXXDynamicCastExpr>(E)) {
9222 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9223 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9224 } else if (isa<CXXReinterpretCastExpr>(E)) {
9226 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9227 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9228 } else if (isa<CXXConstCastExpr>(E)) {
9230 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9231 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9232 } else {
9233 llvm_unreachable("Unknown cast type");
9234 return make_error<ASTImportError>();
9235 }
9236}
9237
9240 Error Err = Error::success();
9241 auto ToType = importChecked(Err, E->getType());
9242 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9243 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9244 auto ToParamType = importChecked(Err, E->getParameterType());
9245 auto ToReplacement = importChecked(Err, E->getReplacement());
9246 if (Err)
9247 return std::move(Err);
9248
9249 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9250 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9251 ToParamType, E->getIndex(), E->getPackIndex(), E->getFinal());
9252}
9253
9255 Error Err = Error::success();
9256 auto ToType = importChecked(Err, E->getType());
9257 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9258 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9259 if (Err)
9260 return std::move(Err);
9261
9263 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9264 return std::move(Err);
9265
9266 if (E->isStoredAsBoolean()) {
9267 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9268 // Value is always false.
9269 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9270 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9271 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9272 }
9273 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9274 E->getTrait(), ToArgs, ToEndLoc,
9275 E->getAPValue());
9276}
9277
9279 ExpectedType ToTypeOrErr = import(E->getType());
9280 if (!ToTypeOrErr)
9281 return ToTypeOrErr.takeError();
9282
9283 auto ToSourceRangeOrErr = import(E->getSourceRange());
9284 if (!ToSourceRangeOrErr)
9285 return ToSourceRangeOrErr.takeError();
9286
9287 if (E->isTypeOperand()) {
9288 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9289 return new (Importer.getToContext()) CXXTypeidExpr(
9290 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9291 else
9292 return ToTSIOrErr.takeError();
9293 }
9294
9295 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9296 if (!ToExprOperandOrErr)
9297 return ToExprOperandOrErr.takeError();
9298
9299 return new (Importer.getToContext()) CXXTypeidExpr(
9300 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9301}
9302
9304 Error Err = Error::success();
9305
9306 QualType ToType = importChecked(Err, E->getType());
9307 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9308 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9309 Expr *ToLHS = importChecked(Err, E->getLHS());
9310 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9311 Expr *ToRHS = importChecked(Err, E->getRHS());
9312 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9313
9314 if (Err)
9315 return std::move(Err);
9316
9317 return new (Importer.getToContext())
9318 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9319 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9320}
9321
9323 Error Err = Error::success();
9324 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9325 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9326 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9327
9328 auto Body = importChecked(Err, E->getBody());
9329 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9330 if (Err)
9331 return std::move(Err);
9332 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9333 if (Error Err =
9334 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9335 return std::move(Err);
9337 E->getRequirements().size());
9338 if (Error Err =
9339 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9340 return std::move(Err);
9341 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9342 LParenLoc, LocalParameters, RParenLoc,
9343 Requirements, RBraceLoc);
9344}
9345
9348 Error Err = Error::success();
9349 auto CL = importChecked(Err, E->getConceptReference());
9350 auto CSD = importChecked(Err, E->getSpecializationDecl());
9351 if (Err)
9352 return std::move(Err);
9353 if (E->isValueDependent())
9355 Importer.getToContext(), CL,
9356 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9357 ConstraintSatisfaction Satisfaction;
9358 if (Error Err =
9360 return std::move(Err);
9362 Importer.getToContext(), CL,
9363 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9364}
9365
9368 Error Err = Error::success();
9369 auto ToType = importChecked(Err, E->getType());
9370 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9371 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9372 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9373 if (Err)
9374 return std::move(Err);
9375
9376 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9377 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9378 E->getIndex(), E->getFinal());
9379}
9380
9383 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9384 return std::move(Err);
9385 auto ToSyntOrErr = import(E->getSyntacticForm());
9386 if (!ToSyntOrErr)
9387 return ToSyntOrErr.takeError();
9388 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9389 ToSemantics, E->getResultExprIndex());
9390}
9391
9394 Error Err = Error::success();
9395 auto ToType = importChecked(Err, E->getType());
9396 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9397 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9398 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9399 if (Err)
9400 return std::move(Err);
9401
9402 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9403 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9404 return std::move(Err);
9405 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9406 E->getUserSpecifiedInitExprs().size(),
9407 ToInitLoc, ToBeginLoc, ToEndLoc);
9408}
9409
9412 Error Err = Error::success();
9413 auto ToRange = importChecked(Err, E->getRangeExpr());
9414 auto ToIndex = importChecked(Err, E->getIndexExpr());
9415 if (Err)
9416 return std::move(Err);
9417
9418 return new (Importer.getToContext())
9419 CXXExpansionSelectExpr(Importer.getToContext(), ToRange, ToIndex);
9420}
9421
9423 CXXMethodDecl *FromMethod) {
9424 Error ImportErrors = Error::success();
9425 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9426 if (auto ImportedOrErr = import(FromOverriddenMethod))
9428 (*ImportedOrErr)->getCanonicalDecl()));
9429 else
9430 ImportErrors =
9431 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9432 }
9433 return ImportErrors;
9434}
9435
9437 ASTContext &FromContext, FileManager &FromFileManager,
9438 bool MinimalImport,
9439 std::shared_ptr<ASTImporterSharedState> SharedState)
9440 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9441 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9442 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9443
9444 // Create a default state without the lookup table: LLDB case.
9445 if (!SharedState) {
9446 this->SharedState = std::make_shared<ASTImporterSharedState>();
9447 }
9448
9449 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9450 ToContext.getTranslationUnitDecl();
9451}
9452
9453ASTImporter::~ASTImporter() = default;
9454
9456 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9457 "Try to get field index for non-field.");
9458
9459 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9460 if (!Owner)
9461 return std::nullopt;
9462
9463 unsigned Index = 0;
9464 for (const auto *D : Owner->decls()) {
9465 if (D == F)
9466 return Index;
9467
9469 ++Index;
9470 }
9471
9472 llvm_unreachable("Field was not found in its parent context.");
9473
9474 return std::nullopt;
9475}
9476
9477ASTImporter::FoundDeclsTy
9478ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9479 // We search in the redecl context because of transparent contexts.
9480 // E.g. a simple C language enum is a transparent context:
9481 // enum E { A, B };
9482 // Now if we had a global variable in the TU
9483 // int A;
9484 // then the enum constant 'A' and the variable 'A' violates ODR.
9485 // We can diagnose this only if we search in the redecl context.
9486 DeclContext *ReDC = DC->getRedeclContext();
9487 if (SharedState->getLookupTable()) {
9488 if (ReDC->isNamespace()) {
9489 // Namespaces can be reopened.
9490 // Lookup table does not handle this, we must search here in all linked
9491 // namespaces.
9492 FoundDeclsTy Result;
9493 SmallVector<Decl *, 2> NSChain =
9495 dyn_cast<NamespaceDecl>(ReDC));
9496 for (auto *D : NSChain) {
9498 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9499 Name);
9501 }
9502 return Result;
9503 } else {
9505 SharedState->getLookupTable()->lookup(ReDC, Name);
9506 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9507 }
9508 } else {
9509 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9510 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9511 // We must search by the slow case of localUncachedLookup because that is
9512 // working even if there is no LookupPtr for the DC. We could use
9513 // DC::buildLookup() to create the LookupPtr, but that would load external
9514 // decls again, we must avoid that case.
9515 // Also, even if we had the LookupPtr, we must find Decls which are not
9516 // in the LookupPtr, so we need the slow case.
9517 // These cases are handled in ASTImporterLookupTable, but we cannot use
9518 // that with LLDB since that traverses through the AST which initiates the
9519 // load of external decls again via DC::decls(). And again, we must avoid
9520 // loading external decls during the import.
9521 if (Result.empty())
9522 ReDC->localUncachedLookup(Name, Result);
9523 return Result;
9524 }
9525}
9526
9527void ASTImporter::AddToLookupTable(Decl *ToD) {
9528 SharedState->addDeclToLookup(ToD);
9529}
9530
9532 // Import the decl using ASTNodeImporter.
9533 ASTNodeImporter Importer(*this);
9534 return Importer.Visit(FromD);
9535}
9536
9538 MapImported(FromD, ToD);
9539}
9540
9543 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9544 if (Expected<Expr *> R = Import(CLE))
9546 }
9547
9548 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9549 // ASTNodeImporter.
9550 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9551}
9552
9554 if (!FromT)
9555 return FromT;
9556
9557 // Check whether we've already imported this type.
9558 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9559 ImportedTypes.find(FromT);
9560 if (Pos != ImportedTypes.end())
9561 return Pos->second;
9562
9563 // Import the type.
9564 ASTNodeImporter Importer(*this);
9565 ExpectedType ToTOrErr = Importer.Visit(FromT);
9566 if (!ToTOrErr)
9567 return ToTOrErr.takeError();
9568
9569 // Record the imported type.
9570 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9571
9572 return ToTOrErr->getTypePtr();
9573}
9574
9576 if (FromT.isNull())
9577 return QualType{};
9578
9579 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9580 if (!ToTyOrErr)
9581 return ToTyOrErr.takeError();
9582
9583 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9584}
9585
9587 if (!FromTSI)
9588 return FromTSI;
9589
9590 // FIXME: For now we just create a "trivial" type source info based
9591 // on the type and a single location. Implement a real version of this.
9592 ExpectedType TOrErr = Import(FromTSI->getType());
9593 if (!TOrErr)
9594 return TOrErr.takeError();
9595 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9596 if (!BeginLocOrErr)
9597 return BeginLocOrErr.takeError();
9598
9599 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9600}
9601
9602namespace {
9603// To use this object, it should be created before the new attribute is created,
9604// and destructed after it is created. The construction already performs the
9605// import of the data.
9606template <typename T> struct AttrArgImporter {
9607 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9608 AttrArgImporter(AttrArgImporter<T> &&) = default;
9609 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9610 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9611
9612 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9613 : To(I.importChecked(Err, From)) {}
9614
9615 const T &value() { return To; }
9616
9617private:
9618 T To;
9619};
9620
9621// To use this object, it should be created before the new attribute is created,
9622// and destructed after it is created. The construction already performs the
9623// import of the data. The array data is accessible in a pointer form, this form
9624// is used by the attribute classes. This object should be created once for the
9625// array data to be imported (the array size is not imported, just copied).
9626template <typename T> struct AttrArgArrayImporter {
9627 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9628 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9629 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9630 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9631
9632 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9633 const llvm::iterator_range<T *> &From,
9634 unsigned ArraySize) {
9635 if (Err)
9636 return;
9637 To.reserve(ArraySize);
9638 Err = I.ImportContainerChecked(From, To);
9639 }
9640
9641 T *value() { return To.data(); }
9642
9643private:
9644 llvm::SmallVector<T, 2> To;
9645};
9646
9647class AttrImporter {
9648 Error Err{Error::success()};
9649 Attr *ToAttr = nullptr;
9650 ASTImporter &Importer;
9651 ASTNodeImporter NImporter;
9652
9653public:
9654 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9655
9656 // Create an "importer" for an attribute parameter.
9657 // Result of the 'value()' of that object is to be passed to the function
9658 // 'importAttr', in the order that is expected by the attribute class.
9659 template <class T> AttrArgImporter<T> importArg(const T &From) {
9660 return AttrArgImporter<T>(NImporter, Err, From);
9661 }
9662
9663 // Create an "importer" for an attribute parameter that has array type.
9664 // Result of the 'value()' of that object is to be passed to the function
9665 // 'importAttr', then the size of the array as next argument.
9666 template <typename T>
9667 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9668 unsigned ArraySize) {
9669 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9670 }
9671
9672 // Create an attribute object with the specified arguments.
9673 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9674 // should be values that are passed to the 'Create' function of the attribute.
9675 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9676 // used here.) As much data is copied or imported from the old attribute
9677 // as possible. The passed arguments should be already imported.
9678 // If an import error happens, the internal error is set to it, and any
9679 // further import attempt is ignored.
9680 template <typename T, typename... Arg>
9681 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9682 static_assert(std::is_base_of<Attr, T>::value,
9683 "T should be subclass of Attr.");
9684 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9685
9686 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9687 const IdentifierInfo *ToScopeName =
9688 Importer.Import(FromAttr->getScopeName());
9689 SourceRange ToAttrRange =
9690 NImporter.importChecked(Err, FromAttr->getRange());
9691 SourceLocation ToScopeLoc =
9692 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9693
9694 if (Err)
9695 return;
9696
9697 AttributeCommonInfo ToI(
9698 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9699 FromAttr->getParsedKind(), FromAttr->getForm());
9700 // The "SemanticSpelling" is not needed to be passed to the constructor.
9701 // That value is recalculated from the SpellingListIndex if needed.
9702 ToAttr = T::Create(Importer.getToContext(),
9703 std::forward<Arg>(ImportedArg)..., ToI);
9704
9705 ToAttr->setImplicit(FromAttr->isImplicit());
9706 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9707 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9708 ToInheritableAttr->setInherited(FromAttr->isInherited());
9709 }
9710
9711 // Create a clone of the 'FromAttr' and import its source range only.
9712 // This causes objects with invalid references to be created if the 'FromAttr'
9713 // contains other data that should be imported.
9714 void cloneAttr(const Attr *FromAttr) {
9715 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9716
9717 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9718 if (Err)
9719 return;
9720
9721 ToAttr = FromAttr->clone(Importer.getToContext());
9722 ToAttr->setRange(ToRange);
9723 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9724 }
9725
9726 // Get the result of the previous import attempt (can be used only once).
9727 llvm::Expected<Attr *> getResult() && {
9728 if (Err)
9729 return std::move(Err);
9730 assert(ToAttr && "Attribute should be created.");
9731 return ToAttr;
9732 }
9733};
9734} // namespace
9735
9737 AttrImporter AI(*this);
9738
9739 // FIXME: Is there some kind of AttrVisitor to use here?
9740 switch (FromAttr->getKind()) {
9741 case attr::Aligned: {
9742 auto *From = cast<AlignedAttr>(FromAttr);
9743 if (From->isAlignmentExpr())
9744 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9745 else
9746 AI.importAttr(From, false,
9747 AI.importArg(From->getAlignmentType()).value());
9748 break;
9749 }
9750
9751 case attr::AlignValue: {
9752 auto *From = cast<AlignValueAttr>(FromAttr);
9753 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9754 break;
9755 }
9756
9757 case attr::Format: {
9758 const auto *From = cast<FormatAttr>(FromAttr);
9759 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9760 From->getFirstArg());
9761 break;
9762 }
9763
9764 case attr::EnableIf: {
9765 const auto *From = cast<EnableIfAttr>(FromAttr);
9766 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9767 From->getMessage());
9768 break;
9769 }
9770
9771 case attr::AssertCapability: {
9772 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9773 AI.importAttr(From,
9774 AI.importArrayArg(From->args(), From->args_size()).value(),
9775 From->args_size());
9776 break;
9777 }
9778 case attr::AcquireCapability: {
9779 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9780 AI.importAttr(From,
9781 AI.importArrayArg(From->args(), From->args_size()).value(),
9782 From->args_size());
9783 break;
9784 }
9785 case attr::TryAcquireCapability: {
9786 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9787 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9788 AI.importArrayArg(From->args(), From->args_size()).value(),
9789 From->args_size());
9790 break;
9791 }
9792 case attr::ReleaseCapability: {
9793 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9794 AI.importAttr(From,
9795 AI.importArrayArg(From->args(), From->args_size()).value(),
9796 From->args_size());
9797 break;
9798 }
9799 case attr::RequiresCapability: {
9800 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9801 AI.importAttr(From,
9802 AI.importArrayArg(From->args(), From->args_size()).value(),
9803 From->args_size());
9804 break;
9805 }
9806 case attr::GuardedBy: {
9807 const auto *From = cast<GuardedByAttr>(FromAttr);
9808 AI.importAttr(From,
9809 AI.importArrayArg(From->args(), From->args_size()).value(),
9810 From->args_size());
9811 break;
9812 }
9813 case attr::PtGuardedBy: {
9814 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9815 AI.importAttr(From,
9816 AI.importArrayArg(From->args(), From->args_size()).value(),
9817 From->args_size());
9818 break;
9819 }
9820 case attr::AcquiredAfter: {
9821 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9822 AI.importAttr(From,
9823 AI.importArrayArg(From->args(), From->args_size()).value(),
9824 From->args_size());
9825 break;
9826 }
9827 case attr::AcquiredBefore: {
9828 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9829 AI.importAttr(From,
9830 AI.importArrayArg(From->args(), From->args_size()).value(),
9831 From->args_size());
9832 break;
9833 }
9834 case attr::LockReturned: {
9835 const auto *From = cast<LockReturnedAttr>(FromAttr);
9836 AI.importAttr(From, AI.importArg(From->getArg()).value());
9837 break;
9838 }
9839 case attr::LocksExcluded: {
9840 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9841 AI.importAttr(From,
9842 AI.importArrayArg(From->args(), From->args_size()).value(),
9843 From->args_size());
9844 break;
9845 }
9846 default: {
9847 // The default branch works for attributes that have no arguments to import.
9848 // FIXME: Handle every attribute type that has arguments of type to import
9849 // (most often Expr* or Decl* or type) in the switch above.
9850 AI.cloneAttr(FromAttr);
9851 break;
9852 }
9853 }
9854
9855 return std::move(AI).getResult();
9856}
9857
9859 return ImportedDecls.lookup(FromD);
9860}
9861
9863 auto FromDPos = ImportedFromDecls.find(ToD);
9864 if (FromDPos == ImportedFromDecls.end())
9865 return nullptr;
9866 return FromDPos->second->getTranslationUnitDecl();
9867}
9868
9870 if (!FromD)
9871 return nullptr;
9872
9873 // Push FromD to the stack, and remove that when we return.
9874 ImportPath.push(FromD);
9875 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9876
9877 // Check whether there was a previous failed import.
9878 // If yes return the existing error.
9879 if (auto Error = getImportDeclErrorIfAny(FromD))
9880 return make_error<ASTImportError>(*Error);
9881
9882 // Check whether we've already imported this declaration.
9883 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9884 if (ToD) {
9885 // Already imported (possibly from another TU) and with an error.
9886 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9887 setImportDeclError(FromD, *Error);
9888 return make_error<ASTImportError>(*Error);
9889 }
9890
9891 // If FromD has some updated flags after last import, apply it.
9892 updateFlags(FromD, ToD);
9893 // If we encounter a cycle during an import then we save the relevant part
9894 // of the import path associated to the Decl.
9895 if (ImportPath.hasCycleAtBack())
9896 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9897 return ToD;
9898 }
9899
9900 // Import the declaration.
9901 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9902 if (!ToDOrErr) {
9903 // Failed to import.
9904
9905 auto Pos = ImportedDecls.find(FromD);
9906 bool ToDWasCreated = Pos != ImportedDecls.end();
9907 // Capture the mapped decl before erasing: the iterator is invalidated by
9908 // the erase below under backward-shift deletion, but it is still needed
9909 // further down to record the import error.
9910 Decl *CreatedToD = ToDWasCreated ? Pos->second : nullptr;
9911 if (ToDWasCreated) {
9912 // Import failed after the object was created.
9913 // Remove all references to it.
9914 auto *ToD = CreatedToD;
9915 ImportedDecls.erase(Pos);
9916
9917 // Remove the imported type mapping as well.
9918 // The imported type can point to a declaration that failed to import
9919 // later.
9920 if (const auto *FromTD = dyn_cast<TagDecl>(FromD)) {
9921 if (const Type *FromTy =
9922 getFromContext().getCanonicalTagType(FromTD).getTypePtr()) {
9923 ImportedTypes.erase(FromTy);
9924 }
9925 }
9926
9927 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9928 // (e.g. with namespaces) that several decls from the 'from' context are
9929 // mapped to the same decl in the 'to' context. If we removed entries
9930 // from the LookupTable here then we may end up removing them multiple
9931 // times.
9932
9933 // The Lookuptable contains decls only which are in the 'to' context.
9934 // Remove from the Lookuptable only if it is *imported* into the 'to'
9935 // context (and do not remove it if it was added during the initial
9936 // traverse of the 'to' context).
9937 auto PosF = ImportedFromDecls.find(ToD);
9938 if (PosF != ImportedFromDecls.end()) {
9939 // In the case of TypedefNameDecl we create the Decl first and only
9940 // then we import and set its DeclContext. So, the DC might not be set
9941 // when we reach here.
9942 if (ToD->getDeclContext())
9943 SharedState->removeDeclFromLookup(ToD);
9944 ImportedFromDecls.erase(PosF);
9945 }
9946
9947 // FIXME: AST may contain remaining references to the failed object.
9948 // However, the ImportDeclErrors in the shared state contains all the
9949 // failed objects together with their error.
9950 }
9951
9952 // Error encountered for the first time.
9953 // After takeError the error is not usable any more in ToDOrErr.
9954 // Get a copy of the error object (any more simple solution for this?).
9955 ASTImportError ErrOut;
9956 handleAllErrors(ToDOrErr.takeError(),
9957 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9958 setImportDeclError(FromD, ErrOut);
9959 // Set the error for the mapped to Decl, which is in the "to" context.
9960 if (ToDWasCreated)
9961 SharedState->setImportDeclError(CreatedToD, ErrOut);
9962
9963 // Set the error for all nodes which have been created before we
9964 // recognized the error.
9965 for (const auto &Path : SavedImportPaths[FromD]) {
9966 // The import path contains import-dependency nodes first.
9967 // Save the node that was imported as dependency of the current node.
9968 Decl *PrevFromDi = FromD;
9969 for (Decl *FromDi : Path) {
9970 // Begin and end of the path equals 'FromD', skip it.
9971 if (FromDi == FromD)
9972 continue;
9973 // We should not set import error on a node and all following nodes in
9974 // the path if child import errors are ignored.
9975 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9976 PrevFromDi))
9977 break;
9978 PrevFromDi = FromDi;
9979 setImportDeclError(FromDi, ErrOut);
9980
9981 if (const auto *FromTDi = dyn_cast<TagDecl>(FromDi)) {
9982 if (const Type *FromTyi =
9983 getFromContext().getCanonicalTagType(FromTDi).getTypePtr()) {
9984 ImportedTypes.erase(FromTyi);
9985 }
9986 }
9987
9988 //FIXME Should we remove these Decls from ImportedDecls?
9989 // Set the error for the mapped to Decl, which is in the "to" context.
9990 auto Ii = ImportedDecls.find(FromDi);
9991 if (Ii != ImportedDecls.end())
9992 SharedState->setImportDeclError(Ii->second, ErrOut);
9993 // FIXME Should we remove these Decls from the LookupTable,
9994 // and from ImportedFromDecls?
9995 }
9996 }
9997 SavedImportPaths.erase(FromD);
9998
9999 // Do not return ToDOrErr, error was taken out of it.
10000 return make_error<ASTImportError>(ErrOut);
10001 }
10002
10003 ToD = *ToDOrErr;
10004
10005 // FIXME: Handle the "already imported with error" case. We can get here
10006 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
10007 // previously failed create was requested).
10008 // Later GetImportedOrCreateDecl can be updated to return the error.
10009 if (!ToD) {
10010 auto Err = getImportDeclErrorIfAny(FromD);
10011 assert(Err);
10012 return make_error<ASTImportError>(*Err);
10013 }
10014
10015 // We could import from the current TU without error. But previously we
10016 // already had imported a Decl as `ToD` from another TU (with another
10017 // ASTImporter object) and with an error.
10018 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
10019 setImportDeclError(FromD, *Error);
10020 return make_error<ASTImportError>(*Error);
10021 }
10022 // Make sure that ImportImpl registered the imported decl.
10023 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
10024
10025 if (FromD->hasAttrs())
10026 for (const Attr *FromAttr : FromD->getAttrs()) {
10027 auto ToAttrOrErr = Import(FromAttr);
10028 if (ToAttrOrErr)
10029 ToD->addAttr(*ToAttrOrErr);
10030 else
10031 return ToAttrOrErr.takeError();
10032 }
10033
10034 // Notify subclasses.
10035 Imported(FromD, ToD);
10036
10037 updateFlags(FromD, ToD);
10038 SavedImportPaths.erase(FromD);
10039 return ToDOrErr;
10040}
10041
10044 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
10045}
10046
10048 if (!FromDC)
10049 return FromDC;
10050
10051 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
10052 if (!ToDCOrErr)
10053 return ToDCOrErr.takeError();
10054 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
10055
10056 // When we're using a record/enum/Objective-C class/protocol as a context, we
10057 // need it to have a definition.
10058 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
10059 auto *FromRecord = cast<RecordDecl>(FromDC);
10060 if (ToRecord->isCompleteDefinition())
10061 return ToDC;
10062
10063 // If FromRecord is not defined we need to force it to be.
10064 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
10065 // it will start the definition but we never finish it.
10066 // If there are base classes they won't be imported and we will
10067 // be missing anything that we inherit from those bases.
10068 if (FromRecord->getASTContext().getExternalSource() &&
10069 !FromRecord->isCompleteDefinition())
10070 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
10071
10072 if (FromRecord->isCompleteDefinition())
10073 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10074 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
10075 return std::move(Err);
10076 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
10077 auto *FromEnum = cast<EnumDecl>(FromDC);
10078 if (ToEnum->isCompleteDefinition()) {
10079 // Do nothing.
10080 } else if (FromEnum->isCompleteDefinition()) {
10081 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10082 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
10083 return std::move(Err);
10084 } else {
10085 CompleteDecl(ToEnum);
10086 }
10087 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
10088 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
10089 if (ToClass->getDefinition()) {
10090 // Do nothing.
10091 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
10092 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10093 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10094 return std::move(Err);
10095 } else {
10096 CompleteDecl(ToClass);
10097 }
10098 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10099 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10100 if (ToProto->getDefinition()) {
10101 // Do nothing.
10102 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10103 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10104 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10105 return std::move(Err);
10106 } else {
10107 CompleteDecl(ToProto);
10108 }
10109 }
10110
10111 return ToDC;
10112}
10113
10115 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10116 return cast_or_null<Expr>(*ToSOrErr);
10117 else
10118 return ToSOrErr.takeError();
10119}
10120
10122 if (!FromS)
10123 return nullptr;
10124
10125 // Check whether we've already imported this statement.
10126 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10127 if (Pos != ImportedStmts.end())
10128 return Pos->second;
10129
10130 // Import the statement.
10131 ASTNodeImporter Importer(*this);
10132 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10133 if (!ToSOrErr)
10134 return ToSOrErr;
10135
10136 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10137 auto *FromE = cast<Expr>(FromS);
10138 // Copy ExprBitfields, which may not be handled in Expr subclasses
10139 // constructors.
10140 ToE->setValueKind(FromE->getValueKind());
10141 ToE->setObjectKind(FromE->getObjectKind());
10142 ToE->setDependence(FromE->getDependence());
10143 }
10144
10145 // Record the imported statement object.
10146 ImportedStmts[FromS] = *ToSOrErr;
10147 return ToSOrErr;
10148}
10149
10151 switch (FromNNS.getKind()) {
10154 return FromNNS;
10156 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10157 auto NSOrErr = Import(Namespace);
10158 if (!NSOrErr)
10159 return NSOrErr.takeError();
10160 auto PrefixOrErr = Import(Prefix);
10161 if (!PrefixOrErr)
10162 return PrefixOrErr.takeError();
10163 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10164 *PrefixOrErr);
10165 }
10167 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10168 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10169 else
10170 return RDOrErr.takeError();
10172 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10173 return NestedNameSpecifier(*TyOrErr);
10174 } else {
10175 return TyOrErr.takeError();
10176 }
10177 }
10178 llvm_unreachable("Invalid nested name specifier kind");
10179}
10180
10183 // Copied from NestedNameSpecifier mostly.
10185 NestedNameSpecifierLoc NNS = FromNNS;
10186
10187 // Push each of the nested-name-specifiers's onto a stack for
10188 // serialization in reverse order.
10189 while (NNS) {
10190 NestedNames.push_back(NNS);
10191 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10192 }
10193
10195
10196 while (!NestedNames.empty()) {
10197 NNS = NestedNames.pop_back_val();
10198 NestedNameSpecifier Spec = std::nullopt;
10199 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10200 return std::move(Err);
10201
10202 NestedNameSpecifier::Kind Kind = Spec.getKind();
10203
10204 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10206 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10207 return std::move(Err);
10208
10210 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10211 return std::move(Err);
10212 }
10213
10214 switch (Kind) {
10216 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10217 ToLocalBeginLoc, ToLocalEndLoc);
10218 break;
10219
10221 SourceLocation ToTLoc;
10222 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10223 return std::move(Err);
10225 QualType(Spec.getAsType(), 0), ToTLoc);
10226 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10227 break;
10228 }
10229
10231 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10232 break;
10233
10235 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10236 if (!ToSourceRangeOrErr)
10237 return ToSourceRangeOrErr.takeError();
10238
10239 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10240 ToSourceRangeOrErr->getBegin(),
10241 ToSourceRangeOrErr->getEnd());
10242 break;
10243 }
10245 llvm_unreachable("unexpected null nested name specifier");
10246 }
10247 }
10248
10249 return Builder.getWithLocInContext(getToContext());
10250}
10251
10253 switch (From.getKind()) {
10255 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10256 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10257 else
10258 return ToTemplateOrErr.takeError();
10259
10262 UnresolvedSet<2> ToTemplates;
10263 for (auto *I : *FromStorage) {
10264 if (auto ToOrErr = Import(I))
10265 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10266 else
10267 return ToOrErr.takeError();
10268 }
10269 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10270 ToTemplates.end());
10271 }
10272
10275 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10276 if (!DeclNameOrErr)
10277 return DeclNameOrErr.takeError();
10278 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10279 }
10280
10283 auto QualifierOrErr = Import(QTN->getQualifier());
10284 if (!QualifierOrErr)
10285 return QualifierOrErr.takeError();
10286 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10287 if (!TNOrErr)
10288 return TNOrErr.takeError();
10289 return ToContext.getQualifiedTemplateName(
10290 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10291 }
10292
10295 auto QualifierOrErr = Import(DTN->getQualifier());
10296 if (!QualifierOrErr)
10297 return QualifierOrErr.takeError();
10298 return ToContext.getDependentTemplateName(
10299 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10300 }
10301
10305 auto ReplacementOrErr = Import(Subst->getReplacement());
10306 if (!ReplacementOrErr)
10307 return ReplacementOrErr.takeError();
10308
10309 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10310 if (!AssociatedDeclOrErr)
10311 return AssociatedDeclOrErr.takeError();
10312
10313 return ToContext.getSubstTemplateTemplateParm(
10314 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10315 Subst->getPackIndex(), Subst->getFinal());
10316 }
10317
10321 ASTNodeImporter Importer(*this);
10322 auto ArgPackOrErr =
10323 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10324 if (!ArgPackOrErr)
10325 return ArgPackOrErr.takeError();
10326
10327 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10328 if (!AssociatedDeclOrErr)
10329 return AssociatedDeclOrErr.takeError();
10330
10331 return ToContext.getSubstTemplateTemplateParmPack(
10332 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10333 SubstPack->getFinal());
10334 }
10336 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10337 if (!UsingOrError)
10338 return UsingOrError.takeError();
10339 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10340 }
10342 llvm_unreachable("Unexpected DeducedTemplate");
10343 }
10344
10345 llvm_unreachable("Invalid template name kind");
10346}
10347
10349 if (FromLoc.isInvalid())
10350 return SourceLocation{};
10351
10352 SourceManager &FromSM = FromContext.getSourceManager();
10353 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10354
10355 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10356 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10357 if (!ToFileIDOrErr)
10358 return ToFileIDOrErr.takeError();
10359 SourceManager &ToSM = ToContext.getSourceManager();
10360 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10361}
10362
10364 SourceLocation ToBegin, ToEnd;
10365 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10366 return std::move(Err);
10367 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10368 return std::move(Err);
10369
10370 return SourceRange(ToBegin, ToEnd);
10371}
10372
10374 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10375 if (Pos != ImportedFileIDs.end())
10376 return Pos->second;
10377
10378 SourceManager &FromSM = FromContext.getSourceManager();
10379 SourceManager &ToSM = ToContext.getSourceManager();
10380 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10381
10382 // Map the FromID to the "to" source manager.
10383 FileID ToID;
10384 if (FromSLoc.isExpansion()) {
10385 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10386 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10387 if (!ToSpLoc)
10388 return ToSpLoc.takeError();
10389 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10390 if (!ToExLocS)
10391 return ToExLocS.takeError();
10392 unsigned ExLength = FromSM.getFileIDSize(FromID);
10393 SourceLocation MLoc;
10394 if (FromEx.isMacroArgExpansion()) {
10395 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10396 } else {
10397 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10398 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10399 FromEx.isExpansionTokenRange());
10400 else
10401 return ToExLocE.takeError();
10402 }
10403 ToID = ToSM.getFileID(MLoc);
10404 } else {
10405 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10406
10407 if (!IsBuiltin && !Cache->BufferOverridden) {
10408 // Include location of this file.
10409 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10410 if (!ToIncludeLoc)
10411 return ToIncludeLoc.takeError();
10412
10413 // Every FileID that is not the main FileID needs to have a valid include
10414 // location so that the include chain points to the main FileID. When
10415 // importing the main FileID (which has no include location), we need to
10416 // create a fake include location in the main file to keep this property
10417 // intact.
10418 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10419 if (FromID == FromSM.getMainFileID())
10420 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10421
10422 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10423 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10424 // the disk again
10425 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10426 // than mmap the files several times.
10427 auto Entry =
10428 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10429 // FIXME: The filename may be a virtual name that does probably not
10430 // point to a valid file and we get no Entry here. In this case try with
10431 // the memory buffer below.
10432 if (Entry)
10433 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10434 FromSLoc.getFile().getFileCharacteristic());
10435 }
10436 }
10437
10438 if (ToID.isInvalid() || IsBuiltin) {
10439 // FIXME: We want to re-use the existing MemoryBuffer!
10440 std::optional<llvm::MemoryBufferRef> FromBuf =
10441 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10442 FromSM.getFileManager(), SourceLocation{});
10443 if (!FromBuf)
10444 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10445
10446 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10447 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10448 FromBuf->getBufferIdentifier());
10449 ToID = ToSM.createFileID(std::move(ToBuf),
10450 FromSLoc.getFile().getFileCharacteristic());
10451 }
10452 }
10453
10454 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10455
10456 ImportedFileIDs[FromID] = ToID;
10457 return ToID;
10458}
10459
10461 ExpectedExpr ToExprOrErr = Import(From->getInit());
10462 if (!ToExprOrErr)
10463 return ToExprOrErr.takeError();
10464
10465 auto LParenLocOrErr = Import(From->getLParenLoc());
10466 if (!LParenLocOrErr)
10467 return LParenLocOrErr.takeError();
10468
10469 auto RParenLocOrErr = Import(From->getRParenLoc());
10470 if (!RParenLocOrErr)
10471 return RParenLocOrErr.takeError();
10472
10473 if (From->isBaseInitializer()) {
10474 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10475 if (!ToTInfoOrErr)
10476 return ToTInfoOrErr.takeError();
10477
10478 SourceLocation EllipsisLoc;
10479 if (From->isPackExpansion())
10480 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10481 return std::move(Err);
10482
10483 return new (ToContext) CXXCtorInitializer(
10484 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10485 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10486 } else if (From->isMemberInitializer()) {
10487 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10488 if (!ToFieldOrErr)
10489 return ToFieldOrErr.takeError();
10490
10491 auto MemberLocOrErr = Import(From->getMemberLocation());
10492 if (!MemberLocOrErr)
10493 return MemberLocOrErr.takeError();
10494
10495 return new (ToContext) CXXCtorInitializer(
10496 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10497 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10498 } else if (From->isIndirectMemberInitializer()) {
10499 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10500 if (!ToIFieldOrErr)
10501 return ToIFieldOrErr.takeError();
10502
10503 auto MemberLocOrErr = Import(From->getMemberLocation());
10504 if (!MemberLocOrErr)
10505 return MemberLocOrErr.takeError();
10506
10507 return new (ToContext) CXXCtorInitializer(
10508 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10509 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10510 } else if (From->isDelegatingInitializer()) {
10511 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10512 if (!ToTInfoOrErr)
10513 return ToTInfoOrErr.takeError();
10514
10515 return new (ToContext)
10516 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10517 *ToExprOrErr, *RParenLocOrErr);
10518 } else {
10519 // FIXME: assert?
10520 return make_error<ASTImportError>();
10521 }
10522}
10523
10526 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10527 if (Pos != ImportedCXXBaseSpecifiers.end())
10528 return Pos->second;
10529
10530 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10531 if (!ToSourceRange)
10532 return ToSourceRange.takeError();
10534 if (!ToTSI)
10535 return ToTSI.takeError();
10536 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10537 if (!ToEllipsisLoc)
10538 return ToEllipsisLoc.takeError();
10539 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10540 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10541 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10542 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10543 return Imported;
10544}
10545
10547 ASTNodeImporter Importer(*this);
10548 return Importer.ImportAPValue(FromValue);
10549}
10550
10552 ExpectedDecl ToOrErr = Import(From);
10553 if (!ToOrErr)
10554 return ToOrErr.takeError();
10555 Decl *To = *ToOrErr;
10556
10557 auto *FromDC = cast<DeclContext>(From);
10558 ASTNodeImporter Importer(*this);
10559
10560 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10561 if (!ToRecord->getDefinition()) {
10562 return Importer.ImportDefinition(
10563 cast<RecordDecl>(FromDC), ToRecord,
10565 }
10566 }
10567
10568 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10569 if (!ToEnum->getDefinition()) {
10570 return Importer.ImportDefinition(
10572 }
10573 }
10574
10575 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10576 if (!ToIFace->getDefinition()) {
10577 return Importer.ImportDefinition(
10578 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10580 }
10581 }
10582
10583 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10584 if (!ToProto->getDefinition()) {
10585 return Importer.ImportDefinition(
10586 cast<ObjCProtocolDecl>(FromDC), ToProto,
10588 }
10589 }
10590
10591 return Importer.ImportDeclContext(FromDC, true);
10592}
10593
10595 if (!FromName)
10596 return DeclarationName{};
10597
10598 switch (FromName.getNameKind()) {
10600 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10601
10605 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10606 return DeclarationName(*ToSelOrErr);
10607 else
10608 return ToSelOrErr.takeError();
10609
10611 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10612 return ToContext.DeclarationNames.getCXXConstructorName(
10613 ToContext.getCanonicalType(*ToTyOrErr));
10614 else
10615 return ToTyOrErr.takeError();
10616 }
10617
10619 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10620 return ToContext.DeclarationNames.getCXXDestructorName(
10621 ToContext.getCanonicalType(*ToTyOrErr));
10622 else
10623 return ToTyOrErr.takeError();
10624 }
10625
10627 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10628 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10629 cast<TemplateDecl>(*ToTemplateOrErr));
10630 else
10631 return ToTemplateOrErr.takeError();
10632 }
10633
10635 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10636 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10637 ToContext.getCanonicalType(*ToTyOrErr));
10638 else
10639 return ToTyOrErr.takeError();
10640 }
10641
10643 return ToContext.DeclarationNames.getCXXOperatorName(
10644 FromName.getCXXOverloadedOperator());
10645
10647 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10648 Import(FromName.getCXXLiteralIdentifier()));
10649
10651 // FIXME: STATICS!
10653 }
10654
10655 llvm_unreachable("Invalid DeclarationName Kind!");
10656}
10657
10659 if (!FromId)
10660 return nullptr;
10661
10662 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10663
10664 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10665 ToId->setBuiltinID(FromId->getBuiltinID());
10666
10667 return ToId;
10668}
10669
10672 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10673 return Import(FromII);
10674 return FromIO.getOperator();
10675}
10676
10678 if (FromSel.isNull())
10679 return Selector{};
10680
10682 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10683 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10684 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10685 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10686}
10687
10691 llvm::Error Err = llvm::Error::success();
10692 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10693 for (unsigned Idx = 0; Idx < Size; Idx++) {
10694 APValue Tmp = importChecked(Err, From[Idx]);
10695 To[Idx] = Tmp;
10696 }
10697 };
10698 switch (FromValue.getKind()) {
10699 case APValue::None:
10701 case APValue::Int:
10702 case APValue::Float:
10706 Result = FromValue;
10707 break;
10708 case APValue::Vector: {
10709 Result.MakeVector();
10711 Result.setVectorUninit(FromValue.getVectorLength());
10712 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10713 Elts.data(), FromValue.getVectorLength());
10714 break;
10715 }
10716 case APValue::Matrix:
10717 // Matrix values cannot currently arise in APValue import contexts.
10718 llvm_unreachable("Matrix APValue import not yet supported");
10719 case APValue::Array:
10720 Result.MakeArray(FromValue.getArrayInitializedElts(),
10721 FromValue.getArraySize());
10722 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10723 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10724 FromValue.getArrayInitializedElts());
10725 break;
10726 case APValue::Struct:
10727 Result.MakeStruct(FromValue.getStructNumBases(),
10728 FromValue.getStructNumFields(),
10729 FromValue.getStructNumVirtualBases());
10730 ImportLoop(
10731 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10732 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10733 FromValue.getStructNumBases() + FromValue.getStructNumFields() +
10734 FromValue.getStructNumVirtualBases());
10735 break;
10736 case APValue::Union: {
10737 Result.MakeUnion();
10738 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10739 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10740 if (Err)
10741 return std::move(Err);
10742 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10743 break;
10744 }
10746 Result.MakeAddrLabelDiff();
10747 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10748 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10749 if (Err)
10750 return std::move(Err);
10751 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10752 cast<AddrLabelExpr>(ImpRHS));
10753 break;
10754 }
10756 const Decl *ImpMemPtrDecl =
10757 importChecked(Err, FromValue.getMemberPointerDecl());
10758 if (Err)
10759 return std::move(Err);
10761 Result.setMemberPointerUninit(
10762 cast<const ValueDecl>(ImpMemPtrDecl),
10764 FromValue.getMemberPointerPath().size());
10765 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10766 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10767 Idx++) {
10768 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10769 if (Err)
10770 return std::move(Err);
10771 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10772 }
10773 break;
10774 }
10775 case APValue::LValue:
10777 QualType FromElemTy;
10778 if (FromValue.getLValueBase()) {
10779 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10780 "in C++20 dynamic allocation are transient so they shouldn't "
10781 "appear in the AST");
10782 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10783 if (const auto *E =
10784 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10785 FromElemTy = E->getType();
10786 const Expr *ImpExpr = importChecked(Err, E);
10787 if (Err)
10788 return std::move(Err);
10789 Base = APValue::LValueBase(ImpExpr,
10790 FromValue.getLValueBase().getCallIndex(),
10791 FromValue.getLValueBase().getVersion());
10792 } else {
10793 FromElemTy =
10794 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10795 const Decl *ImpDecl = importChecked(
10796 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10797 if (Err)
10798 return std::move(Err);
10800 FromValue.getLValueBase().getCallIndex(),
10801 FromValue.getLValueBase().getVersion());
10802 }
10803 } else {
10804 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10805 const Type *ImpTypeInfo = importChecked(
10806 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10807 QualType ImpType =
10808 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10809 if (Err)
10810 return std::move(Err);
10812 ImpType);
10813 }
10814 }
10815 CharUnits Offset = FromValue.getLValueOffset();
10816 unsigned PathLength = FromValue.getLValuePath().size();
10817 Result.MakeLValue();
10818 if (FromValue.hasLValuePath()) {
10819 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10820 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10821 FromValue.isNullPointer());
10823 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10824 if (FromElemTy->isRecordType()) {
10825 const Decl *FromDecl =
10826 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10827 const Decl *ImpDecl = importChecked(Err, FromDecl);
10828 if (Err)
10829 return std::move(Err);
10830 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10831 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10832 else
10833 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10835 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10836 } else {
10837 FromElemTy =
10838 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10839 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10840 FromPath[LoopIdx].getAsArrayIndex());
10841 }
10842 }
10843 } else
10844 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10845 FromValue.isNullPointer());
10846 }
10847 if (Err)
10848 return std::move(Err);
10849 return Result;
10850}
10851
10853 DeclContext *DC,
10854 unsigned IDNS,
10855 NamedDecl **Decls,
10856 unsigned NumDecls) {
10857 if (ODRHandling == ODRHandlingType::Conservative)
10858 // Report error at any name conflict.
10859 return make_error<ASTImportError>(ASTImportError::NameConflict);
10860 else
10861 // Allow to create the new Decl with the same name.
10862 return Name;
10863}
10864
10866 if (LastDiagFromFrom)
10867 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10868 FromContext.getDiagnostics());
10869 LastDiagFromFrom = false;
10870 return ToContext.getDiagnostics().Report(Loc, DiagID);
10871}
10872
10874 if (!LastDiagFromFrom)
10875 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10876 ToContext.getDiagnostics());
10877 LastDiagFromFrom = true;
10878 return FromContext.getDiagnostics().Report(Loc, DiagID);
10879}
10880
10882 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10883 if (!ID->getDefinition())
10884 ID->startDefinition();
10885 }
10886 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10887 if (!PD->getDefinition())
10888 PD->startDefinition();
10889 }
10890 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10891 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10892 TD->startDefinition();
10893 TD->setCompleteDefinition(true);
10894 }
10895 }
10896 else {
10897 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10898 }
10899}
10900
10902 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10903 assert((Inserted || Pos->second == To) &&
10904 "Try to import an already imported Decl");
10905 if (!Inserted)
10906 return Pos->second;
10907 // This mapping should be maintained only in this function. Therefore do not
10908 // check for additional consistency.
10909 ImportedFromDecls[To] = From;
10910 // In the case of TypedefNameDecl we create the Decl first and only then we
10911 // import and set its DeclContext. So, the DC is still not set when we reach
10912 // here from GetImportedOrCreateDecl.
10913 if (To->getDeclContext())
10914 AddToLookupTable(To);
10915 return To;
10916}
10917
10918std::optional<ASTImportError>
10920 auto Pos = ImportDeclErrors.find(FromD);
10921 if (Pos != ImportDeclErrors.end())
10922 return Pos->second;
10923 else
10924 return std::nullopt;
10925}
10926
10928 auto InsertRes = ImportDeclErrors.insert({From, Error});
10929 (void)InsertRes;
10930 // Either we set the error for the first time, or we already had set one and
10931 // now we want to set the same error.
10932 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10933}
10934
10936 bool Complain) {
10937 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10938 ImportedTypes.find(From.getTypePtr());
10939 if (Pos != ImportedTypes.end()) {
10940 if (ExpectedType ToFromOrErr = Import(From)) {
10941 if (ToContext.hasSameType(*ToFromOrErr, To))
10942 return true;
10943 } else {
10944 llvm::consumeError(ToFromOrErr.takeError());
10945 }
10946 }
10947
10949 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10950 getStructuralEquivalenceKind(*this), false, Complain);
10951 return Ctx.IsEquivalent(From, To);
10952}
Defines the clang::ASTContext interface.
#define V(N, I)
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static ExpectedStmt ImportLoopControlStmt(ASTNodeImporter &NodeImporter, ASTImporter &Importer, StmtClass *S)
static auto getTemplateDefinition(T *D) -> T *
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::FileManager interface and associated types.
TokenType getType() const
Returns the token's type, e.g.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Result
Implement __builtin_bit_cast and related operations.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the Objective-C statement AST node classes.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
llvm::APInt getValue() const
unsigned getVersion() const
Definition APValue.cpp:113
QualType getTypeInfoType() const
Definition APValue.cpp:117
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition APValue.cpp:55
unsigned getCallIndex() const
Definition APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition APValue.h:208
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition APValue.h:216
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
const LValueBase getLValueBase() const
Definition APValue.cpp:1018
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1038
const FieldDecl * getUnionField() const
Definition APValue.h:695
unsigned getStructNumFields() const
Definition APValue.h:661
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition APValue.h:205
ValueKind getKind() const
Definition APValue.h:482
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:1023
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1108
unsigned getArrayInitializedElts() const
Definition APValue.h:648
unsigned getStructNumBases() const
Definition APValue.h:657
unsigned getStructNumVirtualBases() const
Definition APValue.h:665
bool hasLValuePath() const
Definition APValue.cpp:1033
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1101
APValue & getUnionValue()
Definition APValue.h:699
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:715
CharUnits & getLValueOffset()
Definition APValue.cpp:1028
unsigned getVectorLength() const
Definition APValue.h:593
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1115
unsigned getArraySize() const
Definition APValue.h:652
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:129
bool isNullPointer() const
Definition APValue.cpp:1054
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:711
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
Definition ASTContext.h:981
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
std::string toString() const
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition ASTImporter.h:62
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
static UnsignedOrNone getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
friend class ASTNodeImporter
Definition ASTImporter.h:63
llvm::Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition ASTImporter.h:65
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedStmt VisitCXXExpansionSelectExpr(CXXExpansionSelectExpr *E)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedStmt VisitCXXExpansionStmtPattern(CXXExpansionStmtPattern *S)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
StringRef ImportASTStringRef(StringRef FromStr)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedDecl VisitRequiresExprBodyDecl(RequiresExprBodyDecl *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitRequiresExpr(RequiresExpr *E)
ExpectedDecl VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitPseudoObjectExpr(PseudoObjectExpr *E)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitConceptDecl(ConceptDecl *D)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
ExpectedDecl VisitCXXExpansionStmtDecl(CXXExpansionStmtDecl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
SmallVector< TemplateArgument, 8 > TemplateArgsTy
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedStmt VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedDecl VisitFileScopeAsmDecl(FileScopeAsmDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
Expected< concepts::Requirement * > ImportNestedRequirement(concepts::NestedRequirement *From)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedStmt VisitCXXExpansionStmtInstantiation(CXXExpansionStmtInstantiation *S)
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:4401
SourceLocation getQuestionLoc() const
Definition Expr.h:4400
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:4570
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4585
SourceLocation getLabelLoc() const
Definition Expr.h:4587
LabelDecl * getLabel() const
Definition Expr.h:4593
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6047
Represents a loop initializing the elements of an array.
Definition Expr.h:5994
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:6009
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:6014
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2741
SourceLocation getRBracketLoc() const
Definition Expr.h:2789
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2770
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:3010
uint64_t getValue() const
Definition ExprCXX.h:3058
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3048
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3050
Expr * getDimensionExpression() const
Definition ExprCXX.h:3060
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3056
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3047
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3836
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:6954
Expr ** getSubExprs()
Definition Expr.h:7029
SourceLocation getRParenLoc() const
Definition Expr.h:7083
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5283
AtomicOp getOp() const
Definition Expr.h:7017
SourceLocation getBuiltinLoc() const
Definition Expr.h:7082
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:3521
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3516
shadow_range shadows() const
Definition DeclCXX.h:3587
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4473
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4527
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4511
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4515
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4520
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4508
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4058
Expr * getLHS() const
Definition Expr.h:4108
SourceLocation getOperatorLoc() const
Definition Expr.h:4100
Expr * getRHS() const
Definition Expr.h:4110
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:5109
Opcode getOpcode() const
Definition Expr.h:4103
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4278
A binding in a decomposition declaration.
Definition DeclCXX.h:4210
void setDecomposedDecl(DecompositionDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4254
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4236
DecompositionDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4243
void setBinding(QualType DeclaredType, Expr *Binding)
Set the binding for this BindingDecl, along with its declared type (which should be a possibly-cv-qua...
Definition DeclCXX.h:4248
BreakStmt - This represents a break.
Definition Stmt.h:3147
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5527
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
BuiltinTemplateKind getBuiltinTemplateKind() const
This class is used for builtin types like 'int'.
Definition TypeBase.h:3241
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition Expr.cpp:2113
Represents a base class of a C++ class.
Definition DeclCXX.h:146
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition DeclCXX.h:242
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition DeclCXX.h:221
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition DeclCXX.h:203
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition DeclCXX.h:254
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the 'class' keyword (vs.
Definition DeclCXX.h:207
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition DeclCXX.h:193
Represents binding an expression to a temporary.
Definition ExprCXX.h:1497
CXXTemporary * getTemporary()
Definition ExprCXX.h:1515
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition ExprCXX.cpp:1151
const Expr * getSubExpr() const
Definition ExprCXX.h:1519
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:727
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition ExprCXX.h:739
bool getValue() const
Definition ExprCXX.h:744
SourceLocation getLocation() const
Definition ExprCXX.h:750
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:925
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1733
void setIsImmediateEscalating(bool Set)
Definition ExprCXX.h:1714
bool isElidable() const
Whether this construction is elidable.
Definition ExprCXX.h:1621
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition ExprCXX.h:1626
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:1213
arg_range arguments()
Definition ExprCXX.h:1676
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1645
bool isImmediateEscalating() const
Definition ExprCXX.h:1710
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition ExprCXX.h:1654
SourceLocation getLocation() const
Definition ExprCXX.h:1617
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1615
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1634
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1692
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1663
Represents a C++ constructor within a class.
Definition DeclCXX.h:2637
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2972
Represents a C++ base or member initializer.
Definition DeclCXX.h:2402
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2542
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2502
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2604
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2601
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2512
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2600
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2507
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2536
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2480
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2474
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2486
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2562
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2556
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2528
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1996
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2079
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition ExprCXX.h:1348
const ParmVarDecl * getParam() const
Definition ExprCXX.h:1316
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1344
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1072
bool hasRewrittenInit() const
Definition ExprCXX.h:1319
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1381
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:1126
const DeclContext * getUsedContext() const
Definition ExprCXX.h:1438
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition ExprCXX.h:1426
bool hasRewrittenInit() const
Definition ExprCXX.h:1410
FieldDecl * getField()
Get the field whose initializer will be used.
Definition ExprCXX.h:1415
SourceLocation getBeginLoc() const
Definition ExprCXX.h:1445
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2630
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2669
bool isArrayForm() const
Definition ExprCXX.h:2656
SourceLocation getBeginLoc() const
Definition ExprCXX.h:2680
bool isGlobalDelete() const
Definition ExprCXX.h:2655
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2665
bool isArrayFormAsWritten() const
Definition ExprCXX.h:2657
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3921
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4020
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4023
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:1583
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:4075
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4067
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4054
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4094
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4063
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4083
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4059
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:4047
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4011
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:4034
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:4003
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4122
Represents a C++ destructor within a class.
Definition DeclCXX.h:2902
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition DeclCXX.cpp:3172
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:839
Helper that selects an expression from an InitListExpr depending on the current expansion index.
Definition ExprCXX.h:5609
InitListExpr * getRangeExpr()
Definition ExprCXX.h:5619
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:5083
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5105
Expr * getRHS() const
Definition ExprCXX.h:5109
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5125
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5127
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5130
Expr * getLHS() const
Definition ExprCXX.h:5108
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5126
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5128
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:951
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition ExprCXX.h:1796
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1792
SourceLocation getLocation() const LLVM_READONLY
Definition ExprCXX.h:1808
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition ExprCXX.h:1806
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:183
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:725
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition DeclCXX.cpp:2805
overridden_method_range overridden_methods() const
Definition DeclCXX.cpp:2828
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition DeclCXX.h:2258
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:379
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:410
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:417
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:413
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2359
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:299
SourceRange getDirectInitRange() const
Definition ExprCXX.h:2613
llvm::iterator_range< arg_iterator > placement_arguments()
Definition ExprCXX.h:2576
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:2473
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition ExprCXX.h:2531
ImplicitAllocationParameters implicitAllocationParameters() const
Provides the full set of information about expected implicit parameters in this call.
Definition ExprCXX.h:2566
FunctionDecl * getOperatorDelete() const
Definition ExprCXX.h:2465
unsigned getNumPlacementArgs() const
Definition ExprCXX.h:2498
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition ExprCXX.h:2442
SourceRange getSourceRange() const
Definition ExprCXX.h:2614
SourceRange getTypeIdParens() const
Definition ExprCXX.h:2520
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition ExprCXX.h:2560
FunctionDecl * getOperatorNew() const
Definition ExprCXX.h:2463
bool isGlobalNew() const
Definition ExprCXX.h:2525
Expr * getInitializer()
The initializer of this new-expression.
Definition ExprCXX.h:2537
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4360
bool getValue() const
Definition ExprCXX.h:4383
SourceLocation getEndLoc() const
Definition ExprCXX.h:4380
Expr * getOperand() const
Definition ExprCXX.h:4377
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4379
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:772
SourceLocation getLocation() const
Definition ExprCXX.h:786
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:655
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5192
static CXXParenListInitExpr * Create(ASTContext &C, ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Definition ExprCXX.cpp:2040
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5248
SourceLocation getInitLoc() const LLVM_READONLY
Definition ExprCXX.h:5250
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5232
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5246
MutableArrayRef< Expr * > getUserSpecifiedInitExprs()
Definition ExprCXX.h:5238
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2749
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition ExprCXX.h:2843
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition ExprCXX.h:2813
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2827
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition ExprCXX.h:2834
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition ExprCXX.h:2802
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition ExprCXX.h:2858
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition ExprCXX.h:2831
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition ExprCXX.h:2816
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:2850
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition DeclCXX.h:539
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition DeclCXX.cpp:2032
method_range methods() const
Definition DeclCXX.h:650
CXXRecordDecl * getDefinition() const
Definition DeclCXX.h:548
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition DeclCXX.cpp:142
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition DeclCXX.cpp:2062
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition DeclCXX.cpp:2045
void setLambdaContextDecl(Decl *ContextDecl)
Set the context declaration for a lambda class.
Definition DeclCXX.cpp:1842
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition DeclCXX.cpp:2058
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers for a lambda class.
Definition DeclCXX.cpp:1847
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition DeclCXX.cpp:2039
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition DeclCXX.cpp:2073
CXXRecordDecl * getPreviousDecl()
Definition DeclCXX.h:530
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition ExprCXX.cpp:903
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:290
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:308
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition ExprCXX.h:326
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2200
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:2219
SourceLocation getRParenLoc() const
Definition ExprCXX.h:2223
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:813
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:804
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1903
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:1179
TypeSourceInfo * getTypeSourceInfo() const
Definition ExprCXX.h:1932
Represents a C++ temporary.
Definition ExprCXX.h:1463
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition ExprCXX.cpp:1146
Represents the this expression in C++.
Definition ExprCXX.h:1158
bool isImplicit() const
Definition ExprCXX.h:1181
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition ExprCXX.cpp:1618
SourceLocation getLocation() const
Definition ExprCXX.h:1175
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1212
const Expr * getSubExpr() const
Definition ExprCXX.h:1232
SourceLocation getThrowLoc() const
Definition ExprCXX.h:1235
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition ExprCXX.h:1242
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:852
bool isTypeOperand() const
Definition ExprCXX.h:888
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition ExprCXX.h:895
Expr * getExprOperand() const
Definition ExprCXX.h:899
SourceRange getSourceRange() const LLVM_READONLY
Definition ExprCXX.h:906
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3795
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3839
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3850
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition ExprCXX.cpp:1521
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3833
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3844
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3853
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2963
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1523
ADLCallKind getADLCallKind() const
Definition Expr.h:3114
Expr * getCallee()
Definition Expr.h:3110
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3262
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3154
arg_range arguments()
Definition Expr.h:3215
SourceLocation getRParenLoc() const
Definition Expr.h:3294
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:3696
path_iterator path_begin()
Definition Expr.h:3766
CastKind getCastKind() const
Definition Expr.h:3740
path_iterator path_end()
Definition Expr.h:3767
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3816
Expr * getSubExpr()
Definition Expr.h:3746
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
SourceLocation getLocation() const
Definition Expr.h:1641
unsigned getValue() const
Definition Expr.h:1649
CharacterLiteralKind getKind() const
Definition Expr.h:1642
How to handle import errors that occur when import of a child declaration of a DeclContext fails.
bool ignoreChildErrorOnParent(Decl *FromChildD) const
Determine if import failure of a child does not cause import failure of its parent.
ChildErrorHandlingStrategy(const Decl *FromD)
void handleChildImportResult(Error &ResultErr, Error &&ChildErr)
Process the import result of a child (of the current declaration).
ChildErrorHandlingStrategy(const DeclContext *FromDC)
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4868
SourceLocation getBuiltinLoc() const
Definition Expr.h:4915
Expr * getLHS() const
Definition Expr.h:4910
bool isConditionDependent() const
Definition Expr.h:4898
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4891
Expr * getRHS() const
Definition Expr.h:4912
SourceLocation getRParenLoc() const
Definition Expr.h:4918
Expr * getCond() const
Definition Expr.h:4908
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4320
QualType getComputationLHSType() const
Definition Expr.h:4354
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:5131
QualType getComputationResultType() const
Definition Expr.h:4357
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3625
SourceLocation getLParenLoc() const
Definition Expr.h:3660
bool isFileScope() const
Definition Expr.h:3657
const Expr * getInitializer() const
Definition Expr.h:3653
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3663
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:4411
Expr * getLHS() const
Definition Expr.h:4445
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4434
Expr * getRHS() const
Definition Expr.h:4446
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1102
APValue getAPValueResult() const
Definition Expr.cpp:419
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:356
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:47
llvm::SmallVector< UnsatisfiedConstraintRecord, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition ASTConcept.h:67
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition DeclCXX.h:3702
ContinueStmt - This represents a continue.
Definition Stmt.h:3131
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4739
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4807
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4843
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:5696
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4840
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4832
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4829
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
AccessSpecifier getAccess() const
The results of name lookup within a DeclContext.
Definition DeclBase.h:1399
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h:2607
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
bool isNamespace() const
Definition DeclBase.h:2219
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isRecord() const
Definition DeclBase.h:2206
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
void removeDecl(Decl *D)
Removes a declaration from this context.
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition DeclBase.h:2718
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition DeclBase.h:2403
bool isFunctionOrMethod() const
Definition DeclBase.h:2178
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition DeclGroup.h:64
iterator begin()
Definition DeclGroup.h:95
bool isNull() const
Definition DeclGroup.h:75
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1290
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition Expr.h:1401
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition Expr.h:1445
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition Expr.h:1494
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition Expr.h:1417
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition Expr.cpp:494
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:1425
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition Expr.h:1383
ValueDecl * getDecl()
Definition Expr.h:1358
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:1471
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:1488
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition Expr.h:1477
SourceLocation getLocation() const
Definition Expr.h:1366
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:1433
bool isImmediateEscalating() const
Definition Expr.h:1498
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1643
SourceLocation getEndLoc() const
Definition Stmt.h:1666
const DeclGroupRef getDeclGroup() const
Definition Stmt.h:1661
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1669
A simple visitor class that helps create declaration visitors.
Definition DeclVisitor.h:68
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:443
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition DeclBase.cpp:285
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition DeclBase.h:1243
bool hasAttrs() const
Definition DeclBase.h:526
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
void addAttr(Attr *A)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:601
@ FOK_None
Not a friend object.
Definition DeclBase.h:1234
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition DeclBase.h:1197
void setAccess(AccessSpecifier AS)
Definition DeclBase.h:510
SourceLocation getLocation() const
Definition DeclBase.h:447
const char * getDeclKindName() const
Definition DeclBase.cpp:169
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition DeclBase.h:125
void setImplicit(bool I=true)
Definition DeclBase.h:602
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition DeclBase.h:616
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition DeclBase.cpp:579
DeclContext * getDeclContext()
Definition DeclBase.h:456
AccessSpecifier getAccess() const
Definition DeclBase.h:515
bool isInAnonymousNamespace() const
Definition DeclBase.cpp:443
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:439
TranslationUnitDecl * getTranslationUnitDecl()
Definition DeclBase.cpp:535
AttrVec & getAttrs()
Definition DeclBase.h:532
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition DeclBase.cpp:385
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:935
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:389
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:995
Kind getKind() const
Definition DeclBase.h:450
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:831
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:814
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2018
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:845
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
A decomposition declaration.
Definition DeclCXX.h:4274
SourceLocation getDefaultLoc() const
Definition Stmt.h:2097
Stmt * getSubStmt()
Definition Stmt.h:2093
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3561
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition ExprCXX.cpp:575
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3635
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3609
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3627
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3669
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3645
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3619
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3600
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3597
A template-id naming a variable template or a concept through a template template parameter.
Definition ExprCXX.h:3479
static DependentTemplateIdExpr * Create(const ASTContext &Context, const DeclarationNameInfo &NameInfo, TemplateName Name, const TemplateArgumentListInfo &TemplateArgs)
Definition ExprCXX.cpp:422
const DeclarationNameInfo & getNameInfo() const
Definition ExprCXX.h:3503
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3522
SourceLocation getRAngleLoc() const
Definition ExprCXX.h:3518
DeclarationName getName() const
Definition ExprCXX.h:3504
TemplateName getTemplateName() const
Definition ExprCXX.h:3507
SourceLocation getNameLoc() const
Definition ExprCXX.h:3505
SourceLocation getLAngleLoc() const
Definition ExprCXX.h:3517
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:5620
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5747
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5701
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5737
SourceLocation getFieldLoc() const
Definition Expr.h:5728
SourceLocation getRBracketLoc() const
Definition Expr.h:5776
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4800
SourceLocation getEllipsisLoc() const
Definition Expr.h:5770
SourceLocation getDotLoc() const
Definition Expr.h:5723
SourceLocation getLBracketLoc() const
Definition Expr.h:5764
Represents a C99 designated initializer expression.
Definition Expr.h:5577
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5859
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5841
MutableArrayRef< Designator > designators()
Definition Expr.h:5810
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5845
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5807
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5832
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5857
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4841
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:65
Represents an empty-declaration.
Definition Decl.h:5313
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3557
llvm::APSInt getInitVal() const
Definition Decl.h:3577
const Expr * getInitExpr() const
Definition Decl.h:3575
Represents an enum.
Definition Decl.h:4145
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4417
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4363
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4355
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4366
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4327
EnumDecl * getMostRecentDecl()
Definition Decl.h:4250
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4372
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5158
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4318
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5218
EnumDecl * getDefinition() const
Definition Decl.h:4257
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4344
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4310
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3948
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3970
Store information needed for an explicit specifier.
Definition DeclCXX.h:1944
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1952
const Expr * getExpr() const
Definition DeclCXX.h:1953
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3712
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3747
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3736
unsigned getNumObjects() const
Definition ExprCXX.h:3740
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3718
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition ExprCXX.cpp:1497
This represents one expression.
Definition Expr.h:113
void setType(QualType t)
Definition Expr.h:146
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:178
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition Expr.h:448
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:195
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition Expr.h:242
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:455
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition Expr.h:224
QualType getType() const
Definition Expr.h:145
ExprDependence getDependence() const
Definition Expr.h:165
An expression trait intrinsic.
Definition ExprCXX.h:3083
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3115
Expr * getQueriedExpression() const
Definition ExprCXX.h:3122
ExpressionTrait getTrait() const
Definition ExprCXX.h:3118
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3116
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
Definition Decl.h:3294
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3394
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4789
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3474
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3468
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4799
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3410
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3518
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4899
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:4747
const Expr * getAsmStringExpr() const
Definition Decl.h:4754
SourceLocation getRParenLoc() const
Definition Decl.h:4748
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1601
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1595
SourceLocation getLocation() const
Definition Expr.h:1727
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp:1082
llvm::APFloat getValue() const
Definition Expr.h:1686
bool isExact() const
Definition Expr.h:1719
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2900
Stmt * getInit()
Definition Stmt.h:2915
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition Stmt.cpp:1120
SourceLocation getRParenLoc() const
Definition Stmt.h:2960
Stmt * getBody()
Definition Stmt.h:2944
Expr * getInc()
Definition Stmt.h:2943
SourceLocation getForLoc() const
Definition Stmt.h:2956
Expr * getCond()
Definition Stmt.h:2942
SourceLocation getLParenLoc() const
Definition Stmt.h:2958
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:46
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition DeclFriend.h:50
SourceLocation getFriendLoc() const
Definition DeclFriend.h:109
SourceLocation getEllipsisLoc() const
Retrieves the location of the '...', if present.
Definition DeclFriend.h:107
virtual NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:102
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:96
Declaration of a friend template.
TemplateName getFriendTemplateName() const
FriendTemplateEntityKind getFriendKind() const
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
const Expr * getSubExpr() const
Definition Expr.h:1082
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, FPOptionsOverride FPFeatures, StringLiteral *DeletedMessage=nullptr)
Definition Decl.cpp:3128
Represents a function declaration or definition.
Definition Decl.h:2058
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3268
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2602
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3183
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4242
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4237
void setIsPureVirtual(bool P=true)
Definition Decl.cpp:3342
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition Decl.cpp:3149
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition Decl.h:2831
bool isDestroyingOperatorDelete() const
Determine whether this is a destroying operator delete.
Definition Decl.cpp:3595
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition Decl.h:3039
SourceLocation getDefaultLoc() const
Definition Decl.h:2524
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2904
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2515
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2503
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2574
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4216
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4367
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2528
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2439
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4433
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2074
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2077
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:3018
void setTrivial(bool IT)
Definition Decl.h:2504
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2837
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4188
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4255
bool isDeletedAsWritten() const
Definition Decl.h:2670
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition Decl.cpp:4422
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2479
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition Decl.h:2475
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp:3599
bool isTypeAwareOperatorNewOrDelete() const
Determine whether this is a type aware operator new or delete.
Definition Decl.cpp:3603
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition Decl.cpp:3607
void setRangeEnd(SourceLocation E)
Definition Decl.h:2331
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2511
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4261
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4461
void setDefaulted(bool D=true)
Definition Decl.h:2512
void setBody(Stmt *B)
Definition Decl.cpp:3280
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2470
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3158
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2520
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4209
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2324
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition Decl.cpp:3188
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition Decl.h:3029
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5421
QualType desugar() const
Definition TypeBase.h:6002
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5710
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5875
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5861
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary pattern.
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition TypeBase.h:4973
QualType getReturnType() const
Definition TypeBase.h:4957
This represents a GCC inline-assembly statement extension.
Definition Stmt.h: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:4943
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4960
Represents a C11 generic selection.
Definition Expr.h:6208
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6485
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6505
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6466
SourceLocation getGenericLoc() const
Definition Expr.h:6563
SourceLocation getRParenLoc() const
Definition Expr.h:6567
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6455
SourceLocation getDefaultLoc() const
Definition Expr.h:6566
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:4730
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6462
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6473
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6510
GotoStmt - This represents a direct goto.
Definition Stmt.h:2981
SourceLocation getLabelLoc() const
Definition Stmt.h:2999
SourceLocation getGotoLoc() const
Definition Stmt.h:2997
LabelDecl * getLabel() const
Definition Stmt.h:2994
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setBuiltinID(unsigned ID)
StringRef getName() const
Return the actual identifier string.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2271
Stmt * getThen()
Definition Stmt.h:2360
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition Stmt.cpp:1044
SourceLocation getIfLoc() const
Definition Stmt.h:2437
IfStatementKind getStatementKind() const
Definition Stmt.h:2472
SourceLocation getElseLoc() const
Definition Stmt.h:2440
Stmt * getInit()
Definition Stmt.h:2421
SourceLocation getLParenLoc() const
Definition Stmt.h:2489
Expr * getCond()
Definition Stmt.h:2348
Stmt * getElse()
Definition Stmt.h:2369
SourceLocation getRParenLoc() const
Definition Stmt.h:2491
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1751
const Expr * getSubExpr() const
Definition Expr.h:1763
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3873
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2081
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1809
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6083
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5187
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3601
unsigned getChainingSize() const
Definition Decl.h:3626
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3622
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h: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:2608
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2621
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2620
Describes an C or C++ initializer list.
Definition Expr.h:5328
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5441
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5502
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5455
unsigned getNumInits() const
Definition Expr.h:5361
SourceLocation getLBraceLoc() const
Definition Expr.h:5486
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2449
InitListExpr * getSyntacticForm() const
Definition Expr.h:5498
bool hadArrayRangeDesignator() const
Definition Expr.h:5509
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5431
bool isExplicit() const
Definition Expr.h:5471
SourceLocation getRBraceLoc() const
Definition Expr.h:5488
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5461
ArrayRef< Expr * > inits() const
Definition Expr.h:5381
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5512
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:981
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1556
Represents the declaration of a label.
Definition Decl.h:524
bool isGnuLocal() const
Definition Decl.h:551
LabelStmt * getStmt() const
Definition Decl.h:548
void setStmt(LabelStmt *T)
Definition Decl.h:549
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h: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:1297
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:1972
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:1345
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2190
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition ExprCXX.h:2175
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition ExprCXX.h:2123
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2053
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition ExprCXX.cpp:1437
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition ExprCXX.h:2178
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition ExprCXX.h:2030
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition ExprCXX.h:2087
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition ExprCXX.h:2025
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1433
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition DeclCXX.h:3333
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3379
Represents a linkage specification.
Definition DeclCXX.h:3040
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3082
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3063
SourceLocation getExternLoc() const
Definition DeclCXX.h:3079
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3080
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3074
Represents the results of name lookup.
Definition Lookup.h:147
iterator end() const
Definition Lookup.h:359
iterator begin() const
Definition Lookup.h:358
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4971
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4988
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:5040
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:5011
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3384
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3556
SourceLocation getOperatorLoc() const
Definition Expr.h:3566
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3501
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3486
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3467
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3528
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3608
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition Expr.cpp:1758
Expr * getBase() const
Definition Expr.h:3461
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3517
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3509
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3561
bool isArrow() const
Definition Expr.h:3568
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3471
Provides information a specialization of a member of a class template, which may be a member function...
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
This represents a decl that may have a name.
Definition Decl.h:274
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1183
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents a C++ namespace alias.
Definition DeclCXX.h:3226
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3287
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3309
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3312
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3315
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3296
Represent a C++ namespace.
Definition Decl.h:592
SourceLocation getRBraceLoc() const
Definition Decl.h:692
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:691
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:675
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:657
void setRBraceLoc(SourceLocation L)
Definition Decl.h:694
Class that aids in the construction of nested-name-specifiers along with source-location information ...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h: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:3672
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition DeclObjC.h:647
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition DeclObjC.h:626
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition DeclObjC.h:636
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:665
SourceLocation getRAngleLoc() const
Definition DeclObjC.h:714
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
SourceLocation getLAngleLoc() const
Definition DeclObjC.h:713
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2547
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2606
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2580
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2594
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1661
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2587
unsigned getNumExpressions() const
Definition Expr.h:2618
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2584
unsigned getNumComponents() const
Definition Expr.h:2602
Helper class for OffsetOfExpr.
Definition Expr.h:2441
const IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1696
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2499
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2505
@ Array
An index into an array.
Definition Expr.h:2446
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2450
@ Field
A field.
Definition Expr.h:2448
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2453
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2527
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2495
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2528
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2515
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1198
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1248
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1220
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3294
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3276
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition ExprCXX.h:3249
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3255
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3268
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3264
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3241
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition ExprCXX.h:3324
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3252
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3284
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3319
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:4414
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4443
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4454
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4450
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2202
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2227
const Expr * getSubExpr() const
Definition Expr.h:2219
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2231
ArrayRef< Expr * > exprs() const
Definition Expr.h:6153
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:4981
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6136
SourceLocation getLParenLoc() const
Definition Expr.h:6155
SourceLocation getRParenLoc() const
Definition Expr.h:6156
Represents a parameter to a function.
Definition Decl.h:1819
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1900
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1879
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1887
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3010
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1915
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1960
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1948
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3035
bool isObjCMethodParameter() const
Definition Decl.h:1862
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1883
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1852
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1952
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1847
bool hasInheritedDefaultArg() const
Definition Decl.h:1964
void setKNRPromoted(bool promoted)
Definition Decl.h:1903
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1911
Expr * getDefaultArg()
Definition Decl.cpp:2998
Expr * getUninstantiatedDefaultArg()
Definition Decl.cpp:3040
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition Decl.cpp:3046
unsigned getFunctionScopeDepth() const
Definition Decl.h:1869
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1968
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2025
SourceLocation getBeginLoc() const
Definition Expr.h:2090
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:639
bool isTransparent() const
Definition Expr.h:2064
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2060
StringLiteral * getFunctionName()
Definition Expr.h:2069
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2698
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6830
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6872
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5203
ArrayRef< Expr * > semantics()
Definition Expr.h:6902
unsigned getNumSemanticExprs() const
Definition Expr.h:6887
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6867
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:8502
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8534
Represents a template name as written in source code.
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Represents a struct/union/class.
Definition Decl.h:4459
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5310
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4515
field_range fields() const
Definition Decl.h:4662
RecordDecl * getMostRecentDecl()
Definition Decl.h:4485
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5355
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4643
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4511
Provides common interface for the Decls that can be redeclared.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition Decl.h:5464
Represents the body of a requires-expression.
Definition DeclCXX.h:2114
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
SourceLocation getRBraceLoc() const
SourceLocation getRequiresKWLoc() const
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
RequiresExprBodyDecl * getBody() const
ArrayRef< concepts::Requirement * > getRequirements() const
ArrayRef< ParmVarDecl * > getLocalParameters() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h: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:4663
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4699
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4696
SourceLocation getRParenLoc() const
Definition Expr.h:4683
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4686
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4492
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4554
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4577
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1741
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4582
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4551
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4557
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4560
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4566
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5046
SourceLocation getBeginLoc() const
Definition Expr.h:5091
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5087
SourceLocation getEndLoc() const
Definition Expr.h:5092
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5066
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4161
bool isFailed() const
Definition DeclCXX.h:4190
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4192
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4615
CompoundStmt * getSubStmt()
Definition Expr.h:4632
unsigned getTemplateDepth() const
Definition Expr.h:4644
SourceLocation getRParenLoc() const
Definition Expr.h:4641
SourceLocation getLParenLoc() const
Definition Expr.h:4639
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:85
StmtClass getStmtClass() const
Definition Stmt.h:1505
const char * getStmtClassName() const
Definition Stmt.cpp:86
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1819
bool isPascal() const
Definition Expr.h:1942
tokloc_iterator tokloc_begin() const
Definition Expr.h:1985
tokloc_iterator tokloc_end() const
Definition Expr.h:1989
StringLiteralKind getKind() const
Definition Expr.h:1932
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
Definition Expr.cpp:1194
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1895
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition Expr.h:1960
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4715
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4760
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4768
QualType getParameterType() const
Determine the substituted type of the template parameter.
Definition ExprCXX.h:4779
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4766
SourceLocation getNameLoc() const
Definition ExprCXX.h:4750
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4805
TemplateArgument getArgumentPack() const
Retrieve the template argument pack containing the substituted template arguments.
Definition ExprCXX.cpp:1817
SourceLocation getParameterPackLocation() const
Retrieve the location of the parameter pack name.
Definition ExprCXX.h:4853
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4839
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4843
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:3851
SourceRange getBraceRange() const
Definition Decl.h:3928
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3972
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4993
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3947
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3952
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4105
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:4088
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4970
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4965
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:5007
TagKind getTagKind() const
Definition Decl.h:4051
void setBraceRange(SourceRange R)
Definition Decl.h:3929
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3955
A convenient class for passing around template argument information.
SourceLocation getRAngleLoc() const
void addArgument(const TemplateArgumentLoc &Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
SourceLocation getLAngleLoc() const
A template argument list.
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
TemplateArgumentLocInfo getLocInfo() const
const TemplateArgument & getArgument() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
UnsignedOrNone getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isCanonicalExpr() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
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.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
A template parameter object.
const APValue & getValue() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
SourceLocation getRAngleLoc() const
SourceLocation getLAngleLoc() const
SourceLocation getTemplateLoc() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
TemplateNameKind templateParameterKind() const
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
unsigned getIndex() const
Retrieve the index of the template parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
The top declaration context.
Definition Decl.h:105
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3822
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3840
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition ASTConcept.h:227
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3681
Symbolic representation of typeid(T) for some type T.
Definition APValue.h:44
const Type * getType() const
Definition APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition TypeLoc.cpp:193
A container of type source information.
Definition TypeBase.h:8473
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:8484
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2900
bool getBoolValue() const
Definition ExprCXX.h:2961
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition ExprCXX.h:2981
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:1939
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:2986
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition ExprCXX.h:2972
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition ExprCXX.h:2949
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:2985
const APValue & getAPValue() const
Definition ExprCXX.h:2966
bool isStoredAsBoolean() const
Definition ExprCXX.h:2953
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:8838
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition TypeBase.h:9291
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition Type.cpp:2559
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:9338
bool isRecordType() const
Definition TypeBase.h:8866
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3801
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3696
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3746
QualType getUnderlyingType() const
Definition Decl.h:3751
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2645
SourceLocation getRParenLoc() const
Definition Expr.h:2721
SourceLocation getOperatorLoc() const
Definition Expr.h:2718
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2691
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2677
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2264
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2309
Expr * getSubExpr() const
Definition Expr.h:2305
Opcode getOpcode() const
Definition Expr.h:2300
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2401
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2404
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5145
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2318
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3372
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3446
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3441
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:463
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4177
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4269
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4272
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4263
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4250
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:1684
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:1677
void addDecl(NamedDecl *D)
A set of unresolved declarations.
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4062
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4092
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4096
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4089
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4113
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3965
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:3996
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4006
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:4013
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4023
Represents a C++ using-declaration.
Definition DeclCXX.h:3616
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3665
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3650
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3657
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3643
Represents C++ using-directive.
Definition DeclCXX.h:3121
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3192
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition DeclCXX.cpp:3357
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition DeclCXX.h:3188
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3196
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3199
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3166
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3817
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3841
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3853
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3837
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3898
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3927
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3931
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3424
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3488
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3487
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4977
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:5010
SourceLocation getBuiltinLoc() const
Definition Expr.h:5013
SourceLocation getRParenLoc() const
Definition Expr.h:5016
VarArgKind getVarargABI() const
Definition Expr.h:5001
const Expr * getSubExpr() const
Definition Expr.h:4997
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
void setType(QualType newType)
Definition Decl.h:724
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:932
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2782
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1593
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp:2907
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:2242
bool isInlineSpecified() const
Definition Decl.h:1578
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition Decl.cpp:2348
EvaluatedStmt * getEvaluatedStmt() const
Definition Decl.cpp:2553
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition Decl.cpp:2539
void setInlineSpecified()
Definition Decl.h:1582
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition Decl.cpp:2744
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1365
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1179
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1575
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1183
const Expr * getInit() const
Definition Decl.h:1391
void setConstexpr(bool IC)
Definition Decl.h:1596
void setInit(Expr *I)
Definition Decl.cpp:2459
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2787
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
void setImplicitlyInline()
Definition Decl.h:1587
VarDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1381
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp:2870
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:150
std::pair< FileID, unsigned > FileIDAndOffset
llvm::Expected< DeclarationName > ExpectedName
llvm::Expected< Decl * > ExpectedDecl
@ Property
The type of a property.
Definition TypeBase.h:912
@ Result
The result type of a method or function.
Definition TypeBase.h:906
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
llvm::Expected< QualType > ExpectedType
@ Template
We are parsing a template declaration.
Definition Parser.h:81
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
@ VarTemplate
The name was classified as a variable template name.
Definition Sema.h: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:133
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
Definition ASTContext.h:147
llvm::Expected< Expr * > ExpectedExpr
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition DeclBase.h:1305
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition Specifiers.h:189
U cast(CodeGen::Address addr)
Definition Address.h:327
llvm::Expected< Stmt * > ExpectedStmt
static void updateFlags(const Decl *From, Decl *To)
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
const UnsatisfiedConstraintRecord * end() const
Definition ASTConcept.h:100
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
const UnsatisfiedConstraintRecord * begin() const
Definition ASTConcept.h:96
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
const Expr * ConstraintExpr
Definition Decl.h:88
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition Decl.h:885
unsigned HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:899
unsigned HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:907
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5490
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5494
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5480
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5483
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5486
Extra information about a function prototype.
Definition TypeBase.h:5506
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
const NamespaceBaseDecl * Namespace
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Location information for a TemplateArgument.
SourceLocation getTemplateEllipsisLoc() const
SourceLocation getTemplateKwLoc() const
TypeSourceInfo * getAsTypeSourceInfo() const
SourceLocation getTemplateNameLoc() const