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 auto ToQualifierOrErr = import(T->getQualifier());
1642 if (!ToQualifierOrErr)
1643 return ToQualifierOrErr.takeError();
1644 auto ToDeclOrErr = import(T->getDecl());
1645 if (!ToDeclOrErr)
1646 return ToDeclOrErr.takeError();
1647
1649 return Importer.getToContext().getCanonicalUnresolvedUsingType(
1650 *ToDeclOrErr);
1651 return Importer.getToContext().getUnresolvedUsingType(
1652 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr);
1653}
1654
1655ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1656 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1657 if (!ToInnerTypeOrErr)
1658 return ToInnerTypeOrErr.takeError();
1659
1660 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1661}
1662
1664ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1665
1666 ExpectedType Pattern = import(T->getPattern());
1667 if (!Pattern)
1668 return Pattern.takeError();
1669 ExpectedExpr Index = import(T->getIndexExpr());
1670 if (!Index)
1671 return Index.takeError();
1672 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1673}
1674
1675ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1676 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1677 if (!ToDeclOrErr)
1678 return ToDeclOrErr.takeError();
1679
1680 auto ToQualifierOrErr = import(T->getQualifier());
1681 if (!ToQualifierOrErr)
1682 return ToQualifierOrErr.takeError();
1683
1684 ExpectedType ToUnderlyingTypeOrErr =
1685 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1686 if (!ToUnderlyingTypeOrErr)
1687 return ToUnderlyingTypeOrErr.takeError();
1688
1689 return Importer.getToContext().getTypedefType(
1690 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1691}
1692
1693ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1694 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1695 if (!ToExprOrErr)
1696 return ToExprOrErr.takeError();
1697 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1698}
1699
1700ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1701 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1702 if (!ToUnderlyingTypeOrErr)
1703 return ToUnderlyingTypeOrErr.takeError();
1704 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1705 T->getKind());
1706}
1707
1708ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1709 auto ToQualifierOrErr = import(T->getQualifier());
1710 if (!ToQualifierOrErr)
1711 return ToQualifierOrErr.takeError();
1712 auto ToDeclOrErr = import(T->getDecl());
1713 if (!ToDeclOrErr)
1714 return ToDeclOrErr.takeError();
1715
1716 ExpectedType ToTypeOrErr = import(T->desugar());
1717 if (!ToTypeOrErr)
1718 return ToTypeOrErr.takeError();
1719 return Importer.getToContext().getUsingType(
1720 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToTypeOrErr);
1721}
1722
1723ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1724 // FIXME: Make sure that the "to" context supports C++0x!
1725 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1726 if (!ToExprOrErr)
1727 return ToExprOrErr.takeError();
1728
1729 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1730 if (!ToUnderlyingTypeOrErr)
1731 return ToUnderlyingTypeOrErr.takeError();
1732
1733 return Importer.getToContext().getDecltypeType(
1734 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1735}
1736
1738ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1739 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1740 if (!ToBaseTypeOrErr)
1741 return ToBaseTypeOrErr.takeError();
1742
1743 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1744 if (!ToUnderlyingTypeOrErr)
1745 return ToUnderlyingTypeOrErr.takeError();
1746
1747 return Importer.getToContext().getUnaryTransformType(
1748 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1749}
1750
1751ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1752 // FIXME: Make sure that the "to" context supports C++11!
1753 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1754 if (!ToDeducedTypeOrErr)
1755 return ToDeducedTypeOrErr.takeError();
1756
1757 TemplateName ToTypeConstraint;
1758 if (TemplateName FromTypeConstraint = T->getTypeConstraintConcept();
1759 !FromTypeConstraint.isNull()) {
1760 Expected<TemplateName> ToTypeConstraintOrErr = import(FromTypeConstraint);
1761 if (!ToTypeConstraintOrErr)
1762 return ToTypeConstraintOrErr.takeError();
1763 ToTypeConstraint = *ToTypeConstraintOrErr;
1764 }
1765
1766 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1767 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1768 ToTemplateArgs))
1769 return std::move(Err);
1770
1771 return Importer.getToContext().getAutoType(
1772 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1773 ToTypeConstraint, ToTemplateArgs);
1774}
1775
1776ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1777 const DeducedTemplateSpecializationType *T) {
1778 // FIXME: Make sure that the "to" context supports C++17!
1779 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1780 if (!ToTemplateNameOrErr)
1781 return ToTemplateNameOrErr.takeError();
1782 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1783 if (!ToDeducedTypeOrErr)
1784 return ToDeducedTypeOrErr.takeError();
1785
1786 return Importer.getToContext().getDeducedTemplateSpecializationType(
1787 T->getDeducedKind(), *ToDeducedTypeOrErr, T->getKeyword(),
1788 *ToTemplateNameOrErr);
1789}
1790
1791ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1792 TagDecl *DeclForType = T->getDecl();
1793 Expected<TagDecl *> ToDeclOrErr = import(DeclForType);
1794 if (!ToDeclOrErr)
1795 return ToDeclOrErr.takeError();
1796
1797 // If there is a definition of the 'OriginalDecl', it should be imported to
1798 // have all information for the type in the "To" AST. (In some cases no
1799 // other reference may exist to the definition decl and it would not be
1800 // imported otherwise.)
1801 Expected<TagDecl *> ToDefDeclOrErr = import(DeclForType->getDefinition());
1802 if (!ToDefDeclOrErr)
1803 return ToDefDeclOrErr.takeError();
1804
1806 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1807
1808 auto ToQualifierOrErr = import(T->getQualifier());
1809 if (!ToQualifierOrErr)
1810 return ToQualifierOrErr.takeError();
1811
1812 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1813 *ToDeclOrErr, T->isTagOwned());
1814}
1815
1816ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1817 return VisitTagType(T);
1818}
1819
1820ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1821 return VisitTagType(T);
1822}
1823
1825ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1826 return VisitTagType(T);
1827}
1828
1829ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1830 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1831 if (!ToModifiedTypeOrErr)
1832 return ToModifiedTypeOrErr.takeError();
1833 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1834 if (!ToEquivalentTypeOrErr)
1835 return ToEquivalentTypeOrErr.takeError();
1836
1837 return Importer.getToContext().getAttributedType(
1838 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1839 T->getAttr());
1840}
1841
1843ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1844 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1845 if (!ToWrappedTypeOrErr)
1846 return ToWrappedTypeOrErr.takeError();
1847
1848 Error Err = Error::success();
1849 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1850
1851 SmallVector<TypeCoupledDeclRefInfo, 1> CoupledDecls;
1852 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1853 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1854 if (!ToDeclOrErr)
1855 return ToDeclOrErr.takeError();
1856 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1857 }
1858
1859 return Importer.getToContext().getCountAttributedType(
1860 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1861 ArrayRef(CoupledDecls));
1862}
1863
1865ASTNodeImporter::VisitLateParsedAttrType(const LateParsedAttrType *T) {
1866 llvm_unreachable("should be replaced with a concrete type before AST import");
1867}
1868
1869ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1870 const TemplateTypeParmType *T) {
1871 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1872 if (!ToDeclOrErr)
1873 return ToDeclOrErr.takeError();
1874
1875 return Importer.getToContext().getTemplateTypeParmType(
1876 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1877}
1878
1879ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1880 const SubstTemplateTypeParmType *T) {
1881 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1882 if (!ReplacedOrErr)
1883 return ReplacedOrErr.takeError();
1884
1885 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1886 if (!ToReplacementTypeOrErr)
1887 return ToReplacementTypeOrErr.takeError();
1888
1889 return Importer.getToContext().getSubstTemplateTypeParmType(
1890 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1891 T->getFinal());
1892}
1893
1894ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1895 const SubstTemplateTypeParmPackType *T) {
1896 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1897 if (!ReplacedOrErr)
1898 return ReplacedOrErr.takeError();
1899
1900 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1901 if (!ToArgumentPack)
1902 return ToArgumentPack.takeError();
1903
1904 return Importer.getToContext().getSubstTemplateTypeParmPackType(
1905 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1906}
1907
1908ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1909 const SubstBuiltinTemplatePackType *T) {
1910 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1911 if (!ToArgumentPack)
1912 return ToArgumentPack.takeError();
1913 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1914}
1915
1916ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1917 const TemplateSpecializationType *T) {
1918 auto ToTemplateOrErr = import(T->getTemplateName());
1919 if (!ToTemplateOrErr)
1920 return ToTemplateOrErr.takeError();
1921
1922 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1923 if (Error Err =
1924 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1925 return std::move(Err);
1926
1927 ExpectedType ToUnderlyingOrErr =
1928 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1929 if (!ToUnderlyingOrErr)
1930 return ToUnderlyingOrErr.takeError();
1931 return Importer.getToContext().getTemplateSpecializationType(
1932 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1933 *ToUnderlyingOrErr);
1934}
1935
1937ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1938 ExpectedType ToPatternOrErr = import(T->getPattern());
1939 if (!ToPatternOrErr)
1940 return ToPatternOrErr.takeError();
1941
1942 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1943 T->getNumExpansions(),
1944 /*ExpactPack=*/false);
1945}
1946
1948ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1949 auto ToQualifierOrErr = import(T->getQualifier());
1950 if (!ToQualifierOrErr)
1951 return ToQualifierOrErr.takeError();
1952
1953 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1954 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1955 *ToQualifierOrErr, Name);
1956}
1957
1959ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1960 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1961 if (!ToDeclOrErr)
1962 return ToDeclOrErr.takeError();
1963
1964 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1965}
1966
1967ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1968 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1969 if (!ToBaseTypeOrErr)
1970 return ToBaseTypeOrErr.takeError();
1971
1972 SmallVector<QualType, 4> TypeArgs;
1973 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1974 if (ExpectedType TyOrErr = import(TypeArg))
1975 TypeArgs.push_back(*TyOrErr);
1976 else
1977 return TyOrErr.takeError();
1978 }
1979
1980 SmallVector<ObjCProtocolDecl *, 4> Protocols;
1981 for (auto *P : T->quals()) {
1982 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1983 Protocols.push_back(*ProtocolOrErr);
1984 else
1985 return ProtocolOrErr.takeError();
1986
1987 }
1988
1989 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1990 Protocols,
1991 T->isKindOfTypeAsWritten());
1992}
1993
1995ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1996 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1997 if (!ToPointeeTypeOrErr)
1998 return ToPointeeTypeOrErr.takeError();
1999
2000 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
2001}
2002
2004ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
2005 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
2006 if (!ToUnderlyingTypeOrErr)
2007 return ToUnderlyingTypeOrErr.takeError();
2008
2009 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
2010 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
2011 ToIdentifier);
2012}
2013
2014ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
2015 Error Err = Error::success();
2016 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
2017 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
2018 if (Err)
2019 return std::move(Err);
2020
2021 return Importer.getToContext().getAdjustedType(ToOriginalType,
2022 ToAdjustedType);
2023}
2024
2025ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
2026 return Importer.getToContext().getBitIntType(T->isUnsigned(),
2027 T->getNumBits());
2028}
2029
2030ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
2031 const clang::BTFTagAttributedType *T) {
2032 Error Err = Error::success();
2033 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
2034 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2035 if (Err)
2036 return std::move(Err);
2037
2038 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
2039 ToWrappedType);
2040}
2041
2042ExpectedType clang::ASTNodeImporter::VisitOverflowBehaviorType(
2043 const clang::OverflowBehaviorType *T) {
2044 Error Err = Error::success();
2045 OverflowBehaviorType::OverflowBehaviorKind ToKind = T->getBehaviorKind();
2046 QualType ToUnderlyingType = importChecked(Err, T->getUnderlyingType());
2047 if (Err)
2048 return std::move(Err);
2049
2050 return Importer.getToContext().getOverflowBehaviorType(ToKind,
2052}
2053
2054ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2055 const clang::HLSLAttributedResourceType *T) {
2056 Error Err = Error::success();
2057 HLSLAttributedResourceType::Attributes ToAttrs = T->getAttrs();
2058 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2059 QualType ToContainedType = importChecked(Err, T->getContainedType());
2060 ToAttrs.SampleCountExpr = importChecked(Err, T->getSampleCountExpr());
2061 if (Err)
2062 return std::move(Err);
2063
2064 return Importer.getToContext().getHLSLAttributedResourceType(
2065 ToWrappedType, ToContainedType, ToAttrs);
2066}
2067
2068ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2069 const clang::HLSLInlineSpirvType *T) {
2070 Error Err = Error::success();
2071
2072 uint32_t ToOpcode = T->getOpcode();
2073 uint32_t ToSize = T->getSize();
2074 uint32_t ToAlignment = T->getAlignment();
2075
2076 llvm::SmallVector<SpirvOperand> ToOperands;
2077
2078 for (auto &Operand : T->getOperands()) {
2079 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2080
2081 switch (Operand.getKind()) {
2082 case SpirvOperandKind::ConstantId:
2083 ToOperands.push_back(SpirvOperand::createConstant(
2084 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2085 break;
2086 case SpirvOperandKind::Literal:
2087 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2088 break;
2089 case SpirvOperandKind::TypeId:
2090 ToOperands.push_back(SpirvOperand::createType(
2091 importChecked(Err, Operand.getResultType())));
2092 break;
2093 default:
2094 llvm_unreachable("Invalid SpirvOperand kind");
2095 }
2096
2097 if (Err)
2098 return std::move(Err);
2099 }
2100
2101 return Importer.getToContext().getHLSLInlineSpirvType(
2102 ToOpcode, ToSize, ToAlignment, ToOperands);
2103}
2104
2105ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2106 const clang::ConstantMatrixType *T) {
2107 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2108 if (!ToElementTypeOrErr)
2109 return ToElementTypeOrErr.takeError();
2110
2111 return Importer.getToContext().getConstantMatrixType(
2112 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2113}
2114
2115ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2116 const clang::DependentAddressSpaceType *T) {
2117 Error Err = Error::success();
2118 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2119 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2120 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2121 if (Err)
2122 return std::move(Err);
2123
2124 return Importer.getToContext().getDependentAddressSpaceType(
2125 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2126}
2127
2128ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2129 const clang::DependentBitIntType *T) {
2130 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2131 if (!ToNumBitsExprOrErr)
2132 return ToNumBitsExprOrErr.takeError();
2133 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2134 *ToNumBitsExprOrErr);
2135}
2136
2137ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2138 const clang::PredefinedSugarType *T) {
2139 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2140}
2141
2142ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2143 const clang::DependentSizedMatrixType *T) {
2144 Error Err = Error::success();
2145 QualType ToElementType = importChecked(Err, T->getElementType());
2146 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2147 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2148 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2149 if (Err)
2150 return std::move(Err);
2151
2152 return Importer.getToContext().getDependentSizedMatrixType(
2153 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2154}
2155
2156ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2157 const clang::DependentVectorType *T) {
2158 Error Err = Error::success();
2159 QualType ToElementType = importChecked(Err, T->getElementType());
2160 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2161 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2162 if (Err)
2163 return std::move(Err);
2164
2165 return Importer.getToContext().getDependentVectorType(
2166 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2167}
2168
2169ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2170 const clang::ObjCTypeParamType *T) {
2171 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2172 if (!ToDeclOrErr)
2173 return ToDeclOrErr.takeError();
2174
2175 SmallVector<ObjCProtocolDecl *, 4> ToProtocols;
2176 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2177 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2178 if (!ToProtocolOrErr)
2179 return ToProtocolOrErr.takeError();
2180 ToProtocols.push_back(*ToProtocolOrErr);
2181 }
2182
2183 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2184 ToProtocols);
2185}
2186
2187ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2188 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2189 if (!ToElementTypeOrErr)
2190 return ToElementTypeOrErr.takeError();
2191
2192 ASTContext &ToCtx = Importer.getToContext();
2193 if (T->isReadOnly())
2194 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2195 else
2196 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2197}
2198
2199//----------------------------------------------------------------------------
2200// Import Declarations
2201//----------------------------------------------------------------------------
2203 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2204 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
2205 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2206 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2207 // FIXME: We could support these constructs by importing a different type of
2208 // this parameter and by importing the original type of the parameter only
2209 // after the FunctionDecl is created. See
2210 // VisitFunctionDecl::UsedDifferentProtoType.
2211 DeclContext *OrigDC = D->getDeclContext();
2212 FunctionDecl *FunDecl;
2213 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2214 FunDecl->hasBody()) {
2215 auto getLeafPointeeType = [](const Type *T) {
2216 while (T->isPointerType() || T->isArrayType()) {
2217 T = T->getPointeeOrArrayElementType();
2218 }
2219 return T;
2220 };
2221 for (const ParmVarDecl *P : FunDecl->parameters()) {
2222 const Type *LeafT =
2223 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2224 auto *RT = dyn_cast<RecordType>(LeafT);
2225 if (RT && RT->getDecl() == D) {
2226 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2227 << D->getDeclKindName();
2228 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2229 }
2230 }
2231 }
2232
2233 // Import the context of this declaration.
2234 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2235 return Err;
2236
2237 // Import the name of this declaration.
2238 if (Error Err = importInto(Name, D->getDeclName()))
2239 return Err;
2240
2241 // Import the location of this declaration.
2242 if (Error Err = importInto(Loc, D->getLocation()))
2243 return Err;
2244
2245 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2246 if (ToD)
2247 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2248 return Err;
2249
2250 return Error::success();
2251}
2252
2254 NamedDecl *&ToD, SourceLocation &Loc) {
2255
2256 // Import the name of this declaration.
2257 if (Error Err = importInto(Name, D->getDeclName()))
2258 return Err;
2259
2260 // Import the location of this declaration.
2261 if (Error Err = importInto(Loc, D->getLocation()))
2262 return Err;
2263
2264 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2265 if (ToD)
2266 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2267 return Err;
2268
2269 return Error::success();
2270}
2271
2273 if (!FromD)
2274 return Error::success();
2275
2276 if (!ToD)
2277 if (Error Err = importInto(ToD, FromD))
2278 return Err;
2279
2280 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2281 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2282 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2283 !ToRecord->getDefinition()) {
2284 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2285 return Err;
2286 }
2287 }
2288 return Error::success();
2289 }
2290
2291 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2292 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2293 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2294 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2295 return Err;
2296 }
2297 }
2298 return Error::success();
2299 }
2300
2301 return Error::success();
2302}
2303
2304Error
2306 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2307 // NOTE: To.Name and To.Loc are already imported.
2308 // We only have to import To.LocInfo.
2309 switch (To.getName().getNameKind()) {
2316 return Error::success();
2317
2319 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2320 To.setCXXOperatorNameRange(*ToRangeOrErr);
2321 else
2322 return ToRangeOrErr.takeError();
2323 return Error::success();
2324 }
2326 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2327 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2328 else
2329 return LocOrErr.takeError();
2330 return Error::success();
2331 }
2335 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2336 To.setNamedTypeInfo(*ToTInfoOrErr);
2337 else
2338 return ToTInfoOrErr.takeError();
2339 return Error::success();
2340 }
2341 }
2342 llvm_unreachable("Unknown name kind.");
2343}
2344
2345Error
2347 if (Importer.isMinimalImport() && !ForceImport) {
2348 auto ToDCOrErr = Importer.ImportContext(FromDC);
2349 return ToDCOrErr.takeError();
2350 }
2351
2352 // We use strict error handling in case of records and enums, but not
2353 // with e.g. namespaces.
2354 //
2355 // FIXME Clients of the ASTImporter should be able to choose an
2356 // appropriate error handling strategy for their needs. For instance,
2357 // they may not want to mark an entire namespace as erroneous merely
2358 // because there is an ODR error with two typedefs. As another example,
2359 // the client may allow EnumConstantDecls with same names but with
2360 // different values in two distinct translation units.
2361 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2362
2363 auto MightNeedReordering = [](const Decl *D) {
2365 };
2366
2367 // Import everything that might need reordering first.
2368 Error ChildErrors = Error::success();
2369 for (auto *From : FromDC->decls()) {
2370 if (!MightNeedReordering(From))
2371 continue;
2372
2373 ExpectedDecl ImportedOrErr = import(From);
2374
2375 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2376 // want to make sure that we are also completing each FieldDecl. There
2377 // are currently cases where this does not happen and this is correctness
2378 // fix since operations such as code generation will expect this to be so.
2379 if (!ImportedOrErr) {
2380 HandleChildErrors.handleChildImportResult(ChildErrors,
2381 ImportedOrErr.takeError());
2382 continue;
2383 }
2384 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2385 Decl *ImportedDecl = *ImportedOrErr;
2386 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2387 if (FieldFrom && FieldTo) {
2388 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2389 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2390 }
2391 }
2392
2393 // We reorder declarations in RecordDecls because they may have another order
2394 // in the "to" context than they have in the "from" context. This may happen
2395 // e.g when we import a class like this:
2396 // struct declToImport {
2397 // int a = c + b;
2398 // int b = 1;
2399 // int c = 2;
2400 // };
2401 // During the import of `a` we import first the dependencies in sequence,
2402 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2403 // first removing the already imported members and then adding them in the
2404 // order as they appear in the "from" context.
2405 //
2406 // Keeping field order is vital because it determines structure layout.
2407 //
2408 // Here and below, we cannot call field_begin() method and its callers on
2409 // ToDC if it has an external storage. Calling field_begin() will
2410 // automatically load all the fields by calling
2411 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2412 // call ASTImporter::Import(). This is because the ExternalASTSource
2413 // interface in LLDB is implemented by the means of the ASTImporter. However,
2414 // calling an import at this point would result in an uncontrolled import, we
2415 // must avoid that.
2416
2417 auto ToDCOrErr = Importer.ImportContext(FromDC);
2418 if (!ToDCOrErr) {
2419 consumeError(std::move(ChildErrors));
2420 return ToDCOrErr.takeError();
2421 }
2422
2423 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2424 DeclContext *ToDC = *ToDCOrErr;
2425 // Remove all declarations, which may be in wrong order in the
2426 // lexical DeclContext and then add them in the proper order.
2427 for (auto *D : FromRD->decls()) {
2428 if (!MightNeedReordering(D))
2429 continue;
2430
2431 assert(D && "DC contains a null decl");
2432 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2433 // Remove only the decls which we successfully imported.
2434 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2435 // Remove the decl from its wrong place in the linked list.
2436 ToDC->removeDecl(ToD);
2437 // Add the decl to the end of the linked list.
2438 // This time it will be at the proper place because the enclosing for
2439 // loop iterates in the original (good) order of the decls.
2440 ToDC->addDeclInternal(ToD);
2441 }
2442 }
2443 }
2444
2445 // Import everything else.
2446 for (auto *From : FromDC->decls()) {
2447 if (MightNeedReordering(From))
2448 continue;
2449
2450 ExpectedDecl ImportedOrErr = import(From);
2451 if (!ImportedOrErr)
2452 HandleChildErrors.handleChildImportResult(ChildErrors,
2453 ImportedOrErr.takeError());
2454 }
2455
2456 return ChildErrors;
2457}
2458
2460 const FieldDecl *To) {
2461 RecordDecl *FromRecordDecl = nullptr;
2462 RecordDecl *ToRecordDecl = nullptr;
2463 // If we have a field that is an ArrayType we need to check if the array
2464 // element is a RecordDecl and if so we need to import the definition.
2465 QualType FromType = From->getType();
2466 QualType ToType = To->getType();
2467 if (FromType->isArrayType()) {
2468 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2469 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2470 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2471 }
2472
2473 if (!FromRecordDecl || !ToRecordDecl) {
2474 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2475 const RecordType *RecordTo = ToType->getAs<RecordType>();
2476
2477 if (RecordFrom && RecordTo) {
2478 FromRecordDecl = RecordFrom->getDecl();
2479 ToRecordDecl = RecordTo->getDecl();
2480 }
2481 }
2482
2483 if (FromRecordDecl && ToRecordDecl) {
2484 if (FromRecordDecl->isCompleteDefinition() &&
2485 !ToRecordDecl->isCompleteDefinition())
2486 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2487 }
2488
2489 return Error::success();
2490}
2491
2493 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2494 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2495 if (!ToDCOrErr)
2496 return ToDCOrErr.takeError();
2497 ToDC = *ToDCOrErr;
2498
2499 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2500 auto ToLexicalDCOrErr = Importer.ImportContext(
2501 FromD->getLexicalDeclContext());
2502 if (!ToLexicalDCOrErr)
2503 return ToLexicalDCOrErr.takeError();
2504 ToLexicalDC = *ToLexicalDCOrErr;
2505 } else
2506 ToLexicalDC = ToDC;
2507
2508 return Error::success();
2509}
2510
2512 const CXXRecordDecl *From, CXXRecordDecl *To) {
2513 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2514 "Import implicit methods to or from non-definition");
2515
2516 for (CXXMethodDecl *FromM : From->methods())
2517 if (FromM->isImplicit()) {
2518 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2519 if (!ToMOrErr)
2520 return ToMOrErr.takeError();
2521 }
2522
2523 return Error::success();
2524}
2525
2527 ASTImporter &Importer) {
2528 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2529 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2531 else
2532 return ToTypedefOrErr.takeError();
2533 }
2534 return Error::success();
2535}
2536
2538 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2539 auto DefinitionCompleter = [To]() {
2540 // There are cases in LLDB when we first import a class without its
2541 // members. The class will have DefinitionData, but no members. Then,
2542 // importDefinition is called from LLDB, which tries to get the members, so
2543 // when we get here, the class already has the DefinitionData set, so we
2544 // must unset the CompleteDefinition here to be able to complete again the
2545 // definition.
2546 To->setCompleteDefinition(false);
2547 To->completeDefinition();
2548 };
2549
2550 if (To->getDefinition() || To->isBeingDefined()) {
2551 if (Kind == IDK_Everything ||
2552 // In case of lambdas, the class already has a definition ptr set, but
2553 // the contained decls are not imported yet. Also, isBeingDefined was
2554 // set in CXXRecordDecl::CreateLambda. We must import the contained
2555 // decls here and finish the definition.
2556 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2557 if (To->isLambda()) {
2558 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2560 ToCaptures.reserve(FromCXXRD->capture_size());
2561 for (const auto &FromCapture : FromCXXRD->captures()) {
2562 if (auto ToCaptureOrErr = import(FromCapture))
2563 ToCaptures.push_back(*ToCaptureOrErr);
2564 else
2565 return ToCaptureOrErr.takeError();
2566 }
2567 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2568 ToCaptures);
2569 }
2570
2571 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2572 // Finish the definition of the lambda, set isBeingDefined to false.
2573 if (To->isLambda())
2574 DefinitionCompleter();
2575 return Result;
2576 }
2577
2578 return Error::success();
2579 }
2580
2581 To->startDefinition();
2582 // Set the definition to complete even if it is really not complete during
2583 // import. Some AST constructs (expressions) require the record layout
2584 // to be calculated (see 'clang::computeDependence') at the time they are
2585 // constructed. Import of such AST node is possible during import of the
2586 // same record, there is no way to have a completely defined record (all
2587 // fields imported) at that time without multiple AST import passes.
2588 if (!Importer.isMinimalImport())
2589 To->setCompleteDefinition(true);
2590 // Complete the definition even if error is returned.
2591 // The RecordDecl may be already part of the AST so it is better to
2592 // have it in complete state even if something is wrong with it.
2593 llvm::scope_exit DefinitionCompleterScopeExit(DefinitionCompleter);
2594
2595 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2596 return Err;
2597
2598 // Add base classes.
2599 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2600 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2601 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2602
2603 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2604 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2605
2606 #define FIELD(Name, Width, Merge) \
2607 ToData.Name = FromData.Name;
2608 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2609
2610 // Copy over the data stored in RecordDeclBits
2611 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2612
2614 for (const auto &Base1 : FromCXX->bases()) {
2615 ExpectedType TyOrErr = import(Base1.getType());
2616 if (!TyOrErr)
2617 return TyOrErr.takeError();
2618
2619 SourceLocation EllipsisLoc;
2620 if (Base1.isPackExpansion()) {
2621 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2622 EllipsisLoc = *LocOrErr;
2623 else
2624 return LocOrErr.takeError();
2625 }
2626
2627 // Ensure that we have a definition for the base.
2628 if (Error Err =
2629 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2630 return Err;
2631
2632 auto RangeOrErr = import(Base1.getSourceRange());
2633 if (!RangeOrErr)
2634 return RangeOrErr.takeError();
2635
2636 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2637 if (!TSIOrErr)
2638 return TSIOrErr.takeError();
2639
2640 Bases.push_back(
2641 new (Importer.getToContext()) CXXBaseSpecifier(
2642 *RangeOrErr,
2643 Base1.isVirtual(),
2644 Base1.isBaseOfClass(),
2645 Base1.getAccessSpecifierAsWritten(),
2646 *TSIOrErr,
2647 EllipsisLoc));
2648 }
2649 if (!Bases.empty())
2650 ToCXX->setBases(Bases.data(), Bases.size());
2651 }
2652
2653 if (shouldForceImportDeclContext(Kind)) {
2654 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2655 return Err;
2656 }
2657
2658 return Error::success();
2659}
2660
2662 if (To->getAnyInitializer())
2663 return Error::success();
2664
2665 Expr *FromInit = From->getInit();
2666 if (!FromInit)
2667 return Error::success();
2668
2669 ExpectedExpr ToInitOrErr = import(FromInit);
2670 if (!ToInitOrErr)
2671 return ToInitOrErr.takeError();
2672
2673 To->setInit(*ToInitOrErr);
2674 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2675 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2676 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2677 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2678 // FIXME: Also import the initializer value.
2679 }
2680
2681 // FIXME: Other bits to merge?
2682 return Error::success();
2683}
2684
2686 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2687 if (To->getDefinition() || To->isBeingDefined()) {
2688 if (Kind == IDK_Everything)
2689 return ImportDeclContext(From, /*ForceImport=*/true);
2690 return Error::success();
2691 }
2692
2693 To->startDefinition();
2694
2695 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2696 return Err;
2697
2698 ExpectedType ToTypeOrErr =
2699 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2700 if (!ToTypeOrErr)
2701 return ToTypeOrErr.takeError();
2702
2703 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2704 if (!ToPromotionTypeOrErr)
2705 return ToPromotionTypeOrErr.takeError();
2706
2708 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2709 return Err;
2710
2711 // FIXME: we might need to merge the number of positive or negative bits
2712 // if the enumerator lists don't match.
2713 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2714 From->getNumPositiveBits(),
2715 From->getNumNegativeBits());
2716 return Error::success();
2717}
2718
2722 for (const auto &Arg : FromArgs) {
2723 if (auto ToOrErr = import(Arg))
2724 ToArgs.push_back(*ToOrErr);
2725 else
2726 return ToOrErr.takeError();
2727 }
2728
2729 return Error::success();
2730}
2731
2732// FIXME: Do not forget to remove this and use only 'import'.
2735 return import(From);
2736}
2737
2738template <typename InContainerTy>
2740 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2741 for (const auto &FromLoc : Container) {
2742 if (auto ToLocOrErr = import(FromLoc))
2743 ToTAInfo.addArgument(*ToLocOrErr);
2744 else
2745 return ToLocOrErr.takeError();
2746 }
2747 return Error::success();
2748}
2749
2755
2756bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2757 bool IgnoreTemplateParmDepth) {
2758 // Eliminate a potential failure point where we attempt to re-import
2759 // something we're trying to import while completing ToRecord.
2760 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2761 if (ToOrigin) {
2762 To = ToOrigin;
2763 }
2764
2766 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2767 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2769 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2770 IgnoreTemplateParmDepth);
2771 return Ctx.IsEquivalent(From, To);
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 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2782 << D->getDeclKindName();
2783 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2784}
2785
2787 // Import the context of this declaration.
2788 DeclContext *DC, *LexicalDC;
2789 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2790 return std::move(Err);
2791
2792 // Import the location of this declaration.
2793 ExpectedSLoc LocOrErr = import(D->getLocation());
2794 if (!LocOrErr)
2795 return LocOrErr.takeError();
2796
2797 EmptyDecl *ToD;
2798 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2799 return ToD;
2800
2801 ToD->setLexicalDeclContext(LexicalDC);
2802 LexicalDC->addDeclInternal(ToD);
2803 return ToD;
2804}
2805
2807 TranslationUnitDecl *ToD =
2808 Importer.getToContext().getTranslationUnitDecl();
2809
2810 Importer.MapImported(D, ToD);
2811
2812 return ToD;
2813}
2814
2816 Error Err = Error::success();
2817 Expr *ToAsmString = importChecked(Err, D->getAsmStringExpr());
2818 SourceLocation ToAsmLoc = importChecked(Err, D->getAsmLoc());
2819 SourceLocation ToRParenLoc = importChecked(Err, D->getRParenLoc());
2820 if (Err)
2821 return std::move(Err);
2822
2823 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2824 if (!DCOrErr)
2825 return DCOrErr.takeError();
2826 DeclContext *DC = *DCOrErr;
2827
2828 FileScopeAsmDecl *ToD;
2829 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToAsmString,
2830 ToAsmLoc, ToRParenLoc))
2831 return ToD;
2832
2833 ToD->setLexicalDeclContext(DC);
2834 DC->addDeclInternal(ToD);
2835
2836 return ToD;
2837}
2838
2840 DeclContext *DC, *LexicalDC;
2841 DeclarationName Name;
2842 SourceLocation Loc;
2843 NamedDecl *ToND;
2844 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2845 return std::move(Err);
2846 if (ToND)
2847 return ToND;
2848
2849 BindingDecl *ToD;
2850 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2851 Name.getAsIdentifierInfo(), D->getType()))
2852 return ToD;
2853
2854 Error Err = Error::success();
2855 QualType ToType = importChecked(Err, D->getType());
2856 Expr *ToBinding = importChecked(Err, D->getBinding());
2857 DecompositionDecl *ToDecomposedDecl =
2859 if (Err)
2860 return std::move(Err);
2861
2862 ToD->setBinding(ToType, ToBinding);
2863 ToD->setDecomposedDecl(ToDecomposedDecl);
2864 addDeclToContexts(D, ToD);
2865
2866 return ToD;
2867}
2868
2870 ExpectedSLoc LocOrErr = import(D->getLocation());
2871 if (!LocOrErr)
2872 return LocOrErr.takeError();
2873 auto ColonLocOrErr = import(D->getColonLoc());
2874 if (!ColonLocOrErr)
2875 return ColonLocOrErr.takeError();
2876
2877 // Import the context of this declaration.
2878 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2879 if (!DCOrErr)
2880 return DCOrErr.takeError();
2881 DeclContext *DC = *DCOrErr;
2882
2883 AccessSpecDecl *ToD;
2884 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2885 DC, *LocOrErr, *ColonLocOrErr))
2886 return ToD;
2887
2888 // Lexical DeclContext and Semantic DeclContext
2889 // is always the same for the accessSpec.
2890 ToD->setLexicalDeclContext(DC);
2891 DC->addDeclInternal(ToD);
2892
2893 return ToD;
2894}
2895
2897 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2898 if (!DCOrErr)
2899 return DCOrErr.takeError();
2900 DeclContext *DC = *DCOrErr;
2901 DeclContext *LexicalDC = DC;
2902
2903 Error Err = Error::success();
2904 auto ToLocation = importChecked(Err, D->getLocation());
2905 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2906 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2907 auto ToMessage = importChecked(Err, D->getMessage());
2908 if (Err)
2909 return std::move(Err);
2910
2911 StaticAssertDecl *ToD;
2912 if (GetImportedOrCreateDecl(
2913 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2914 ToRParenLoc, D->isFailed()))
2915 return ToD;
2916
2917 ToD->setLexicalDeclContext(LexicalDC);
2918 LexicalDC->addDeclInternal(ToD);
2919 return ToD;
2920}
2921
2924 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2925 if (!DCOrErr)
2926 return DCOrErr.takeError();
2927 DeclContext *DC = *DCOrErr;
2928 DeclContext *LexicalDC = DC;
2929
2930 Error Err = Error::success();
2931 auto ToLocation = importChecked(Err, D->getLocation());
2932 auto ToExpansion = importChecked(Err, D->getExpansionPattern());
2933 auto ToIndex = importChecked(Err, D->getIndexTemplateParm());
2934 auto ToInstantiations = importChecked(Err, D->getInstantiations());
2935 if (Err)
2936 return std::move(Err);
2937
2939 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToLocation,
2940 ToIndex))
2941 return ToD;
2942
2943 ToD->setExpansionPattern(ToExpansion);
2944 ToD->setInstantiations(ToInstantiations);
2945 ToD->setLexicalDeclContext(LexicalDC);
2946 LexicalDC->addDeclInternal(ToD);
2947 return ToD;
2948}
2949
2951 // Import the major distinguishing characteristics of this namespace.
2952 DeclContext *DC, *LexicalDC;
2953 DeclarationName Name;
2954 SourceLocation Loc;
2955 NamedDecl *ToD;
2956 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2957 return std::move(Err);
2958 if (ToD)
2959 return ToD;
2960
2961 NamespaceDecl *MergeWithNamespace = nullptr;
2962 if (!Name) {
2963 // This is an anonymous namespace. Adopt an existing anonymous
2964 // namespace if we can.
2965 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2966 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2967 MergeWithNamespace = TU->getAnonymousNamespace();
2968 else
2969 MergeWithNamespace =
2970 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2971 } else {
2972 SmallVector<NamedDecl *, 4> ConflictingDecls;
2973 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2974 for (auto *FoundDecl : FoundDecls) {
2975 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace))
2976 continue;
2977
2978 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2979 MergeWithNamespace = FoundNS;
2980 ConflictingDecls.clear();
2981 break;
2982 }
2983
2984 ConflictingDecls.push_back(FoundDecl);
2985 }
2986
2987 if (!ConflictingDecls.empty()) {
2988 ExpectedName NameOrErr = Importer.HandleNameConflict(
2989 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2990 ConflictingDecls.size());
2991 if (NameOrErr)
2992 Name = NameOrErr.get();
2993 else
2994 return NameOrErr.takeError();
2995 }
2996 }
2997
2998 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2999 if (!BeginLocOrErr)
3000 return BeginLocOrErr.takeError();
3001 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
3002 if (!RBraceLocOrErr)
3003 return RBraceLocOrErr.takeError();
3004
3005 // Create the "to" namespace, if needed.
3006 NamespaceDecl *ToNamespace = MergeWithNamespace;
3007 if (!ToNamespace) {
3008 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
3009 D->isInline(), *BeginLocOrErr, Loc,
3010 Name.getAsIdentifierInfo(),
3011 /*PrevDecl=*/nullptr, D->isNested()))
3012 return ToNamespace;
3013 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
3014 ToNamespace->setLexicalDeclContext(LexicalDC);
3015 LexicalDC->addDeclInternal(ToNamespace);
3016
3017 // If this is an anonymous namespace, register it as the anonymous
3018 // namespace within its context.
3019 if (!Name) {
3020 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3021 TU->setAnonymousNamespace(ToNamespace);
3022 else
3023 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
3024 }
3025 }
3026 Importer.MapImported(D, ToNamespace);
3027
3028 if (Error Err = ImportDeclContext(D))
3029 return std::move(Err);
3030
3031 return ToNamespace;
3032}
3033
3035 // Import the major distinguishing characteristics of this namespace.
3036 DeclContext *DC, *LexicalDC;
3037 DeclarationName Name;
3038 SourceLocation Loc;
3039 NamedDecl *LookupD;
3040 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
3041 return std::move(Err);
3042 if (LookupD)
3043 return LookupD;
3044
3045 // NOTE: No conflict resolution is done for namespace aliases now.
3046
3047 Error Err = Error::success();
3048 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
3049 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
3050 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3051 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
3052 auto ToNamespace = importChecked(Err, D->getNamespace());
3053 if (Err)
3054 return std::move(Err);
3055
3056 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
3057
3058 NamespaceAliasDecl *ToD;
3059 if (GetImportedOrCreateDecl(
3060 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
3061 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
3062 return ToD;
3063
3064 ToD->setLexicalDeclContext(LexicalDC);
3065 LexicalDC->addDeclInternal(ToD);
3066
3067 return ToD;
3068}
3069
3072 // Import the major distinguishing characteristics of this typedef.
3073 DeclarationName Name;
3074 SourceLocation Loc;
3075 NamedDecl *ToD;
3076 // Do not import the DeclContext, we will import it once the TypedefNameDecl
3077 // is created.
3078 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
3079 return std::move(Err);
3080 if (ToD)
3081 return ToD;
3082
3083 DeclContext *DC = cast_or_null<DeclContext>(
3084 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
3085 DeclContext *LexicalDC =
3086 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
3088
3089 // If this typedef is not in block scope, determine whether we've
3090 // seen a typedef with the same name (that we can merge with) or any
3091 // other entity by that name (which name lookup could conflict with).
3092 // Note: Repeated typedefs are not valid in C99:
3093 // 'typedef int T; typedef int T;' is invalid
3094 // We do not care about this now.
3095 if (DC && !DC->isFunctionOrMethod()) {
3096 SmallVector<NamedDecl *, 4> ConflictingDecls;
3097 unsigned IDNS = Decl::IDNS_Ordinary;
3098 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3099 for (auto *FoundDecl : FoundDecls) {
3100 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3101 continue;
3102 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3103 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
3104 continue;
3105
3106 QualType FromUT = D->getUnderlyingType();
3107 QualType FoundUT = FoundTypedef->getUnderlyingType();
3108 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3109 // If the underlying declarations are unnamed records these can be
3110 // imported as different types. We should create a distinct typedef
3111 // node in this case.
3112 // If we found an existing underlying type with a record in a
3113 // different context (than the imported), this is already reason for
3114 // having distinct typedef nodes for these.
3115 // Again this can create situation like
3116 // 'typedef int T; typedef int T;' but this is hard to avoid without
3117 // a rename strategy at import.
3118 if (!FromUT.isNull() && !FoundUT.isNull()) {
3119 RecordDecl *FromR = FromUT->getAsRecordDecl();
3120 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3121 if (FromR && FoundR &&
3122 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3123 continue;
3124 }
3125 // If the "From" context has a complete underlying type but we
3126 // already have a complete underlying type then return with that.
3127 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3128 return Importer.MapImported(D, FoundTypedef);
3129 // FIXME Handle redecl chain. When you do that make consistent changes
3130 // in ASTImporterLookupTable too.
3131 } else {
3132 ConflictingDecls.push_back(FoundDecl);
3133 }
3134 }
3135 }
3136
3137 if (!ConflictingDecls.empty()) {
3138 ExpectedName NameOrErr = Importer.HandleNameConflict(
3139 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3140 if (NameOrErr)
3141 Name = NameOrErr.get();
3142 else
3143 return NameOrErr.takeError();
3144 }
3145 }
3146
3147 Error Err = Error::success();
3149 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3150 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3151 if (Err)
3152 return std::move(Err);
3153
3154 // Create the new typedef node.
3155 // FIXME: ToUnderlyingType is not used.
3156 (void)ToUnderlyingType;
3157 TypedefNameDecl *ToTypedef;
3158 if (IsAlias) {
3159 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3160 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3161 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3162 return ToTypedef;
3163 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3164 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3165 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3166 return ToTypedef;
3167
3168 // Import the DeclContext and set it to the Typedef.
3169 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3170 return std::move(Err);
3171 ToTypedef->setDeclContext(DC);
3172 ToTypedef->setLexicalDeclContext(LexicalDC);
3173 // Add to the lookupTable because we could not do that in MapImported.
3174 Importer.AddToLookupTable(ToTypedef);
3175
3176 ToTypedef->setAccess(D->getAccess());
3177
3178 // Templated declarations should not appear in DeclContext.
3179 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3180 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3181 LexicalDC->addDeclInternal(ToTypedef);
3182
3183 return ToTypedef;
3184}
3185
3189
3193
3196 // Import the major distinguishing characteristics of this typedef.
3197 DeclContext *DC, *LexicalDC;
3198 DeclarationName Name;
3199 SourceLocation Loc;
3200 NamedDecl *FoundD;
3201 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3202 return std::move(Err);
3203 if (FoundD)
3204 return FoundD;
3205
3206 // If this typedef is not in block scope, determine whether we've
3207 // seen a typedef with the same name (that we can merge with) or any
3208 // other entity by that name (which name lookup could conflict with).
3209 if (!DC->isFunctionOrMethod()) {
3210 SmallVector<NamedDecl *, 4> ConflictingDecls;
3211 unsigned IDNS = Decl::IDNS_Ordinary;
3212 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3213 for (auto *FoundDecl : FoundDecls) {
3214 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3215 continue;
3216 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3217 if (IsStructuralMatch(D, FoundAlias))
3218 return Importer.MapImported(D, FoundAlias);
3219 ConflictingDecls.push_back(FoundDecl);
3220 }
3221 }
3222
3223 if (!ConflictingDecls.empty()) {
3224 ExpectedName NameOrErr = Importer.HandleNameConflict(
3225 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3226 if (NameOrErr)
3227 Name = NameOrErr.get();
3228 else
3229 return NameOrErr.takeError();
3230 }
3231 }
3232
3233 Error Err = Error::success();
3234 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3235 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3236 if (Err)
3237 return std::move(Err);
3238
3239 TypeAliasTemplateDecl *ToAlias;
3240 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3241 Name, ToTemplateParameters, ToTemplatedDecl))
3242 return ToAlias;
3243
3244 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3245
3246 ToAlias->setAccess(D->getAccess());
3247 ToAlias->setLexicalDeclContext(LexicalDC);
3248 LexicalDC->addDeclInternal(ToAlias);
3249 if (DC != Importer.getToContext().getTranslationUnitDecl())
3250 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3251 return ToAlias;
3252}
3253
3255 // Import the major distinguishing characteristics of this label.
3256 DeclContext *DC, *LexicalDC;
3257 DeclarationName Name;
3258 SourceLocation Loc;
3259 NamedDecl *ToD;
3260 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3261 return std::move(Err);
3262 if (ToD)
3263 return ToD;
3264
3265 assert(LexicalDC->isFunctionOrMethod());
3266
3267 LabelDecl *ToLabel;
3268 if (D->isGnuLocal()) {
3269 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3270 if (!BeginLocOrErr)
3271 return BeginLocOrErr.takeError();
3272 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3273 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3274 return ToLabel;
3275
3276 } else {
3277 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3278 Name.getAsIdentifierInfo()))
3279 return ToLabel;
3280
3281 }
3282
3283 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3284 if (!ToStmtOrErr)
3285 return ToStmtOrErr.takeError();
3286
3287 ToLabel->setStmt(*ToStmtOrErr);
3288 ToLabel->setLexicalDeclContext(LexicalDC);
3289 LexicalDC->addDeclInternal(ToLabel);
3290 return ToLabel;
3291}
3292
3294 // Import the major distinguishing characteristics of this enum.
3295 DeclContext *DC, *LexicalDC;
3296 DeclarationName Name;
3297 SourceLocation Loc;
3298 NamedDecl *ToD;
3299 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3300 return std::move(Err);
3301 if (ToD)
3302 return ToD;
3303
3304 // Figure out what enum name we're looking for.
3305 unsigned IDNS = Decl::IDNS_Tag;
3306 DeclarationName SearchName = Name;
3307 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3308 if (Error Err = importInto(
3309 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3310 return std::move(Err);
3311 IDNS = Decl::IDNS_Ordinary;
3312 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3313 IDNS |= Decl::IDNS_Ordinary;
3314
3315 // We may already have an enum of the same name; try to find and match it.
3316 EnumDecl *PrevDecl = nullptr;
3317 if (!DC->isFunctionOrMethod()) {
3318 SmallVector<NamedDecl *, 4> ConflictingDecls;
3319 auto FoundDecls =
3320 Importer.findDeclsInToCtx(DC, SearchName);
3321 for (auto *FoundDecl : FoundDecls) {
3322 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3323 continue;
3324
3325 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3326 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3327 FoundDecl = Tag->getDecl();
3328 }
3329
3330 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3331 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3332 continue;
3333 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3334 EnumDecl *FoundDef = FoundEnum->getDefinition();
3335 if (D->isThisDeclarationADefinition() && FoundDef)
3336 return Importer.MapImported(D, FoundDef);
3337 PrevDecl = FoundEnum->getMostRecentDecl();
3338 break;
3339 }
3340 ConflictingDecls.push_back(FoundDecl);
3341 }
3342 }
3343
3344 // In case of unnamed enums, we try to find an existing similar one, if none
3345 // was found, perform the import always.
3346 // Structural in-equivalence is not detected in this way here, but it may
3347 // be found when the parent decl is imported (if the enum is part of a
3348 // class). To make this totally exact a more difficult solution is needed.
3349 if (SearchName && !ConflictingDecls.empty()) {
3350 ExpectedName NameOrErr = Importer.HandleNameConflict(
3351 SearchName, DC, IDNS, ConflictingDecls.data(),
3352 ConflictingDecls.size());
3353 if (NameOrErr)
3354 Name = NameOrErr.get();
3355 else
3356 return NameOrErr.takeError();
3357 }
3358 }
3359
3360 Error Err = Error::success();
3361 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3362 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3363 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3364 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3365 if (Err)
3366 return std::move(Err);
3367
3368 // Create the enum declaration.
3369 EnumDecl *D2;
3370 if (GetImportedOrCreateDecl(
3371 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3372 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3373 D->isScopedUsingClassTag(), D->isFixed()))
3374 return D2;
3375
3376 D2->setQualifierInfo(ToQualifierLoc);
3377 D2->setIntegerType(ToIntegerType);
3378 D2->setBraceRange(ToBraceRange);
3379 D2->setAccess(D->getAccess());
3380 D2->setLexicalDeclContext(LexicalDC);
3381 addDeclToContexts(D, D2);
3382
3384 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3385 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3386 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3387 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3388 else
3389 return ToInstOrErr.takeError();
3390 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3392 else
3393 return POIOrErr.takeError();
3394 }
3395
3396 // Import the definition
3397 if (D->isCompleteDefinition())
3398 if (Error Err = ImportDefinition(D, D2))
3399 return std::move(Err);
3400
3401 return D2;
3402}
3403
3405 bool IsFriendTemplate = false;
3406 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3407 IsFriendTemplate =
3408 DCXX->getDescribedClassTemplate() &&
3409 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3411 }
3412
3413 // Import the major distinguishing characteristics of this record.
3414 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3415 DeclarationName Name;
3416 SourceLocation Loc;
3417 NamedDecl *ToD = nullptr;
3418 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3419 return std::move(Err);
3420 if (ToD)
3421 return ToD;
3422
3423 // Figure out what structure name we're looking for.
3424 unsigned IDNS = Decl::IDNS_Tag;
3425 DeclarationName SearchName = Name;
3426 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3427 if (Error Err = importInto(
3428 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3429 return std::move(Err);
3430 IDNS = Decl::IDNS_Ordinary;
3431 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3433
3434 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3435 : DC->isDependentContext();
3436 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3437
3438 // We may already have a record of the same name; try to find and match it.
3439 RecordDecl *PrevDecl = nullptr;
3440 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3441 SmallVector<NamedDecl *, 4> ConflictingDecls;
3442 auto FoundDecls =
3443 Importer.findDeclsInToCtx(DC, SearchName);
3444 if (!FoundDecls.empty()) {
3445 // We're going to have to compare D against potentially conflicting Decls,
3446 // so complete it.
3449 }
3450
3451 for (auto *FoundDecl : FoundDecls) {
3452 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3453 continue;
3454
3455 Decl *Found = FoundDecl;
3456 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3457 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3458 Found = Tag->getDecl();
3459 }
3460
3461 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3462 // Do not emit false positive diagnostic in case of unnamed
3463 // struct/union and in case of anonymous structs. Would be false
3464 // because there may be several anonymous/unnamed structs in a class.
3465 // E.g. these are both valid:
3466 // struct A { // unnamed structs
3467 // struct { struct A *next; } entry0;
3468 // struct { struct A *next; } entry1;
3469 // };
3470 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3471 if (!SearchName)
3472 if (!IsStructuralMatch(D, FoundRecord, false))
3473 continue;
3474
3475 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3476 continue;
3477
3478 if (IsStructuralMatch(D, FoundRecord)) {
3479 RecordDecl *FoundDef = FoundRecord->getDefinition();
3480 if (D->isThisDeclarationADefinition() && FoundDef) {
3481 // FIXME: Structural equivalence check should check for same
3482 // user-defined methods.
3483 Importer.MapImported(D, FoundDef);
3484 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3485 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3486 assert(FoundCXX && "Record type mismatch");
3487
3488 if (!Importer.isMinimalImport())
3489 // FoundDef may not have every implicit method that D has
3490 // because implicit methods are created only if they are used.
3491 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3492 return std::move(Err);
3493 }
3494 // FIXME: We can return FoundDef here.
3495 }
3496 PrevDecl = FoundRecord->getMostRecentDecl();
3497 break;
3498 }
3499 ConflictingDecls.push_back(FoundDecl);
3500 } // kind is RecordDecl
3501 } // for
3502
3503 if (!ConflictingDecls.empty() && SearchName) {
3504 ExpectedName NameOrErr = Importer.HandleNameConflict(
3505 SearchName, DC, IDNS, ConflictingDecls.data(),
3506 ConflictingDecls.size());
3507 if (NameOrErr)
3508 Name = NameOrErr.get();
3509 else
3510 return NameOrErr.takeError();
3511 }
3512 }
3513
3514 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3515 if (!BeginLocOrErr)
3516 return BeginLocOrErr.takeError();
3517
3518 // Create the record declaration.
3519 RecordDecl *D2 = nullptr;
3520 CXXRecordDecl *D2CXX = nullptr;
3521 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3522 if (DCXX->isLambda()) {
3523 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3524 if (!TInfoOrErr)
3525 return TInfoOrErr.takeError();
3526 if (GetImportedOrCreateSpecialDecl(
3527 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3528 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3529 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3530 return D2CXX;
3531 Decl *ContextDecl = DCXX->getLambdaContextDecl();
3532 ExpectedDecl CDeclOrErr = import(ContextDecl);
3533 if (!CDeclOrErr)
3534 return CDeclOrErr.takeError();
3535 if (ContextDecl != nullptr) {
3536 D2CXX->setLambdaContextDecl(*CDeclOrErr);
3537 }
3538 D2CXX->setLambdaNumbering(DCXX->getLambdaNumbering());
3539 } else {
3540 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3541 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3542 Name.getAsIdentifierInfo(),
3543 cast_or_null<CXXRecordDecl>(PrevDecl)))
3544 return D2CXX;
3545 }
3546
3547 D2 = D2CXX;
3548 D2->setAccess(D->getAccess());
3549 D2->setLexicalDeclContext(LexicalDC);
3550 addDeclToContexts(D, D2);
3551
3552 if (ClassTemplateDecl *FromDescribed =
3553 DCXX->getDescribedClassTemplate()) {
3554 ClassTemplateDecl *ToDescribed;
3555 if (Error Err = importInto(ToDescribed, FromDescribed))
3556 return std::move(Err);
3557 D2CXX->setDescribedClassTemplate(ToDescribed);
3558 } else if (MemberSpecializationInfo *MemberInfo =
3559 DCXX->getMemberSpecializationInfo()) {
3561 MemberInfo->getTemplateSpecializationKind();
3563
3564 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3565 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3566 else
3567 return ToInstOrErr.takeError();
3568
3569 if (ExpectedSLoc POIOrErr =
3570 import(MemberInfo->getPointOfInstantiation()))
3572 *POIOrErr);
3573 else
3574 return POIOrErr.takeError();
3575 }
3576
3577 } else {
3578 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3579 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3580 Name.getAsIdentifierInfo(), PrevDecl))
3581 return D2;
3582 D2->setLexicalDeclContext(LexicalDC);
3583 addDeclToContexts(D, D2);
3584 }
3585
3586 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3587 D2->setBraceRange(*BraceRangeOrErr);
3588 else
3589 return BraceRangeOrErr.takeError();
3590 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3591 D2->setQualifierInfo(*QualifierLocOrErr);
3592 else
3593 return QualifierLocOrErr.takeError();
3594
3595 if (D->isAnonymousStructOrUnion())
3596 D2->setAnonymousStructOrUnion(true);
3597
3598 if (D->isCompleteDefinition())
3599 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3600 return std::move(Err);
3601
3602 return D2;
3603}
3604
3606 // Import the major distinguishing characteristics of this enumerator.
3607 DeclContext *DC, *LexicalDC;
3608 DeclarationName Name;
3609 SourceLocation Loc;
3610 NamedDecl *ToD;
3611 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3612 return std::move(Err);
3613 if (ToD)
3614 return ToD;
3615
3616 // Determine whether there are any other declarations with the same name and
3617 // in the same context.
3618 if (!LexicalDC->isFunctionOrMethod()) {
3619 SmallVector<NamedDecl *, 4> ConflictingDecls;
3620 unsigned IDNS = Decl::IDNS_Ordinary;
3621 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3622 for (auto *FoundDecl : FoundDecls) {
3623 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3624 continue;
3625
3626 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3627 if (IsStructuralMatch(D, FoundEnumConstant))
3628 return Importer.MapImported(D, FoundEnumConstant);
3629 ConflictingDecls.push_back(FoundDecl);
3630 }
3631 }
3632
3633 if (!ConflictingDecls.empty()) {
3634 ExpectedName NameOrErr = Importer.HandleNameConflict(
3635 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3636 if (NameOrErr)
3637 Name = NameOrErr.get();
3638 else
3639 return NameOrErr.takeError();
3640 }
3641 }
3642
3643 ExpectedType TypeOrErr = import(D->getType());
3644 if (!TypeOrErr)
3645 return TypeOrErr.takeError();
3646
3647 ExpectedExpr InitOrErr = import(D->getInitExpr());
3648 if (!InitOrErr)
3649 return InitOrErr.takeError();
3650
3651 EnumConstantDecl *ToEnumerator;
3652 if (GetImportedOrCreateDecl(
3653 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3654 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3655 return ToEnumerator;
3656
3657 ToEnumerator->setAccess(D->getAccess());
3658 ToEnumerator->setLexicalDeclContext(LexicalDC);
3659 LexicalDC->addDeclInternal(ToEnumerator);
3660 return ToEnumerator;
3661}
3662
3663template <typename DeclTy>
3665 DeclTy *ToD) {
3667 FromD->getTemplateParameterLists();
3668 if (FromTPLs.empty())
3669 return Error::success();
3670 SmallVector<TemplateParameterList *, 2> ToTPLists(FromTPLs.size());
3671 for (unsigned int I = 0; I < FromTPLs.size(); ++I)
3672 if (Expected<TemplateParameterList *> ToTPListOrErr = import(FromTPLs[I]))
3673 ToTPLists[I] = *ToTPListOrErr;
3674 else
3675 return ToTPListOrErr.takeError();
3676 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3677 return Error::success();
3678}
3679
3681 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3682 switch (FromFD->getTemplatedKind()) {
3685 return Error::success();
3686
3688 if (Expected<FunctionDecl *> InstFDOrErr =
3689 import(FromFD->getInstantiatedFromDecl()))
3690 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3691 return Error::success();
3694
3695 if (Expected<FunctionDecl *> InstFDOrErr =
3696 import(FromFD->getInstantiatedFromMemberFunction()))
3697 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3698 else
3699 return InstFDOrErr.takeError();
3700
3701 if (ExpectedSLoc POIOrErr = import(
3704 else
3705 return POIOrErr.takeError();
3706
3707 return Error::success();
3708 }
3709
3711 auto FunctionAndArgsOrErr =
3713 if (!FunctionAndArgsOrErr)
3714 return FunctionAndArgsOrErr.takeError();
3715
3717 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3718
3719 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3720 TemplateArgumentListInfo ToTAInfo;
3721 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3722 if (FromTAArgsAsWritten)
3724 *FromTAArgsAsWritten, ToTAInfo))
3725 return Err;
3726
3727 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3728 if (!POIOrErr)
3729 return POIOrErr.takeError();
3730
3731 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3732 return Err;
3733
3734 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3735 ToFD->setFunctionTemplateSpecialization(
3736 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /*InsertToken=*/{}, TSK,
3737 FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3738 return Error::success();
3739 }
3740
3742 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3743 UnresolvedSet<8> Candidates;
3744 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3745 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3746 Candidates.addDecl(*ToFTDOrErr);
3747 else
3748 return ToFTDOrErr.takeError();
3749 }
3750
3751 // Import TemplateArgumentListInfo.
3752 TemplateArgumentListInfo ToTAInfo;
3753 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3754 if (FromTAArgsAsWritten)
3755 if (Error Err =
3756 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3757 return Err;
3758
3760 Importer.getToContext(), Candidates,
3761 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3762 return Error::success();
3763 }
3764 }
3765 llvm_unreachable("All cases should be covered!");
3766}
3767
3770 auto FunctionAndArgsOrErr =
3772 if (!FunctionAndArgsOrErr)
3773 return FunctionAndArgsOrErr.takeError();
3774
3776 TemplateArgsTy ToTemplArgs;
3777 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3778 llvm::FoldingSetInsertToken InsertToken;
3779 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertToken);
3780 return FoundSpec;
3781}
3782
3784 FunctionDecl *ToFD) {
3785 if (Stmt *FromBody = FromFD->getBody()) {
3786 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3787 ToFD->setBody(*ToBodyOrErr);
3788 else
3789 return ToBodyOrErr.takeError();
3790 }
3791 return Error::success();
3792}
3793
3795ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3796 Expr *ExplicitExpr = ESpec.getExpr();
3797 if (ExplicitExpr)
3798 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3799 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3800}
3801
3803
3805 auto RedeclIt = Redecls.begin();
3806 // Import the first part of the decl chain. I.e. import all previous
3807 // declarations starting from the canonical decl.
3808 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3809 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3810 if (!ToRedeclOrErr)
3811 return ToRedeclOrErr.takeError();
3812 }
3813 assert(*RedeclIt == D);
3814
3815 // Import the major distinguishing characteristics of this function.
3816 DeclContext *DC, *LexicalDC;
3817 DeclarationName Name;
3818 SourceLocation Loc;
3819 NamedDecl *ToD;
3820 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3821 return std::move(Err);
3822 if (ToD)
3823 return ToD;
3824
3825 FunctionDecl *FoundByLookup = nullptr;
3827
3828 // If this is a function template specialization, then try to find the same
3829 // existing specialization in the "to" context. The lookup below will not
3830 // find any specialization, but would find the primary template; thus, we
3831 // have to skip normal lookup in case of specializations.
3832 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3833 if (D->getTemplatedKind() ==
3835 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3836 if (!FoundFunctionOrErr)
3837 return FoundFunctionOrErr.takeError();
3838 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3839 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3840 return Def;
3841 FoundByLookup = FoundFunction;
3842 }
3843 }
3844 // Try to find a function in our own ("to") context with the same name, same
3845 // type, and in the same context as the function we're importing.
3846 else if (!LexicalDC->isFunctionOrMethod()) {
3847 SmallVector<NamedDecl *, 4> ConflictingDecls;
3849 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3850 for (auto *FoundDecl : FoundDecls) {
3851 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3852 continue;
3853
3854 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3855 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3856 continue;
3857
3858 if (IsStructuralMatch(D, FoundFunction)) {
3859 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3860 return Def;
3861 FoundByLookup = FoundFunction;
3862 break;
3863 }
3864 // FIXME: Check for overloading more carefully, e.g., by boosting
3865 // Sema::IsOverload out to the AST library.
3866
3867 // Function overloading is okay in C++.
3868 if (Importer.getToContext().getLangOpts().CPlusPlus)
3869 continue;
3870
3871 // Complain about inconsistent function types.
3872 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3873 << Name << D->getType() << FoundFunction->getType();
3874 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3875 << FoundFunction->getType();
3876 ConflictingDecls.push_back(FoundDecl);
3877 }
3878 }
3879
3880 if (!ConflictingDecls.empty()) {
3881 ExpectedName NameOrErr = Importer.HandleNameConflict(
3882 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3883 if (NameOrErr)
3884 Name = NameOrErr.get();
3885 else
3886 return NameOrErr.takeError();
3887 }
3888 }
3889
3890 // We do not allow more than one in-class declaration of a function. This is
3891 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3892 // assumes there is only one in-class declaration. Building a redecl
3893 // chain would result in more than one in-class declaration for
3894 // overrides (even if they are part of the same redecl chain inside the
3895 // derived class.)
3896 if (FoundByLookup) {
3897 if (isa<CXXMethodDecl>(FoundByLookup)) {
3898 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3899 if (!D->doesThisDeclarationHaveABody()) {
3900 if (FunctionTemplateDecl *DescribedD =
3902 // Handle a "templated" function together with its described
3903 // template. This avoids need for a similar check at import of the
3904 // described template.
3905 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3906 "Templated function mapped to non-templated?");
3907 Importer.MapImported(DescribedD,
3908 FoundByLookup->getDescribedFunctionTemplate());
3909 }
3910 return Importer.MapImported(D, FoundByLookup);
3911 } else {
3912 // Let's continue and build up the redecl chain in this case.
3913 // FIXME Merge the functions into one decl.
3914 }
3915 }
3916 }
3917 }
3918
3919 DeclarationNameInfo NameInfo(Name, Loc);
3920 // Import additional name location/type info.
3921 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3922 return std::move(Err);
3923
3924 QualType FromTy = D->getType();
3925 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3926 // Set to true if we do not import the type of the function as is. There are
3927 // cases when the original type would result in an infinite recursion during
3928 // the import. To avoid an infinite recursion when importing, we create the
3929 // FunctionDecl with a simplified function type and update it only after the
3930 // relevant AST nodes are already imported.
3931 // The type is related to TypeSourceInfo (it references the type), so we must
3932 // do the same with TypeSourceInfo.
3933 bool UsedDifferentProtoType = false;
3934 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3935 QualType FromReturnTy = FromFPT->getReturnType();
3936 // Functions with auto return type may define a struct inside their body
3937 // and the return type could refer to that struct.
3938 // E.g.: auto foo() { struct X{}; return X(); }
3939 // There are many more cases when types inside the function declaration
3940 // can appear in the return type, like types declared as typenames from
3941 // template params.
3942 // All such cases are tracked in FindFunctionDeclImportCycle.
3943 if (Importer.FindFunctionDeclImportCycle.isCycle(D)) {
3944 FromReturnTy = Importer.getFromContext().VoidTy;
3945 UsedDifferentProtoType = true;
3946 }
3947 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3948 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3949 // FunctionDecl that we are importing the FunctionProtoType for.
3950 // To avoid an infinite recursion when importing, create the FunctionDecl
3951 // with a simplified function type.
3952 if (FromEPI.ExceptionSpec.SourceDecl ||
3953 FromEPI.ExceptionSpec.SourceTemplate ||
3954 FromEPI.ExceptionSpec.NoexceptExpr) {
3956 FromEPI = DefaultEPI;
3957 UsedDifferentProtoType = true;
3958 }
3959 FromTy = Importer.getFromContext().getFunctionType(
3960 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3961 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3962 FromTy, D->getBeginLoc());
3963 }
3964
3965 Error Err = Error::success();
3966 auto ScopedReturnTypeDeclCycleDetector =
3967 Importer.FindFunctionDeclImportCycle.makeScopedCycleDetection(D);
3968 auto T = importChecked(Err, FromTy);
3969 auto TInfo = importChecked(Err, FromTSI);
3970 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3971 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3972 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3973 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3974 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
3975 TrailingRequiresClause.ConstraintExpr =
3976 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
3977 if (Err)
3978 return std::move(Err);
3979
3980 // Import the function parameters.
3982 for (auto *P : D->parameters()) {
3983 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3984 Parameters.push_back(*ToPOrErr);
3985 else
3986 return ToPOrErr.takeError();
3987 }
3988
3989 // Create the imported function.
3990 FunctionDecl *ToFunction = nullptr;
3991 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3992 ExplicitSpecifier ESpec =
3993 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3994 if (Err)
3995 return std::move(Err);
3996 auto ToInheritedConstructor = InheritedConstructor();
3997 if (FromConstructor->isInheritingConstructor()) {
3998 Expected<InheritedConstructor> ImportedInheritedCtor =
3999 import(FromConstructor->getInheritedConstructor());
4000 if (!ImportedInheritedCtor)
4001 return ImportedInheritedCtor.takeError();
4002 ToInheritedConstructor = *ImportedInheritedCtor;
4003 }
4004 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4005 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4006 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4008 ToInheritedConstructor, TrailingRequiresClause))
4009 return ToFunction;
4010 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4011
4012 Error Err = Error::success();
4013 auto ToOperatorDelete = importChecked(
4014 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4015 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4016 if (Err)
4017 return std::move(Err);
4018
4019 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4020 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4021 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4023 TrailingRequiresClause))
4024 return ToFunction;
4025
4026 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4027
4028 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4029 } else if (CXXConversionDecl *FromConversion =
4030 dyn_cast<CXXConversionDecl>(D)) {
4031 ExplicitSpecifier ESpec =
4032 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4033 if (Err)
4034 return std::move(Err);
4035 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4036 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4037 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4038 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4039 SourceLocation(), TrailingRequiresClause))
4040 return ToFunction;
4041 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4042 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4043 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4044 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4045 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4046 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4047 return ToFunction;
4048 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4049 ExplicitSpecifier ESpec =
4050 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4051 CXXConstructorDecl *Ctor =
4052 importChecked(Err, Guide->getCorrespondingConstructor());
4053 const CXXDeductionGuideDecl *SourceDG =
4054 importChecked(Err, Guide->getSourceDeductionGuide());
4055 if (Err)
4056 return std::move(Err);
4057 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4058 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4059 NameInfo, T, TInfo, ToEndLoc, Ctor,
4060 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4061 SourceDG, Guide->getSourceDeductionGuideKind()))
4062 return ToFunction;
4063 } else {
4064 if (GetImportedOrCreateDecl(
4065 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4066 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4068 D->getConstexprKind(), TrailingRequiresClause))
4069 return ToFunction;
4070 }
4071
4072 // Connect the redecl chain.
4073 if (FoundByLookup) {
4074 auto *Recent = const_cast<FunctionDecl *>(
4075 FoundByLookup->getMostRecentDecl());
4076 ToFunction->setPreviousDecl(Recent);
4077 // FIXME Probably we should merge exception specifications. E.g. In the
4078 // "To" context the existing function may have exception specification with
4079 // noexcept-unevaluated, while the newly imported function may have an
4080 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4081 // decl and its redeclarations may be required.
4082 }
4083
4084 // We will import DefaultedOrDeletedInfo later.
4085
4086 ToFunction->setQualifierInfo(ToQualifierLoc);
4087 ToFunction->setAccess(D->getAccess());
4088 ToFunction->setLexicalDeclContext(LexicalDC);
4089 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4090 ToFunction->setTrivial(D->isTrivial());
4091 ToFunction->setIsPureVirtual(D->isPureVirtual());
4092 ToFunction->setDefaulted(D->isDefaulted());
4094 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4100 ToFunction->setRangeEnd(ToEndLoc);
4101 ToFunction->setDefaultLoc(ToDefaultLoc);
4102
4103 if (auto *Info = D->getDefaultedOrDeletedInfo()) {
4104 StringLiteral *Msg = nullptr;
4105 if (StringLiteral *M = Info->getDeletedMessage()) {
4106 auto Imported = import(M);
4107 if (!Imported)
4108 return Imported.takeError();
4109 Msg = *Imported;
4110 }
4111
4113 for (DeclAccessPair P : Info->getUnqualifiedLookups()) {
4114 auto Imported = import(P.getDecl());
4115 if (!Imported)
4116 return Imported.takeError();
4117 Lookups.push_back(
4119 }
4120
4121 ToFunction->setDefaultedOrDeletedInfo(
4123 Importer.getToContext(), Lookups, Info->getFPFeatures(), Msg));
4124 }
4125
4126 // Set the parameters.
4127 for (auto *Param : Parameters) {
4128 Param->setOwningFunction(ToFunction);
4129 ToFunction->addDeclInternal(Param);
4130 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4131 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4132 }
4133 ToFunction->setParams(Parameters);
4134
4135 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4136 // params it refers to.
4137 if (TInfo) {
4138 if (auto ProtoLoc =
4139 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4140 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4141 ProtoLoc.setParam(I, Parameters[I]);
4142 }
4143 }
4144
4145 // Import the describing template function, if any.
4146 if (FromFT) {
4147 auto ToFTOrErr = import(FromFT);
4148 if (!ToFTOrErr)
4149 return ToFTOrErr.takeError();
4150 }
4151
4152 // Import Ctor initializers.
4153 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4154 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4155 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4156 // Import first, then allocate memory and copy if there was no error.
4157 if (Error Err = ImportContainerChecked(
4158 FromConstructor->inits(), CtorInitializers))
4159 return std::move(Err);
4160 auto **Memory =
4161 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4162 llvm::copy(CtorInitializers, Memory);
4163 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4164 ToCtor->setCtorInitializers(Memory);
4165 ToCtor->setNumCtorInitializers(NumInitializers);
4166 }
4167 }
4168
4169 // If it is a template, import all related things.
4170 if (Error Err = ImportTemplateInformation(D, ToFunction))
4171 return std::move(Err);
4172
4173 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4175 FromCXXMethod))
4176 return std::move(Err);
4177
4179 Error Err = ImportFunctionDeclBody(D, ToFunction);
4180
4181 if (Err)
4182 return std::move(Err);
4183 }
4184
4185 // Import and set the original type in case we used another type.
4186 if (UsedDifferentProtoType) {
4187 if (ExpectedType TyOrErr = import(D->getType()))
4188 ToFunction->setType(*TyOrErr);
4189 else
4190 return TyOrErr.takeError();
4191 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4192 ToFunction->setTypeSourceInfo(*TSIOrErr);
4193 else
4194 return TSIOrErr.takeError();
4195 }
4196
4197 // FIXME: Other bits to merge?
4198
4199 addDeclToContexts(D, ToFunction);
4200
4201 // Import the rest of the chain. I.e. import all subsequent declarations.
4202 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4203 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4204 if (!ToRedeclOrErr)
4205 return ToRedeclOrErr.takeError();
4206 }
4207
4208 return ToFunction;
4209}
4210
4214
4218
4222
4226
4231
4233 // Import the major distinguishing characteristics of a variable.
4234 DeclContext *DC, *LexicalDC;
4235 DeclarationName Name;
4236 SourceLocation Loc;
4237 NamedDecl *ToD;
4238 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4239 return std::move(Err);
4240 if (ToD)
4241 return ToD;
4242
4243 // Determine whether we've already imported this field.
4244 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4245 for (auto *FoundDecl : FoundDecls) {
4246 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4247 // For anonymous fields, match up by index.
4248 if (!Name &&
4250 ASTImporter::getFieldIndex(FoundField))
4251 continue;
4252
4253 if (Importer.IsStructurallyEquivalent(D->getType(),
4254 FoundField->getType())) {
4255 Importer.MapImported(D, FoundField);
4256 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4257 // initializer of a FieldDecl might not had been instantiated in the
4258 // "To" context. However, the "From" context might instantiated that,
4259 // thus we have to merge that.
4260 // Note: `hasInClassInitializer()` is not the same as non-null
4261 // `getInClassInitializer()` value.
4262 if (Expr *FromInitializer = D->getInClassInitializer()) {
4263 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4264 // Import of the FromInitializer may result in the setting of
4265 // InClassInitializer. If not, set it here.
4266 assert(FoundField->hasInClassInitializer() &&
4267 "Field should have an in-class initializer if it has an "
4268 "expression for it.");
4269 if (!FoundField->getInClassInitializer())
4270 FoundField->setInClassInitializer(*ToInitializerOrErr);
4271 } else {
4272 return ToInitializerOrErr.takeError();
4273 }
4274 }
4275 return FoundField;
4276 }
4277
4278 // FIXME: Why is this case not handled with calling HandleNameConflict?
4279 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4280 << Name << D->getType() << FoundField->getType();
4281 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4282 << FoundField->getType();
4283
4284 return make_error<ASTImportError>(ASTImportError::NameConflict);
4285 }
4286 }
4287
4288 Error Err = Error::success();
4289 auto ToType = importChecked(Err, D->getType());
4290 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4291 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4292 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4293 if (Err)
4294 return std::move(Err);
4295 const Type *ToCapturedVLAType = nullptr;
4296 if (Error Err = Importer.importInto(
4297 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4298 return std::move(Err);
4299
4300 FieldDecl *ToField;
4301 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4302 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4303 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4304 D->getInClassInitStyle()))
4305 return ToField;
4306
4307 ToField->setAccess(D->getAccess());
4308 ToField->setLexicalDeclContext(LexicalDC);
4309 ToField->setImplicit(D->isImplicit());
4310 if (ToCapturedVLAType)
4311 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4312 LexicalDC->addDeclInternal(ToField);
4313 // Import initializer only after the field was created, it may have recursive
4314 // reference to the field.
4315 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4316 if (Err)
4317 return std::move(Err);
4318 if (ToInitializer) {
4319 auto *AlreadyImported = ToField->getInClassInitializer();
4320 if (AlreadyImported)
4321 assert(ToInitializer == AlreadyImported &&
4322 "Duplicate import of in-class initializer.");
4323 else
4324 ToField->setInClassInitializer(ToInitializer);
4325 }
4326
4327 return ToField;
4328}
4329
4331 // Import the major distinguishing characteristics of a variable.
4332 DeclContext *DC, *LexicalDC;
4333 DeclarationName Name;
4334 SourceLocation Loc;
4335 NamedDecl *ToD;
4336 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4337 return std::move(Err);
4338 if (ToD)
4339 return ToD;
4340
4341 // Determine whether we've already imported this field.
4342 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4343 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4344 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4345 // For anonymous indirect fields, match up by index.
4346 if (!Name &&
4348 ASTImporter::getFieldIndex(FoundField))
4349 continue;
4350
4351 if (Importer.IsStructurallyEquivalent(D->getType(),
4352 FoundField->getType(),
4353 !Name.isEmpty())) {
4354 Importer.MapImported(D, FoundField);
4355 return FoundField;
4356 }
4357
4358 // If there are more anonymous fields to check, continue.
4359 if (!Name && I < N-1)
4360 continue;
4361
4362 // FIXME: Why is this case not handled with calling HandleNameConflict?
4363 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4364 << Name << D->getType() << FoundField->getType();
4365 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4366 << FoundField->getType();
4367
4368 return make_error<ASTImportError>(ASTImportError::NameConflict);
4369 }
4370 }
4371
4372 // Import the type.
4373 auto TypeOrErr = import(D->getType());
4374 if (!TypeOrErr)
4375 return TypeOrErr.takeError();
4376
4377 auto **NamedChain =
4378 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4379
4380 unsigned i = 0;
4381 for (auto *PI : D->chain())
4382 if (Expected<NamedDecl *> ToD = import(PI))
4383 NamedChain[i++] = *ToD;
4384 else
4385 return ToD.takeError();
4386
4387 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4388 IndirectFieldDecl *ToIndirectField;
4389 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4390 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4391 // FIXME here we leak `NamedChain` which is allocated before
4392 return ToIndirectField;
4393
4394 ToIndirectField->setAccess(D->getAccess());
4395 ToIndirectField->setLexicalDeclContext(LexicalDC);
4396 LexicalDC->addDeclInternal(ToIndirectField);
4397 return ToIndirectField;
4398}
4399
4400/// Used as return type of getFriendCountAndPosition.
4402 /// Number of similar looking friends.
4403 unsigned int TotalCount;
4404 /// Index of the specific FriendDecl.
4405 unsigned int IndexOfDecl;
4406};
4407
4408static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4409 FriendDecl *FD2) {
4410 if (FD1->getKind() != FD2->getKind())
4411 return false;
4412
4413 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4415 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4416 FD2->getASTContext(), NonEquivalentDecls,
4418 /*StrictTypeSpelling=*/false, /*Complain=*/false);
4419 return Ctx.IsEquivalent(FD1, FD2);
4420}
4421
4423 FriendDecl *FD) {
4424 unsigned int FriendCount = 0;
4425 UnsignedOrNone FriendPosition = std::nullopt;
4426 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4427
4428 for (FriendDecl *FoundFriend : RD->friends()) {
4429 if (FoundFriend == FD) {
4430 FriendPosition = FriendCount;
4431 ++FriendCount;
4432 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4433 ++FriendCount;
4434 }
4435 }
4436
4437 assert(FriendPosition && "Friend decl not found in own parent.");
4438 return {FriendCount, *FriendPosition};
4439}
4440
4441Expected<FriendDecl::FriendUnion>
4442ASTNodeImporter::importFriendUnion(FriendDecl *D) {
4443 if (NamedDecl *FriendD = D->getFriendDecl()) {
4444 NamedDecl *ToFriendD;
4445 if (Error Err = importInto(ToFriendD, FriendD))
4446 return std::move(Err);
4447
4448 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4449 !FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))
4450 ToFriendD->setObjectOfFriendDecl(false);
4451
4452 return ToFriendD;
4453 }
4454
4455 // The friend is a type, not a decl.
4456 auto TSIOrErr = import(D->getFriendType());
4457 if (TSIOrErr)
4458 return *TSIOrErr;
4459 return TSIOrErr.takeError();
4460}
4461
4463 // Import the major distinguishing characteristics of a declaration.
4464 DeclContext *DC, *LexicalDC;
4465 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4466 return std::move(Err);
4467
4468 // Determine whether we've already imported this decl.
4469 // FriendDecl is not a NamedDecl so we cannot use lookup.
4470 // We try to maintain order and count of redundant friend declarations.
4471 const auto *RD = cast<CXXRecordDecl>(DC);
4472 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4473 for (FriendDecl *ImportedFriend : RD->friends())
4474 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4475 ImportedEquivalentFriends.push_back(ImportedFriend);
4476
4477 FriendCountAndPosition CountAndPosition =
4478 getFriendCountAndPosition(Importer, D);
4479
4480 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4481 "Class with non-matching friends is imported, ODR check wrong?");
4482 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4483 return Importer.MapImported(
4484 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4485
4486 // Not found. Create it.
4487 // The declarations will be put into order later by ImportDeclContext.
4488 auto ToFUOrErr = importFriendUnion(D);
4489 if (!ToFUOrErr)
4490 return ToFUOrErr.takeError();
4491 FriendDecl::FriendUnion ToFU = *ToFUOrErr;
4492
4493 auto LocationOrErr = import(D->getLocation());
4494 if (!LocationOrErr)
4495 return LocationOrErr.takeError();
4496 auto FriendLocOrErr = import(D->getFriendLoc());
4497 if (!FriendLocOrErr)
4498 return FriendLocOrErr.takeError();
4499 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4500 if (!EllipsisLocOrErr)
4501 return EllipsisLocOrErr.takeError();
4502
4503 FriendDecl *FrD;
4504 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4505 *LocationOrErr, ToFU, *FriendLocOrErr,
4506 *EllipsisLocOrErr))
4507 return FrD;
4508
4509 FrD->setAccess(D->getAccess());
4510 FrD->setLexicalDeclContext(LexicalDC);
4511 LexicalDC->addDeclInternal(FrD);
4512 return FrD;
4513}
4514
4516 DeclContext *DC, *LexicalDC;
4517 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4518 return std::move(Err);
4519
4520 const auto *RD = cast<CXXRecordDecl>(DC);
4521 SmallVector<FriendTemplateDecl *, 2> ImportedEquivalentFriends;
4522 for (FriendDecl *ImportedFriend : RD->friends()) {
4523 auto *ImportedFriendTemplate = dyn_cast<FriendTemplateDecl>(ImportedFriend);
4524 if (ImportedFriendTemplate &&
4525 IsEquivalentFriend(Importer, D, ImportedFriendTemplate))
4526 ImportedEquivalentFriends.push_back(ImportedFriendTemplate);
4527 }
4528
4529 FriendCountAndPosition CountAndPosition =
4530 getFriendCountAndPosition(Importer, D);
4531 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4532 "Class with non-matching friends is imported, ODR check wrong?");
4533
4534 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4535 return Importer.MapImported(
4536 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4537
4539 if (D->getFriendKind() !=
4541 auto ToFUOrErr = importFriendUnion(D);
4542 if (!ToFUOrErr)
4543 return ToFUOrErr.takeError();
4544 ToFU = *ToFUOrErr;
4545 }
4546
4547 TemplateName ToTemplate;
4548 const TemplateName FromTemplate = D->getFriendTemplateName();
4549 if (!FromTemplate.isNull()) {
4550 if (Error Err = importInto(ToTemplate, FromTemplate))
4551 return std::move(Err);
4552 }
4553
4555 SmallVector<TemplateParameterList *, 1> ToTPLs(FromTPLs.size());
4556 if (Error Err = ImportContainerChecked(FromTPLs, ToTPLs))
4557 return std::move(Err);
4558
4559 auto LocationOrErr = import(D->getLocation());
4560 if (!LocationOrErr)
4561 return LocationOrErr.takeError();
4562
4563 auto FriendLocOrErr = import(D->getFriendLoc());
4564 if (!FriendLocOrErr)
4565 return FriendLocOrErr.takeError();
4566
4567 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4568 if (!EllipsisLocOrErr)
4569 return EllipsisLocOrErr.takeError();
4570
4571 FriendTemplateDecl *FTD;
4572 if (GetImportedOrCreateDecl(FTD, D, Importer.getToContext(), DC,
4573 *LocationOrErr, ToFU, *FriendLocOrErr, ToTPLs,
4574 *EllipsisLocOrErr, ToTemplate))
4575 return FTD;
4576
4577 FTD->setAccess(D->getAccess());
4578 FTD->setLexicalDeclContext(LexicalDC);
4579 LexicalDC->addDeclInternal(FTD);
4580 return FTD;
4581}
4582
4584 // Import the major distinguishing characteristics of an ivar.
4585 DeclContext *DC, *LexicalDC;
4586 DeclarationName Name;
4587 SourceLocation Loc;
4588 NamedDecl *ToD;
4589 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4590 return std::move(Err);
4591 if (ToD)
4592 return ToD;
4593
4594 // Determine whether we've already imported this ivar
4595 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4596 for (auto *FoundDecl : FoundDecls) {
4597 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4598 if (Importer.IsStructurallyEquivalent(D->getType(),
4599 FoundIvar->getType())) {
4600 Importer.MapImported(D, FoundIvar);
4601 return FoundIvar;
4602 }
4603
4604 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4605 << Name << D->getType() << FoundIvar->getType();
4606 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4607 << FoundIvar->getType();
4608
4609 return make_error<ASTImportError>(ASTImportError::NameConflict);
4610 }
4611 }
4612
4613 Error Err = Error::success();
4614 auto ToType = importChecked(Err, D->getType());
4615 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4616 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4617 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4618 if (Err)
4619 return std::move(Err);
4620
4621 ObjCIvarDecl *ToIvar;
4622 if (GetImportedOrCreateDecl(
4623 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4624 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4625 ToType, ToTypeSourceInfo,
4626 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4627 return ToIvar;
4628
4629 ToIvar->setLexicalDeclContext(LexicalDC);
4630 LexicalDC->addDeclInternal(ToIvar);
4631 return ToIvar;
4632}
4633
4635
4637 auto RedeclIt = Redecls.begin();
4638 // Import the first part of the decl chain. I.e. import all previous
4639 // declarations starting from the canonical decl.
4640 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4641 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4642 if (!RedeclOrErr)
4643 return RedeclOrErr.takeError();
4644 }
4645 assert(*RedeclIt == D);
4646
4647 // Import the major distinguishing characteristics of a variable.
4648 DeclContext *DC, *LexicalDC;
4649 DeclarationName Name;
4650 SourceLocation Loc;
4651 NamedDecl *ToD;
4652 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4653 return std::move(Err);
4654 if (ToD)
4655 return ToD;
4656
4657 // Try to find a variable in our own ("to") context with the same name and
4658 // in the same context as the variable we're importing.
4659 VarDecl *FoundByLookup = nullptr;
4660 if (D->isFileVarDecl()) {
4661 SmallVector<NamedDecl *, 4> ConflictingDecls;
4662 unsigned IDNS = Decl::IDNS_Ordinary;
4663 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4664 for (auto *FoundDecl : FoundDecls) {
4665 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4666 continue;
4667
4668 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4669 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4670 continue;
4671 if (Importer.IsStructurallyEquivalent(D->getType(),
4672 FoundVar->getType())) {
4673
4674 // The VarDecl in the "From" context has a definition, but in the
4675 // "To" context we already have a definition.
4676 VarDecl *FoundDef = FoundVar->getDefinition();
4677 if (D->isThisDeclarationADefinition() && FoundDef)
4678 // FIXME Check for ODR error if the two definitions have
4679 // different initializers?
4680 return Importer.MapImported(D, FoundDef);
4681
4682 // The VarDecl in the "From" context has an initializer, but in the
4683 // "To" context we already have an initializer.
4684 const VarDecl *FoundDInit = nullptr;
4685 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4686 // FIXME Diagnose ODR error if the two initializers are different?
4687 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4688
4689 FoundByLookup = FoundVar;
4690 break;
4691 }
4692
4693 const ArrayType *FoundArray
4694 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4695 const ArrayType *TArray
4696 = Importer.getToContext().getAsArrayType(D->getType());
4697 if (FoundArray && TArray) {
4698 if (isa<IncompleteArrayType>(FoundArray) &&
4699 isa<ConstantArrayType>(TArray)) {
4700 // Import the type.
4701 if (auto TyOrErr = import(D->getType()))
4702 FoundVar->setType(*TyOrErr);
4703 else
4704 return TyOrErr.takeError();
4705
4706 FoundByLookup = FoundVar;
4707 break;
4708 } else if (isa<IncompleteArrayType>(TArray) &&
4709 isa<ConstantArrayType>(FoundArray)) {
4710 FoundByLookup = FoundVar;
4711 break;
4712 }
4713 }
4714
4715 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4716 << Name << D->getType() << FoundVar->getType();
4717 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4718 << FoundVar->getType();
4719 ConflictingDecls.push_back(FoundDecl);
4720 }
4721 }
4722
4723 if (!ConflictingDecls.empty()) {
4724 ExpectedName NameOrErr = Importer.HandleNameConflict(
4725 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4726 if (NameOrErr)
4727 Name = NameOrErr.get();
4728 else
4729 return NameOrErr.takeError();
4730 }
4731 }
4732
4733 Error Err = Error::success();
4734 auto ToType = importChecked(Err, D->getType());
4735 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4736 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4737 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4738 if (Err)
4739 return std::move(Err);
4740
4741 VarDecl *ToVar;
4742 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4743 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4744 if (Error Err =
4745 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4746 return std::move(Err);
4747 DecompositionDecl *ToDecomp;
4748 if (GetImportedOrCreateDecl(
4749 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4750 Loc, FromDecomp->getRSquareLoc(), ToType, ToTypeSourceInfo,
4752 return ToDecomp;
4753 ToVar = ToDecomp;
4754 } else {
4755 // Create the imported variable.
4756 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4757 ToInnerLocStart, Loc,
4758 Name.getAsIdentifierInfo(), ToType,
4759 ToTypeSourceInfo, D->getStorageClass()))
4760 return ToVar;
4761 }
4762
4763 ToVar->setTSCSpec(D->getTSCSpec());
4764 ToVar->setQualifierInfo(ToQualifierLoc);
4765 ToVar->setAccess(D->getAccess());
4766 ToVar->setLexicalDeclContext(LexicalDC);
4767 if (D->isInlineSpecified())
4768 ToVar->setInlineSpecified();
4769 if (D->isInline())
4770 ToVar->setImplicitlyInline();
4771
4772 if (FoundByLookup) {
4773 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4774 ToVar->setPreviousDecl(Recent);
4775 }
4776
4777 // Import the described template, if any.
4778 if (D->getDescribedVarTemplate()) {
4779 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4780 if (!ToVTOrErr)
4781 return ToVTOrErr.takeError();
4783 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4785 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4786 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4787 else
4788 return ToInstOrErr.takeError();
4789 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4791 else
4792 return POIOrErr.takeError();
4793 }
4794
4795 if (Error Err = ImportInitializer(D, ToVar))
4796 return std::move(Err);
4797
4798 if (D->isConstexpr())
4799 ToVar->setConstexpr(true);
4800
4801 addDeclToContexts(D, ToVar);
4802
4803 // Import the rest of the chain. I.e. import all subsequent declarations.
4804 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4805 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4806 if (!RedeclOrErr)
4807 return RedeclOrErr.takeError();
4808 }
4809
4810 return ToVar;
4811}
4812
4814 // Parameters are created in the translation unit's context, then moved
4815 // into the function declaration's context afterward.
4816 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4817
4818 Error Err = Error::success();
4819 auto ToDeclName = importChecked(Err, D->getDeclName());
4820 auto ToLocation = importChecked(Err, D->getLocation());
4821 auto ToType = importChecked(Err, D->getType());
4822 if (Err)
4823 return std::move(Err);
4824
4825 // Create the imported parameter.
4826 ImplicitParamDecl *ToParm = nullptr;
4827 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4828 ToLocation, ToDeclName.getAsIdentifierInfo(),
4829 ToType, D->getParameterKind()))
4830 return ToParm;
4831 return ToParm;
4832}
4833
4835 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4836
4837 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4838 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4839 else
4840 return LocOrErr.takeError();
4841
4843 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4844
4845 if (FromParam->hasUninstantiatedDefaultArg()) {
4846 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4847 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4848 else
4849 return ToDefArgOrErr.takeError();
4850 } else if (FromParam->hasUnparsedDefaultArg()) {
4851 ToParam->setUnparsedDefaultArg();
4852 } else if (FromParam->hasDefaultArg()) {
4853 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4854 ToParam->setDefaultArg(*ToDefArgOrErr);
4855 else
4856 return ToDefArgOrErr.takeError();
4857 }
4858
4859 return Error::success();
4860}
4861
4864 Error Err = Error::success();
4865 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4866 ConstructorUsingShadowDecl *ToShadow =
4867 importChecked(Err, From.getShadowDecl());
4868 if (Err)
4869 return std::move(Err);
4870 return InheritedConstructor(ToShadow, ToBaseCtor);
4871}
4872
4874 // Parameters are created in the translation unit's context, then moved
4875 // into the function declaration's context afterward.
4876 DeclContext *DC = Importer.getToContext().getTranslationUnitDecl();
4877
4878 Error Err = Error::success();
4879 auto ToDeclName = importChecked(Err, D->getDeclName());
4880 auto ToLocation = importChecked(Err, D->getLocation());
4881 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4882 auto ToType = importChecked(Err, D->getType());
4883 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4884 if (Err)
4885 return std::move(Err);
4886
4887 ParmVarDecl *ToParm;
4888 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4889 ToInnerLocStart, ToLocation,
4890 ToDeclName.getAsIdentifierInfo(), ToType,
4891 ToTypeSourceInfo, D->getStorageClass(),
4892 /*DefaultArg*/ nullptr))
4893 return ToParm;
4894
4895 // Set the default argument. It should be no problem if it was already done.
4896 // Do not import the default expression before GetImportedOrCreateDecl call
4897 // to avoid possible infinite import loop because circular dependency.
4898 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4899 return std::move(Err);
4900
4901 if (D->isObjCMethodParameter()) {
4904 } else {
4907 }
4908
4909 return ToParm;
4910}
4911
4913 // Import the major distinguishing characteristics of a method.
4914 DeclContext *DC, *LexicalDC;
4915 DeclarationName Name;
4916 SourceLocation Loc;
4917 NamedDecl *ToD;
4918 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4919 return std::move(Err);
4920 if (ToD)
4921 return ToD;
4922
4923 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4924 for (auto *FoundDecl : FoundDecls) {
4925 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4926 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4927 continue;
4928
4929 // Check return types.
4930 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4931 FoundMethod->getReturnType())) {
4932 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4933 << D->isInstanceMethod() << Name << D->getReturnType()
4934 << FoundMethod->getReturnType();
4935 Importer.ToDiag(FoundMethod->getLocation(),
4936 diag::note_odr_objc_method_here)
4937 << D->isInstanceMethod() << Name;
4938
4939 return make_error<ASTImportError>(ASTImportError::NameConflict);
4940 }
4941
4942 // Check the number of parameters.
4943 if (D->param_size() != FoundMethod->param_size()) {
4944 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4945 << D->isInstanceMethod() << Name
4946 << D->param_size() << FoundMethod->param_size();
4947 Importer.ToDiag(FoundMethod->getLocation(),
4948 diag::note_odr_objc_method_here)
4949 << D->isInstanceMethod() << Name;
4950
4951 return make_error<ASTImportError>(ASTImportError::NameConflict);
4952 }
4953
4954 // Check parameter types.
4956 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4957 P != PEnd; ++P, ++FoundP) {
4958 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4959 (*FoundP)->getType())) {
4960 Importer.FromDiag((*P)->getLocation(),
4961 diag::warn_odr_objc_method_param_type_inconsistent)
4962 << D->isInstanceMethod() << Name
4963 << (*P)->getType() << (*FoundP)->getType();
4964 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4965 << (*FoundP)->getType();
4966
4967 return make_error<ASTImportError>(ASTImportError::NameConflict);
4968 }
4969 }
4970
4971 // Check variadic/non-variadic.
4972 // Check the number of parameters.
4973 if (D->isVariadic() != FoundMethod->isVariadic()) {
4974 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4975 << D->isInstanceMethod() << Name;
4976 Importer.ToDiag(FoundMethod->getLocation(),
4977 diag::note_odr_objc_method_here)
4978 << D->isInstanceMethod() << Name;
4979
4980 return make_error<ASTImportError>(ASTImportError::NameConflict);
4981 }
4982
4983 // FIXME: Any other bits we need to merge?
4984 return Importer.MapImported(D, FoundMethod);
4985 }
4986 }
4987
4988 Error Err = Error::success();
4989 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4990 auto ToReturnType = importChecked(Err, D->getReturnType());
4991 auto ToReturnTypeSourceInfo =
4993 if (Err)
4994 return std::move(Err);
4995
4996 ObjCMethodDecl *ToMethod;
4997 if (GetImportedOrCreateDecl(
4998 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4999 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5003 return ToMethod;
5004
5005 // FIXME: When we decide to merge method definitions, we'll need to
5006 // deal with implicit parameters.
5007
5008 // Import the parameters
5010 for (auto *FromP : D->parameters()) {
5011 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5012 ToParams.push_back(*ToPOrErr);
5013 else
5014 return ToPOrErr.takeError();
5015 }
5016
5017 // Set the parameters.
5018 for (auto *ToParam : ToParams) {
5019 ToParam->setOwningFunction(ToMethod);
5020 ToMethod->addDeclInternal(ToParam);
5021 }
5022
5024 D->getSelectorLocs(FromSelLocs);
5025 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5026 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5027 return std::move(Err);
5028
5029 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5030
5031 ToMethod->setLexicalDeclContext(LexicalDC);
5032 LexicalDC->addDeclInternal(ToMethod);
5033
5034 // Implicit params are declared when Sema encounters the definition but this
5035 // never happens when the method is imported. Manually declare the implicit
5036 // params now that the MethodDecl knows its class interface.
5037 if (D->getSelfDecl())
5038 ToMethod->createImplicitParams(Importer.getToContext(),
5039 ToMethod->getClassInterface());
5040
5041 return ToMethod;
5042}
5043
5045 // Import the major distinguishing characteristics of a category.
5046 DeclContext *DC, *LexicalDC;
5047 DeclarationName Name;
5048 SourceLocation Loc;
5049 NamedDecl *ToD;
5050 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5051 return std::move(Err);
5052 if (ToD)
5053 return ToD;
5054
5055 Error Err = Error::success();
5056 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5057 auto ToLocation = importChecked(Err, D->getLocation());
5058 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5059 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5060 if (Err)
5061 return std::move(Err);
5062
5064 if (GetImportedOrCreateDecl(
5065 Result, D, Importer.getToContext(), DC, D->getVariance(),
5066 ToVarianceLoc, D->getIndex(),
5067 ToLocation, Name.getAsIdentifierInfo(),
5068 ToColonLoc, ToTypeSourceInfo))
5069 return Result;
5070
5071 // Only import 'ObjCTypeParamType' after the decl is created.
5072 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5073 if (Err)
5074 return std::move(Err);
5075 Result->setTypeForDecl(ToTypeForDecl);
5076 Result->setLexicalDeclContext(LexicalDC);
5077 return Result;
5078}
5079
5081 // Import the major distinguishing characteristics of a category.
5082 DeclContext *DC, *LexicalDC;
5083 DeclarationName Name;
5084 SourceLocation Loc;
5085 NamedDecl *ToD;
5086 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5087 return std::move(Err);
5088 if (ToD)
5089 return ToD;
5090
5091 ObjCInterfaceDecl *ToInterface;
5092 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5093 return std::move(Err);
5094
5095 // Determine if we've already encountered this category.
5096 ObjCCategoryDecl *MergeWithCategory
5097 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5098 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5099 if (!ToCategory) {
5100
5101 Error Err = Error::success();
5102 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5103 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5104 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5105 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5106 if (Err)
5107 return std::move(Err);
5108
5109 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5110 ToAtStartLoc, Loc,
5111 ToCategoryNameLoc,
5112 Name.getAsIdentifierInfo(), ToInterface,
5113 /*TypeParamList=*/nullptr,
5114 ToIvarLBraceLoc,
5115 ToIvarRBraceLoc))
5116 return ToCategory;
5117
5118 ToCategory->setLexicalDeclContext(LexicalDC);
5119 LexicalDC->addDeclInternal(ToCategory);
5120 // Import the type parameter list after MapImported, to avoid
5121 // loops when bringing in their DeclContext.
5122 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5123 ToCategory->setTypeParamList(*PListOrErr);
5124 else
5125 return PListOrErr.takeError();
5126
5127 // Import protocols
5129 SmallVector<SourceLocation, 4> ProtocolLocs;
5131 = D->protocol_loc_begin();
5133 FromProtoEnd = D->protocol_end();
5134 FromProto != FromProtoEnd;
5135 ++FromProto, ++FromProtoLoc) {
5136 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5137 Protocols.push_back(*ToProtoOrErr);
5138 else
5139 return ToProtoOrErr.takeError();
5140
5141 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5142 ProtocolLocs.push_back(*ToProtoLocOrErr);
5143 else
5144 return ToProtoLocOrErr.takeError();
5145 }
5146
5147 // FIXME: If we're merging, make sure that the protocol list is the same.
5148 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5149 ProtocolLocs.data(), Importer.getToContext());
5150
5151 } else {
5152 Importer.MapImported(D, ToCategory);
5153 }
5154
5155 // Import all of the members of this category.
5156 if (Error Err = ImportDeclContext(D))
5157 return std::move(Err);
5158
5159 // If we have an implementation, import it as well.
5160 if (D->getImplementation()) {
5161 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5162 import(D->getImplementation()))
5163 ToCategory->setImplementation(*ToImplOrErr);
5164 else
5165 return ToImplOrErr.takeError();
5166 }
5167
5168 return ToCategory;
5169}
5170
5173 if (To->getDefinition()) {
5175 if (Error Err = ImportDeclContext(From))
5176 return Err;
5177 return Error::success();
5178 }
5179
5180 // Start the protocol definition
5181 To->startDefinition();
5182
5183 // Import protocols
5185 SmallVector<SourceLocation, 4> ProtocolLocs;
5187 From->protocol_loc_begin();
5188 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5189 FromProtoEnd = From->protocol_end();
5190 FromProto != FromProtoEnd;
5191 ++FromProto, ++FromProtoLoc) {
5192 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5193 Protocols.push_back(*ToProtoOrErr);
5194 else
5195 return ToProtoOrErr.takeError();
5196
5197 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5198 ProtocolLocs.push_back(*ToProtoLocOrErr);
5199 else
5200 return ToProtoLocOrErr.takeError();
5201
5202 }
5203
5204 // FIXME: If we're merging, make sure that the protocol list is the same.
5205 To->setProtocolList(Protocols.data(), Protocols.size(),
5206 ProtocolLocs.data(), Importer.getToContext());
5207
5208 if (shouldForceImportDeclContext(Kind)) {
5209 // Import all of the members of this protocol.
5210 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5211 return Err;
5212 }
5213 return Error::success();
5214}
5215
5217 // If this protocol has a definition in the translation unit we're coming
5218 // from, but this particular declaration is not that definition, import the
5219 // definition and map to that.
5221 if (Definition && Definition != D) {
5222 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5223 return Importer.MapImported(D, *ImportedDefOrErr);
5224 else
5225 return ImportedDefOrErr.takeError();
5226 }
5227
5228 // Import the major distinguishing characteristics of a protocol.
5229 DeclContext *DC, *LexicalDC;
5230 DeclarationName Name;
5231 SourceLocation Loc;
5232 NamedDecl *ToD;
5233 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5234 return std::move(Err);
5235 if (ToD)
5236 return ToD;
5237
5238 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5239 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5240 for (auto *FoundDecl : FoundDecls) {
5241 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol))
5242 continue;
5243
5244 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5245 break;
5246 }
5247
5248 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5249 if (!ToProto) {
5250 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5251 if (!ToAtBeginLocOrErr)
5252 return ToAtBeginLocOrErr.takeError();
5253
5254 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5255 Name.getAsIdentifierInfo(), Loc,
5256 *ToAtBeginLocOrErr,
5257 /*PrevDecl=*/nullptr))
5258 return ToProto;
5259 ToProto->setLexicalDeclContext(LexicalDC);
5260 LexicalDC->addDeclInternal(ToProto);
5261 }
5262
5263 Importer.MapImported(D, ToProto);
5264
5266 if (Error Err = ImportDefinition(D, ToProto))
5267 return std::move(Err);
5268
5269 return ToProto;
5270}
5271
5273 DeclContext *DC, *LexicalDC;
5274 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5275 return std::move(Err);
5276
5277 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5278 if (!ExternLocOrErr)
5279 return ExternLocOrErr.takeError();
5280
5281 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5282 if (!LangLocOrErr)
5283 return LangLocOrErr.takeError();
5284
5285 bool HasBraces = D->hasBraces();
5286
5287 LinkageSpecDecl *ToLinkageSpec;
5288 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5289 *ExternLocOrErr, *LangLocOrErr,
5290 D->getLanguage(), HasBraces))
5291 return ToLinkageSpec;
5292
5293 if (HasBraces) {
5294 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5295 if (!RBraceLocOrErr)
5296 return RBraceLocOrErr.takeError();
5297 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5298 }
5299
5300 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5301 LexicalDC->addDeclInternal(ToLinkageSpec);
5302
5303 return ToLinkageSpec;
5304}
5305
5307 BaseUsingDecl *ToSI) {
5308 for (UsingShadowDecl *FromShadow : D->shadows()) {
5309 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5310 ToSI->addShadowDecl(*ToShadowOrErr);
5311 else
5312 // FIXME: We return error here but the definition is already created
5313 // and available with lookups. How to fix this?..
5314 return ToShadowOrErr.takeError();
5315 }
5316 return ToSI;
5317}
5318
5320 DeclContext *DC, *LexicalDC;
5321 DeclarationName Name;
5322 SourceLocation Loc;
5323 NamedDecl *ToD = nullptr;
5324 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5325 return std::move(Err);
5326 if (ToD)
5327 return ToD;
5328
5329 Error Err = Error::success();
5330 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5331 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5332 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5333 if (Err)
5334 return std::move(Err);
5335
5336 DeclarationNameInfo NameInfo(Name, ToLoc);
5337 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5338 return std::move(Err);
5339
5340 UsingDecl *ToUsing;
5341 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5342 ToUsingLoc, ToQualifierLoc, NameInfo,
5343 D->hasTypename()))
5344 return ToUsing;
5345
5346 ToUsing->setLexicalDeclContext(LexicalDC);
5347 LexicalDC->addDeclInternal(ToUsing);
5348
5349 if (NamedDecl *FromPattern =
5350 Importer.getFromContext().getInstantiatedFromUsingDecl(D)) {
5351 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5352 Importer.getToContext().setInstantiatedFromUsingDecl(
5353 ToUsing, *ToPatternOrErr);
5354 else
5355 return ToPatternOrErr.takeError();
5356 }
5357
5358 return ImportUsingShadowDecls(D, ToUsing);
5359}
5360
5362 DeclContext *DC, *LexicalDC;
5363 DeclarationName Name;
5364 SourceLocation Loc;
5365 NamedDecl *ToD = nullptr;
5366 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5367 return std::move(Err);
5368 if (ToD)
5369 return ToD;
5370
5371 Error Err = Error::success();
5372 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5373 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5374 auto ToNameLoc = importChecked(Err, D->getLocation());
5375 auto *ToEnumType = importChecked(Err, D->getEnumType());
5376 if (Err)
5377 return std::move(Err);
5378
5379 UsingEnumDecl *ToUsingEnum;
5380 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5381 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5382 return ToUsingEnum;
5383
5384 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5385 LexicalDC->addDeclInternal(ToUsingEnum);
5386
5387 if (UsingEnumDecl *FromPattern =
5388 Importer.getFromContext().getInstantiatedFromUsingEnumDecl(D)) {
5389 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5390 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5391 *ToPatternOrErr);
5392 else
5393 return ToPatternOrErr.takeError();
5394 }
5395
5396 return ImportUsingShadowDecls(D, ToUsingEnum);
5397}
5398
5400 DeclContext *DC, *LexicalDC;
5401 DeclarationName Name;
5402 SourceLocation Loc;
5403 NamedDecl *ToD = nullptr;
5404 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5405 return std::move(Err);
5406 if (ToD)
5407 return ToD;
5408
5409 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5410 if (!ToIntroducerOrErr)
5411 return ToIntroducerOrErr.takeError();
5412
5413 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5414 if (!ToTargetOrErr)
5415 return ToTargetOrErr.takeError();
5416
5417 UsingShadowDecl *ToShadow;
5418 if (auto *FromConstructorUsingShadow =
5419 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5420 Error Err = Error::success();
5422 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5423 if (Err)
5424 return std::move(Err);
5425 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5426 // is really the "NominatedBaseClassShadowDecl" value if it exists
5427 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5428 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5429 // get the correct values.
5430 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5431 ToShadow, D, Importer.getToContext(), DC, Loc,
5432 cast<UsingDecl>(*ToIntroducerOrErr),
5433 Nominated ? Nominated : *ToTargetOrErr,
5434 FromConstructorUsingShadow->constructsVirtualBase()))
5435 return ToShadow;
5436 } else {
5437 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5438 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5439 return ToShadow;
5440 }
5441
5442 ToShadow->setLexicalDeclContext(LexicalDC);
5443 ToShadow->setAccess(D->getAccess());
5444
5445 if (UsingShadowDecl *FromPattern =
5446 Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) {
5447 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5448 Importer.getToContext().setInstantiatedFromUsingShadowDecl(
5449 ToShadow, *ToPatternOrErr);
5450 else
5451 // FIXME: We return error here but the definition is already created
5452 // and available with lookups. How to fix this?..
5453 return ToPatternOrErr.takeError();
5454 }
5455
5456 LexicalDC->addDeclInternal(ToShadow);
5457
5458 return ToShadow;
5459}
5460
5462 DeclContext *DC, *LexicalDC;
5463 DeclarationName Name;
5464 SourceLocation Loc;
5465 NamedDecl *ToD = nullptr;
5466 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5467 return std::move(Err);
5468 if (ToD)
5469 return ToD;
5470
5471 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5472 if (!ToComAncestorOrErr)
5473 return ToComAncestorOrErr.takeError();
5474
5475 Error Err = Error::success();
5476 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5477 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5478 auto ToNamespaceKeyLocation =
5480 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5481 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5482 if (Err)
5483 return std::move(Err);
5484
5485 UsingDirectiveDecl *ToUsingDir;
5486 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5487 ToUsingLoc,
5488 ToNamespaceKeyLocation,
5489 ToQualifierLoc,
5490 ToIdentLocation,
5491 ToNominatedNamespace, *ToComAncestorOrErr))
5492 return ToUsingDir;
5493
5494 ToUsingDir->setLexicalDeclContext(LexicalDC);
5495 LexicalDC->addDeclInternal(ToUsingDir);
5496
5497 return ToUsingDir;
5498}
5499
5501 DeclContext *DC, *LexicalDC;
5502 DeclarationName Name;
5503 SourceLocation Loc;
5504 NamedDecl *ToD = nullptr;
5505 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5506 return std::move(Err);
5507 if (ToD)
5508 return ToD;
5509
5510 auto ToInstantiatedFromUsingOrErr =
5511 Importer.Import(D->getInstantiatedFromUsingDecl());
5512 if (!ToInstantiatedFromUsingOrErr)
5513 return ToInstantiatedFromUsingOrErr.takeError();
5514 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5515 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5516 return std::move(Err);
5517
5518 UsingPackDecl *ToUsingPack;
5519 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5520 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5521 Expansions))
5522 return ToUsingPack;
5523
5524 addDeclToContexts(D, ToUsingPack);
5525
5526 return ToUsingPack;
5527}
5528
5531 DeclContext *DC, *LexicalDC;
5532 DeclarationName Name;
5533 SourceLocation Loc;
5534 NamedDecl *ToD = nullptr;
5535 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5536 return std::move(Err);
5537 if (ToD)
5538 return ToD;
5539
5540 Error Err = Error::success();
5541 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5542 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5543 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5544 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5545 if (Err)
5546 return std::move(Err);
5547
5548 DeclarationNameInfo NameInfo(Name, ToLoc);
5549 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5550 return std::move(Err);
5551
5552 UnresolvedUsingValueDecl *ToUsingValue;
5553 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5554 ToUsingLoc, ToQualifierLoc, NameInfo,
5555 ToEllipsisLoc))
5556 return ToUsingValue;
5557
5558 ToUsingValue->setAccess(D->getAccess());
5559 ToUsingValue->setLexicalDeclContext(LexicalDC);
5560 LexicalDC->addDeclInternal(ToUsingValue);
5561
5562 return ToUsingValue;
5563}
5564
5567 DeclContext *DC, *LexicalDC;
5568 DeclarationName Name;
5569 SourceLocation Loc;
5570 NamedDecl *ToD = nullptr;
5571 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5572 return std::move(Err);
5573 if (ToD)
5574 return ToD;
5575
5576 Error Err = Error::success();
5577 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5578 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5579 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5580 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5581 if (Err)
5582 return std::move(Err);
5583
5585 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5586 ToUsingLoc, ToTypenameLoc,
5587 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5588 return ToUsing;
5589
5590 ToUsing->setAccess(D->getAccess());
5591 ToUsing->setLexicalDeclContext(LexicalDC);
5592 LexicalDC->addDeclInternal(ToUsing);
5593
5594 return ToUsing;
5595}
5596
5598 Decl* ToD = nullptr;
5599 switch (D->getBuiltinTemplateKind()) {
5600#define BuiltinTemplate(BTName) \
5601 case BuiltinTemplateKind::BTK##BTName: \
5602 ToD = Importer.getToContext().get##BTName##Decl(); \
5603 break;
5604#include "clang/Basic/BuiltinTemplates.inc"
5605 }
5606 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5607 Importer.MapImported(D, ToD);
5608 return ToD;
5609}
5610
5613 if (To->getDefinition()) {
5614 // Check consistency of superclass.
5615 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5616 if (FromSuper) {
5617 if (auto FromSuperOrErr = import(FromSuper))
5618 FromSuper = *FromSuperOrErr;
5619 else
5620 return FromSuperOrErr.takeError();
5621 }
5622
5623 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5624 if ((bool)FromSuper != (bool)ToSuper ||
5625 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5626 Importer.ToDiag(To->getLocation(),
5627 diag::warn_odr_objc_superclass_inconsistent)
5628 << To->getDeclName();
5629 if (ToSuper)
5630 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5631 << To->getSuperClass()->getDeclName();
5632 else
5633 Importer.ToDiag(To->getLocation(),
5634 diag::note_odr_objc_missing_superclass);
5635 if (From->getSuperClass())
5636 Importer.FromDiag(From->getSuperClassLoc(),
5637 diag::note_odr_objc_superclass)
5638 << From->getSuperClass()->getDeclName();
5639 else
5640 Importer.FromDiag(From->getLocation(),
5641 diag::note_odr_objc_missing_superclass);
5642 }
5643
5645 if (Error Err = ImportDeclContext(From))
5646 return Err;
5647 return Error::success();
5648 }
5649
5650 // Start the definition.
5651 To->startDefinition();
5652
5653 // If this class has a superclass, import it.
5654 if (From->getSuperClass()) {
5655 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5656 To->setSuperClass(*SuperTInfoOrErr);
5657 else
5658 return SuperTInfoOrErr.takeError();
5659 }
5660
5661 // Import protocols
5663 SmallVector<SourceLocation, 4> ProtocolLocs;
5665 From->protocol_loc_begin();
5666
5668 FromProtoEnd = From->protocol_end();
5669 FromProto != FromProtoEnd;
5670 ++FromProto, ++FromProtoLoc) {
5671 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5672 Protocols.push_back(*ToProtoOrErr);
5673 else
5674 return ToProtoOrErr.takeError();
5675
5676 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5677 ProtocolLocs.push_back(*ToProtoLocOrErr);
5678 else
5679 return ToProtoLocOrErr.takeError();
5680
5681 }
5682
5683 // FIXME: If we're merging, make sure that the protocol list is the same.
5684 To->setProtocolList(Protocols.data(), Protocols.size(),
5685 ProtocolLocs.data(), Importer.getToContext());
5686
5687 // Import categories. When the categories themselves are imported, they'll
5688 // hook themselves into this interface.
5689 for (auto *Cat : From->known_categories()) {
5690 auto ToCatOrErr = import(Cat);
5691 if (!ToCatOrErr)
5692 return ToCatOrErr.takeError();
5693 }
5694
5695 // If we have an @implementation, import it as well.
5696 if (From->getImplementation()) {
5697 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5698 import(From->getImplementation()))
5699 To->setImplementation(*ToImplOrErr);
5700 else
5701 return ToImplOrErr.takeError();
5702 }
5703
5704 // Import all of the members of this class.
5705 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5706 return Err;
5707
5708 return Error::success();
5709}
5710
5713 if (!list)
5714 return nullptr;
5715
5717 for (auto *fromTypeParam : *list) {
5718 if (auto toTypeParamOrErr = import(fromTypeParam))
5719 toTypeParams.push_back(*toTypeParamOrErr);
5720 else
5721 return toTypeParamOrErr.takeError();
5722 }
5723
5724 auto LAngleLocOrErr = import(list->getLAngleLoc());
5725 if (!LAngleLocOrErr)
5726 return LAngleLocOrErr.takeError();
5727
5728 auto RAngleLocOrErr = import(list->getRAngleLoc());
5729 if (!RAngleLocOrErr)
5730 return RAngleLocOrErr.takeError();
5731
5732 return ObjCTypeParamList::create(Importer.getToContext(),
5733 *LAngleLocOrErr,
5734 toTypeParams,
5735 *RAngleLocOrErr);
5736}
5737
5739 // If this class has a definition in the translation unit we're coming from,
5740 // but this particular declaration is not that definition, import the
5741 // definition and map to that.
5743 if (Definition && Definition != D) {
5744 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5745 return Importer.MapImported(D, *ImportedDefOrErr);
5746 else
5747 return ImportedDefOrErr.takeError();
5748 }
5749
5750 // Import the major distinguishing characteristics of an @interface.
5751 DeclContext *DC, *LexicalDC;
5752 DeclarationName Name;
5753 SourceLocation Loc;
5754 NamedDecl *ToD;
5755 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5756 return std::move(Err);
5757 if (ToD)
5758 return ToD;
5759
5760 // Look for an existing interface with the same name.
5761 ObjCInterfaceDecl *MergeWithIface = nullptr;
5762 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5763 for (auto *FoundDecl : FoundDecls) {
5764 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
5765 continue;
5766
5767 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5768 break;
5769 }
5770
5771 // Create an interface declaration, if one does not already exist.
5772 ObjCInterfaceDecl *ToIface = MergeWithIface;
5773 if (!ToIface) {
5774 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5775 if (!AtBeginLocOrErr)
5776 return AtBeginLocOrErr.takeError();
5777
5778 if (GetImportedOrCreateDecl(
5779 ToIface, D, Importer.getToContext(), DC,
5780 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5781 /*TypeParamList=*/nullptr,
5782 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5783 return ToIface;
5784 ToIface->setLexicalDeclContext(LexicalDC);
5785 LexicalDC->addDeclInternal(ToIface);
5786 }
5787 Importer.MapImported(D, ToIface);
5788 // Import the type parameter list after MapImported, to avoid
5789 // loops when bringing in their DeclContext.
5790 if (auto ToPListOrErr =
5792 ToIface->setTypeParamList(*ToPListOrErr);
5793 else
5794 return ToPListOrErr.takeError();
5795
5797 if (Error Err = ImportDefinition(D, ToIface))
5798 return std::move(Err);
5799
5800 return ToIface;
5801}
5802
5805 ObjCCategoryDecl *Category;
5806 if (Error Err = importInto(Category, D->getCategoryDecl()))
5807 return std::move(Err);
5808
5809 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5810 if (!ToImpl) {
5811 DeclContext *DC, *LexicalDC;
5812 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5813 return std::move(Err);
5814
5815 Error Err = Error::success();
5816 auto ToLocation = importChecked(Err, D->getLocation());
5817 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5818 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5819 if (Err)
5820 return std::move(Err);
5821
5822 if (GetImportedOrCreateDecl(
5823 ToImpl, D, Importer.getToContext(), DC,
5824 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5825 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5826 return ToImpl;
5827
5828 ToImpl->setLexicalDeclContext(LexicalDC);
5829 LexicalDC->addDeclInternal(ToImpl);
5830 Category->setImplementation(ToImpl);
5831 }
5832
5833 Importer.MapImported(D, ToImpl);
5834 if (Error Err = ImportDeclContext(D))
5835 return std::move(Err);
5836
5837 return ToImpl;
5838}
5839
5842 // Find the corresponding interface.
5843 ObjCInterfaceDecl *Iface;
5844 if (Error Err = importInto(Iface, D->getClassInterface()))
5845 return std::move(Err);
5846
5847 // Import the superclass, if any.
5848 ObjCInterfaceDecl *Super;
5849 if (Error Err = importInto(Super, D->getSuperClass()))
5850 return std::move(Err);
5851
5853 if (!Impl) {
5854 // We haven't imported an implementation yet. Create a new @implementation
5855 // now.
5856 DeclContext *DC, *LexicalDC;
5857 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5858 return std::move(Err);
5859
5860 Error Err = Error::success();
5861 auto ToLocation = importChecked(Err, D->getLocation());
5862 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5863 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5864 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5865 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5866 if (Err)
5867 return std::move(Err);
5868
5869 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5870 DC, Iface, Super,
5871 ToLocation,
5872 ToAtStartLoc,
5873 ToSuperClassLoc,
5874 ToIvarLBraceLoc,
5875 ToIvarRBraceLoc))
5876 return Impl;
5877
5878 Impl->setLexicalDeclContext(LexicalDC);
5879
5880 // Associate the implementation with the class it implements.
5881 Iface->setImplementation(Impl);
5882 Importer.MapImported(D, Iface->getImplementation());
5883 } else {
5884 Importer.MapImported(D, Iface->getImplementation());
5885
5886 // Verify that the existing @implementation has the same superclass.
5887 if ((Super && !Impl->getSuperClass()) ||
5888 (!Super && Impl->getSuperClass()) ||
5889 (Super && Impl->getSuperClass() &&
5891 Impl->getSuperClass()))) {
5892 Importer.ToDiag(Impl->getLocation(),
5893 diag::warn_odr_objc_superclass_inconsistent)
5894 << Iface->getDeclName();
5895 // FIXME: It would be nice to have the location of the superclass
5896 // below.
5897 if (Impl->getSuperClass())
5898 Importer.ToDiag(Impl->getLocation(),
5899 diag::note_odr_objc_superclass)
5900 << Impl->getSuperClass()->getDeclName();
5901 else
5902 Importer.ToDiag(Impl->getLocation(),
5903 diag::note_odr_objc_missing_superclass);
5904 if (D->getSuperClass())
5905 Importer.FromDiag(D->getLocation(),
5906 diag::note_odr_objc_superclass)
5907 << D->getSuperClass()->getDeclName();
5908 else
5909 Importer.FromDiag(D->getLocation(),
5910 diag::note_odr_objc_missing_superclass);
5911
5912 return make_error<ASTImportError>(ASTImportError::NameConflict);
5913 }
5914 }
5915
5916 // Import all of the members of this @implementation.
5917 if (Error Err = ImportDeclContext(D))
5918 return std::move(Err);
5919
5920 return Impl;
5921}
5922
5924 // Import the major distinguishing characteristics of an @property.
5925 DeclContext *DC, *LexicalDC;
5926 DeclarationName Name;
5927 SourceLocation Loc;
5928 NamedDecl *ToD;
5929 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5930 return std::move(Err);
5931 if (ToD)
5932 return ToD;
5933
5934 // Check whether we have already imported this property.
5935 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5936 for (auto *FoundDecl : FoundDecls) {
5937 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5938 // Instance and class properties can share the same name but are different
5939 // declarations.
5940 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5941 continue;
5942
5943 // Check property types.
5944 if (!Importer.IsStructurallyEquivalent(D->getType(),
5945 FoundProp->getType())) {
5946 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5947 << Name << D->getType() << FoundProp->getType();
5948 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5949 << FoundProp->getType();
5950
5951 return make_error<ASTImportError>(ASTImportError::NameConflict);
5952 }
5953
5954 // FIXME: Check property attributes, getters, setters, etc.?
5955
5956 // Consider these properties to be equivalent.
5957 Importer.MapImported(D, FoundProp);
5958 return FoundProp;
5959 }
5960 }
5961
5962 Error Err = Error::success();
5963 auto ToType = importChecked(Err, D->getType());
5964 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5965 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5966 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5967 if (Err)
5968 return std::move(Err);
5969
5970 // Create the new property.
5971 ObjCPropertyDecl *ToProperty;
5972 if (GetImportedOrCreateDecl(
5973 ToProperty, D, Importer.getToContext(), DC, Loc,
5974 Name.getAsIdentifierInfo(), ToAtLoc,
5975 ToLParenLoc, ToType,
5976 ToTypeSourceInfo, D->getPropertyImplementation()))
5977 return ToProperty;
5978
5979 auto ToGetterName = importChecked(Err, D->getGetterName());
5980 auto ToSetterName = importChecked(Err, D->getSetterName());
5981 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5982 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5983 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5984 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5985 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5986 if (Err)
5987 return std::move(Err);
5988
5989 ToProperty->setLexicalDeclContext(LexicalDC);
5990 LexicalDC->addDeclInternal(ToProperty);
5991
5995 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5996 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5997 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5998 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5999 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6000 return ToProperty;
6001}
6002
6006 if (Error Err = importInto(Property, D->getPropertyDecl()))
6007 return std::move(Err);
6008
6009 DeclContext *DC, *LexicalDC;
6010 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6011 return std::move(Err);
6012
6013 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6014
6015 // Import the ivar (for an @synthesize).
6016 ObjCIvarDecl *Ivar = nullptr;
6017 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6018 return std::move(Err);
6019
6020 ObjCPropertyImplDecl *ToImpl
6021 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6022 Property->getQueryKind());
6023 if (!ToImpl) {
6024
6025 Error Err = Error::success();
6026 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6027 auto ToLocation = importChecked(Err, D->getLocation());
6028 auto ToPropertyIvarDeclLoc =
6030 if (Err)
6031 return std::move(Err);
6032
6033 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6034 ToBeginLoc,
6035 ToLocation, Property,
6036 D->getPropertyImplementation(), Ivar,
6037 ToPropertyIvarDeclLoc))
6038 return ToImpl;
6039
6040 ToImpl->setLexicalDeclContext(LexicalDC);
6041 LexicalDC->addDeclInternal(ToImpl);
6042 } else {
6043 // Check that we have the same kind of property implementation (@synthesize
6044 // vs. @dynamic).
6046 Importer.ToDiag(ToImpl->getLocation(),
6047 diag::warn_odr_objc_property_impl_kind_inconsistent)
6048 << Property->getDeclName()
6049 << (ToImpl->getPropertyImplementation()
6051 Importer.FromDiag(D->getLocation(),
6052 diag::note_odr_objc_property_impl_kind)
6053 << D->getPropertyDecl()->getDeclName()
6055
6056 return make_error<ASTImportError>(ASTImportError::NameConflict);
6057 }
6058
6059 // For @synthesize, check that we have the same
6061 Ivar != ToImpl->getPropertyIvarDecl()) {
6062 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6063 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6064 << Property->getDeclName()
6065 << ToImpl->getPropertyIvarDecl()->getDeclName()
6066 << Ivar->getDeclName();
6067 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6068 diag::note_odr_objc_synthesize_ivar_here)
6070
6071 return make_error<ASTImportError>(ASTImportError::NameConflict);
6072 }
6073
6074 // Merge the existing implementation with the new implementation.
6075 Importer.MapImported(D, ToImpl);
6076 }
6077
6078 return ToImpl;
6079}
6080
6083 Error Err = Error::success();
6084 auto ToType = importChecked(Err, D->getType());
6085 auto ToValue = importChecked(Err, D->getValue());
6086 if (Err)
6087 return std::move(Err);
6088
6090 auto Create = [this](QualType T, const APValue &V) {
6091 return Importer.ToContext.getTemplateParamObjectDecl(T, V);
6092 };
6093 (void)GetImportedOrCreateSpecialDecl(ToD, Create, D, ToType, ToValue);
6094 return ToD;
6095}
6096
6099 // For template arguments, we adopt the translation unit as our declaration
6100 // context. This context will be fixed when (during) the actual template
6101 // declaration is created.
6102
6103 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6104 if (!BeginLocOrErr)
6105 return BeginLocOrErr.takeError();
6106
6107 ExpectedSLoc LocationOrErr = import(D->getLocation());
6108 if (!LocationOrErr)
6109 return LocationOrErr.takeError();
6110
6111 TemplateTypeParmDecl *ToD = nullptr;
6112 if (GetImportedOrCreateDecl(
6113 ToD, D, Importer.getToContext(),
6114 Importer.getToContext().getTranslationUnitDecl(),
6115 *BeginLocOrErr, *LocationOrErr,
6116 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6118 D->hasTypeConstraint()))
6119 return ToD;
6120
6121 // Import the type-constraint
6122 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6123
6124 Error Err = Error::success();
6125 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6126 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6127 if (Err)
6128 return std::move(Err);
6129
6130 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6131 }
6132
6133 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6134 return Err;
6135
6136 return ToD;
6137}
6138
6141
6142 Error Err = Error::success();
6143 auto ToDeclName = importChecked(Err, D->getDeclName());
6144 auto ToLocation = importChecked(Err, D->getLocation());
6145 auto ToType = importChecked(Err, D->getType());
6146 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6147 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6148 if (Err)
6149 return std::move(Err);
6150
6151 NonTypeTemplateParmDecl *ToD = nullptr;
6152 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6153 Importer.getToContext().getTranslationUnitDecl(),
6154 ToInnerLocStart, ToLocation, D->getDepth(),
6155 D->getPosition(),
6156 ToDeclName.getAsIdentifierInfo(), ToType,
6157 D->isParameterPack(), ToTypeSourceInfo))
6158 return ToD;
6159
6160 Err = importTemplateParameterDefaultArgument(D, ToD);
6161 if (Err)
6162 return Err;
6163
6164 return ToD;
6165}
6166
6169 bool IsCanonical = false;
6170 if (auto *CanonD = Importer.getFromContext()
6171 .findCanonicalTemplateTemplateParmDeclInternal(D);
6172 CanonD == D)
6173 IsCanonical = true;
6174
6175 // Import the name of this declaration.
6176 auto NameOrErr = import(D->getDeclName());
6177 if (!NameOrErr)
6178 return NameOrErr.takeError();
6179
6180 // Import the location of this declaration.
6181 ExpectedSLoc LocationOrErr = import(D->getLocation());
6182 if (!LocationOrErr)
6183 return LocationOrErr.takeError();
6184
6185 // Import template parameters.
6186 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6187 if (!TemplateParamsOrErr)
6188 return TemplateParamsOrErr.takeError();
6189
6190 TemplateTemplateParmDecl *ToD = nullptr;
6191 if (GetImportedOrCreateDecl(
6192 ToD, D, Importer.getToContext(),
6193 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6194 D->getDepth(), D->getPosition(), D->isParameterPack(),
6195 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6196 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6197 return ToD;
6198
6199 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6200 return Err;
6201
6202 if (IsCanonical)
6203 return Importer.getToContext()
6204 .insertCanonicalTemplateTemplateParmDeclInternal(ToD);
6205
6206 return ToD;
6207}
6208
6209// Returns the definition for a (forward) declaration of a TemplateDecl, if
6210// it has any definition in the redecl chain.
6211template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6212 assert(D->getTemplatedDecl() && "Should be called on templates only");
6213 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6214 if (!ToTemplatedDef)
6215 return nullptr;
6216 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6217 return cast_or_null<T>(TemplateWithDef);
6218}
6219
6221
6222 // Import the major distinguishing characteristics of this class template.
6223 DeclContext *DC, *LexicalDC;
6224 DeclarationName Name;
6225 SourceLocation Loc;
6226 NamedDecl *ToD;
6227 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6228 return std::move(Err);
6229 if (ToD)
6230 return ToD;
6231
6232 // Should check if a declaration is friend in a dependent context.
6233 // Such templates are not linked together in a declaration chain.
6234 // The ASTImporter strategy is to map existing forward declarations to
6235 // imported ones only if strictly necessary, otherwise import these as new
6236 // forward declarations. In case of the "dependent friend" declarations, new
6237 // declarations are created, but not linked in a declaration chain.
6238 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6239 return TD->getFriendObjectKind() != Decl::FOK_None &&
6240 TD->getLexicalDeclContext()->isDependentContext();
6241 };
6242 bool DependentFriend = IsDependentFriend(D);
6243
6244 ClassTemplateDecl *FoundByLookup = nullptr;
6245
6246 // We may already have a template of the same name; try to find and match it.
6247 if (!DC->isFunctionOrMethod()) {
6248 SmallVector<NamedDecl *, 4> ConflictingDecls;
6249 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6250 for (auto *FoundDecl : FoundDecls) {
6251 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary |
6253 continue;
6254
6255 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6256 if (FoundTemplate) {
6257 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6258 continue;
6259
6260 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6261 bool IgnoreTemplateParmDepth =
6262 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6264 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6265 IgnoreTemplateParmDepth)) {
6266 if (DependentFriend || IsDependentFriend(FoundTemplate))
6267 continue;
6268
6269 ClassTemplateDecl *TemplateWithDef =
6270 getTemplateDefinition(FoundTemplate);
6271 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6272 return Importer.MapImported(D, TemplateWithDef);
6273 if (!FoundByLookup)
6274 FoundByLookup = FoundTemplate;
6275 // Search in all matches because there may be multiple decl chains,
6276 // see ASTTests test ImportExistingFriendClassTemplateDef.
6277 continue;
6278 }
6279 // When importing a friend, it is possible that multiple declarations
6280 // with same name can co-exist in specific cases (if a template contains
6281 // a friend template and has a specialization). For this case the
6282 // declarations should match, except that the "template depth" is
6283 // different. No linking of previous declaration is needed in this case.
6284 // FIXME: This condition may need refinement.
6285 if (D->getFriendObjectKind() != Decl::FOK_None &&
6286 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6287 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6288 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6289 /*IgnoreTemplateParmDepth=*/true))
6290 continue;
6291
6292 ConflictingDecls.push_back(FoundDecl);
6293 }
6294 }
6295
6296 if (!ConflictingDecls.empty()) {
6297 ExpectedName NameOrErr = Importer.HandleNameConflict(
6298 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6299 ConflictingDecls.size());
6300 if (NameOrErr)
6301 Name = NameOrErr.get();
6302 else
6303 return NameOrErr.takeError();
6304 }
6305 }
6306
6307 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6308
6309 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6310 if (!TemplateParamsOrErr)
6311 return TemplateParamsOrErr.takeError();
6312
6313 // Create the declaration that is being templated.
6314 CXXRecordDecl *ToTemplated;
6315 if (Error Err = importInto(ToTemplated, FromTemplated))
6316 return std::move(Err);
6317
6318 // Create the class template declaration itself.
6320 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6321 *TemplateParamsOrErr, ToTemplated))
6322 return D2;
6323
6324 ToTemplated->setDescribedClassTemplate(D2);
6325
6326 D2->setAccess(D->getAccess());
6327 D2->setLexicalDeclContext(LexicalDC);
6328
6329 addDeclToContexts(D, D2);
6330 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6331
6332 if (FoundByLookup) {
6333 auto *Recent =
6334 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6335
6336 // It is possible that during the import of the class template definition
6337 // we start the import of a fwd friend decl of the very same class template
6338 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6339 // had been created earlier and by that time the lookup could not find
6340 // anything existing, so it has no previous decl. Later, (still during the
6341 // import of the fwd friend decl) we start to import the definition again
6342 // and this time the lookup finds the previous fwd friend class template.
6343 // In this case we must set up the previous decl for the templated decl.
6344 if (!ToTemplated->getPreviousDecl()) {
6345 assert(FoundByLookup->getTemplatedDecl() &&
6346 "Found decl must have its templated decl set");
6347 CXXRecordDecl *PrevTemplated =
6348 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6349 if (ToTemplated != PrevTemplated)
6350 ToTemplated->setPreviousDecl(PrevTemplated);
6351 }
6352
6353 D2->setPreviousDecl(Recent);
6354 }
6355
6356 return D2;
6357}
6358
6361 ClassTemplateDecl *ClassTemplate;
6362 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6363 return std::move(Err);
6364
6365 // Import the context of this declaration.
6366 DeclContext *DC, *LexicalDC;
6367 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6368 return std::move(Err);
6369
6370 // Import template arguments.
6372 if (Error Err =
6373 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6374 return std::move(Err);
6375 // Try to find an existing specialization with these template arguments and
6376 // template parameter list.
6377 llvm::FoldingSetInsertToken InsertToken;
6378 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6380 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6381
6382 // Import template parameters.
6383 TemplateParameterList *ToTPList = nullptr;
6384
6385 if (PartialSpec) {
6386 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6387 if (!ToTPListOrErr)
6388 return ToTPListOrErr.takeError();
6389 ToTPList = *ToTPListOrErr;
6390 PrevDecl = ClassTemplate->findPartialSpecialization(
6391 TemplateArgs, *ToTPListOrErr, InsertToken);
6392 } else
6393 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertToken);
6394
6395 if (PrevDecl) {
6396 if (IsStructuralMatch(D, PrevDecl)) {
6397 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6398 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6399 Importer.MapImported(D, PrevDefinition);
6400 // Import those default field initializers which have been
6401 // instantiated in the "From" context, but not in the "To" context.
6402 for (auto *FromField : D->fields()) {
6403 auto ToOrErr = import(FromField);
6404 if (!ToOrErr)
6405 return ToOrErr.takeError();
6406 }
6407
6408 // Import those methods which have been instantiated in the
6409 // "From" context, but not in the "To" context.
6410 for (CXXMethodDecl *FromM : D->methods()) {
6411 auto ToOrErr = import(FromM);
6412 if (!ToOrErr)
6413 return ToOrErr.takeError();
6414 }
6415
6416 // TODO Import instantiated default arguments.
6417 // TODO Import instantiated exception specifications.
6418 //
6419 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6420 // what else could be fused during an AST merge.
6421 return PrevDefinition;
6422 }
6423 } else { // ODR violation.
6424 // FIXME HandleNameConflict
6425 return make_error<ASTImportError>(ASTImportError::NameConflict);
6426 }
6427 }
6428
6429 // Import the location of this declaration.
6430 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6431 if (!BeginLocOrErr)
6432 return BeginLocOrErr.takeError();
6433 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6434 if (!IdLocOrErr)
6435 return IdLocOrErr.takeError();
6436
6437 // Import TemplateArgumentListInfo.
6438 TemplateArgumentListInfo ToTAInfo;
6439 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6440 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6441 return std::move(Err);
6442 }
6443
6444 // Create the specialization.
6445 ClassTemplateSpecializationDecl *D2 = nullptr;
6446 if (PartialSpec) {
6447 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6448 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6449 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6450 /*CanonInjectedTST=*/CanQualType(),
6451 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6452 return D2;
6453
6454 // Update InsertToken, because preceding import calls may have invalidated
6455 // it by adding new specializations.
6457 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6458 InsertToken))
6459 // Add this partial specialization to the class template.
6460 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertToken);
6462 import(PartialSpec->getInstantiatedFromMember()))
6463 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6464 else
6465 return ToInstOrErr.takeError();
6466
6467 updateLookupTableForTemplateParameters(*ToTPList);
6468 } else { // Not a partial specialization.
6469 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6470 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6471 TemplateArgs, D->hasStrictPackMatch(),
6472 PrevDecl))
6473 return D2;
6474
6475 // Update InsertToken, because preceding import calls may have invalidated
6476 // it by adding new specializations.
6477 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertToken))
6478 // Add this specialization to the class template.
6479 ClassTemplate->AddSpecialization(D2, InsertToken);
6480 }
6481
6483
6484 // Set the context of this specialization/instantiation.
6485 D2->setLexicalDeclContext(LexicalDC);
6486
6487 // Add to the DC only if it was an explicit specialization/instantiation.
6489 LexicalDC->addDeclInternal(D2);
6490 }
6491
6492 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6493 D2->setBraceRange(*BraceRangeOrErr);
6494 else
6495 return BraceRangeOrErr.takeError();
6496
6497 if (Error Err = ImportTemplateParameterLists(D, D2))
6498 return std::move(Err);
6499
6500 // Import the qualifier, if any.
6501 if (auto LocOrErr = import(D->getQualifierLoc()))
6502 D2->setQualifierInfo(*LocOrErr);
6503 else
6504 return LocOrErr.takeError();
6505
6506 if (D->getTemplateArgsAsWritten())
6507 D2->setTemplateArgsAsWritten(ToTAInfo);
6508
6509 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6510 D2->setTemplateKeywordLoc(*LocOrErr);
6511 else
6512 return LocOrErr.takeError();
6513
6514 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6515 D2->setExternKeywordLoc(*LocOrErr);
6516 else
6517 return LocOrErr.takeError();
6518
6519 if (D->getPointOfInstantiation().isValid()) {
6520 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6521 D2->setPointOfInstantiation(*POIOrErr);
6522 else
6523 return POIOrErr.takeError();
6524 }
6525
6527
6528 if (auto P = D->getInstantiatedFrom()) {
6529 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6530 if (auto CTDorErr = import(CTD))
6531 D2->setInstantiationOf(*CTDorErr);
6532 } else {
6534 auto CTPSDOrErr = import(CTPSD);
6535 if (!CTPSDOrErr)
6536 return CTPSDOrErr.takeError();
6538 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6539 for (unsigned I = 0; I < DArgs.size(); ++I) {
6540 const TemplateArgument &DArg = DArgs[I];
6541 if (auto ArgOrErr = import(DArg))
6542 D2ArgsVec[I] = *ArgOrErr;
6543 else
6544 return ArgOrErr.takeError();
6545 }
6547 *CTPSDOrErr,
6548 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6549 }
6550 }
6551
6552 if (D->isCompleteDefinition())
6553 if (Error Err = ImportDefinition(D, D2))
6554 return std::move(Err);
6555
6556 return D2;
6557}
6558
6560 // Import the major distinguishing characteristics of this variable template.
6561 DeclContext *DC, *LexicalDC;
6562 DeclarationName Name;
6563 SourceLocation Loc;
6564 NamedDecl *ToD;
6565 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6566 return std::move(Err);
6567 if (ToD)
6568 return ToD;
6569
6570 // We may already have a template of the same name; try to find and match it.
6571 assert(!DC->isFunctionOrMethod() &&
6572 "Variable templates cannot be declared at function scope");
6573
6574 SmallVector<NamedDecl *, 4> ConflictingDecls;
6575 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6576 VarTemplateDecl *FoundByLookup = nullptr;
6577 for (auto *FoundDecl : FoundDecls) {
6578 if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
6579 continue;
6580
6581 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6582 // Use the templated decl, some linkage flags are set only there.
6583 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6584 D->getTemplatedDecl()))
6585 continue;
6586 if (IsStructuralMatch(D, FoundTemplate)) {
6587 // FIXME Check for ODR error if the two definitions have
6588 // different initializers?
6589 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6590 if (D->getDeclContext()->isRecord()) {
6591 assert(FoundTemplate->getDeclContext()->isRecord() &&
6592 "Member variable template imported as non-member, "
6593 "inconsistent imported AST?");
6594 if (FoundDef)
6595 return Importer.MapImported(D, FoundDef);
6597 return Importer.MapImported(D, FoundTemplate);
6598 } else {
6599 if (FoundDef && D->isThisDeclarationADefinition())
6600 return Importer.MapImported(D, FoundDef);
6601 }
6602 FoundByLookup = FoundTemplate;
6603 break;
6604 }
6605 ConflictingDecls.push_back(FoundDecl);
6606 }
6607 }
6608
6609 if (!ConflictingDecls.empty()) {
6610 ExpectedName NameOrErr = Importer.HandleNameConflict(
6611 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6612 ConflictingDecls.size());
6613 if (NameOrErr)
6614 Name = NameOrErr.get();
6615 else
6616 return NameOrErr.takeError();
6617 }
6618
6619 VarDecl *DTemplated = D->getTemplatedDecl();
6620
6621 // Import the type.
6622 // FIXME: Value not used?
6623 ExpectedType TypeOrErr = import(DTemplated->getType());
6624 if (!TypeOrErr)
6625 return TypeOrErr.takeError();
6626
6627 // Create the declaration that is being templated.
6628 VarDecl *ToTemplated;
6629 if (Error Err = importInto(ToTemplated, DTemplated))
6630 return std::move(Err);
6631
6632 // Create the variable template declaration itself.
6633 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6634 if (!TemplateParamsOrErr)
6635 return TemplateParamsOrErr.takeError();
6636
6637 VarTemplateDecl *ToVarTD;
6638 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6639 Name, *TemplateParamsOrErr, ToTemplated))
6640 return ToVarTD;
6641
6642 ToTemplated->setDescribedVarTemplate(ToVarTD);
6643
6644 ToVarTD->setAccess(D->getAccess());
6645 ToVarTD->setLexicalDeclContext(LexicalDC);
6646 LexicalDC->addDeclInternal(ToVarTD);
6647 if (DC != Importer.getToContext().getTranslationUnitDecl())
6648 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6649
6650 if (FoundByLookup) {
6651 auto *Recent =
6652 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6653 if (!ToTemplated->getPreviousDecl()) {
6654 auto *PrevTemplated =
6655 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6656 if (ToTemplated != PrevTemplated)
6657 ToTemplated->setPreviousDecl(PrevTemplated);
6658 }
6659 ToVarTD->setPreviousDecl(Recent);
6660 }
6661
6662 return ToVarTD;
6663}
6664
6667 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6668 // in an analog way (but specialized for this case).
6669
6671 auto RedeclIt = Redecls.begin();
6672 // Import the first part of the decl chain. I.e. import all previous
6673 // declarations starting from the canonical decl.
6674 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6675 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6676 if (!RedeclOrErr)
6677 return RedeclOrErr.takeError();
6678 }
6679 assert(*RedeclIt == D);
6680
6681 VarTemplateDecl *VarTemplate = nullptr;
6683 return std::move(Err);
6684
6685 // Import the context of this declaration.
6686 DeclContext *DC, *LexicalDC;
6687 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6688 return std::move(Err);
6689
6690 // Import the location of this declaration.
6691 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6692 if (!BeginLocOrErr)
6693 return BeginLocOrErr.takeError();
6694
6695 auto IdLocOrErr = import(D->getLocation());
6696 if (!IdLocOrErr)
6697 return IdLocOrErr.takeError();
6698
6699 // Import template arguments.
6701 if (Error Err =
6702 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6703 return std::move(Err);
6704
6705 // Try to find an existing specialization with these template arguments.
6706 llvm::FoldingSetInsertToken InsertToken;
6707 VarTemplateSpecializationDecl *FoundSpecialization =
6708 VarTemplate->findSpecialization(TemplateArgs, InsertToken);
6709 if (FoundSpecialization) {
6710 if (IsStructuralMatch(D, FoundSpecialization)) {
6711 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6712 if (D->getDeclContext()->isRecord()) {
6713 // In a record, it is allowed only to have one optional declaration and
6714 // one definition of the (static or constexpr) variable template.
6715 assert(
6716 FoundSpecialization->getDeclContext()->isRecord() &&
6717 "Member variable template specialization imported as non-member, "
6718 "inconsistent imported AST?");
6719 if (FoundDef)
6720 return Importer.MapImported(D, FoundDef);
6722 return Importer.MapImported(D, FoundSpecialization);
6723 } else {
6724 // If definition is imported and there is already one, map to it.
6725 // Otherwise create a new variable and link it to the existing.
6726 if (FoundDef && D->isThisDeclarationADefinition())
6727 return Importer.MapImported(D, FoundDef);
6728 }
6729 } else {
6730 return make_error<ASTImportError>(ASTImportError::NameConflict);
6731 }
6732 }
6733
6734 VarTemplateSpecializationDecl *D2 = nullptr;
6735
6736 TemplateArgumentListInfo ToTAInfo;
6737 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6738 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6739 return std::move(Err);
6740 }
6741
6742 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6743 // Create a new specialization.
6744 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6745 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6746 if (!ToTPListOrErr)
6747 return ToTPListOrErr.takeError();
6748
6749 PartVarSpecDecl *ToPartial;
6750 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6751 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6752 VarTemplate, QualType(), nullptr,
6753 D->getStorageClass(), TemplateArgs))
6754 return ToPartial;
6755
6756 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6757 import(FromPartial->getInstantiatedFromMember()))
6758 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6759 else
6760 return ToInstOrErr.takeError();
6761
6762 if (FromPartial->isMemberSpecialization())
6763 ToPartial->setMemberSpecialization();
6764
6765 D2 = ToPartial;
6766
6767 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6768 // to adopt template parameters.
6769 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6770 } else { // Full specialization
6771 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6772 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6773 QualType(), nullptr, D->getStorageClass(),
6774 TemplateArgs))
6775 return D2;
6776 }
6777
6778 // Update InsertToken, because preceding import calls may have invalidated
6779 // it by adding new specializations.
6780 if (!VarTemplate->findSpecialization(TemplateArgs, InsertToken))
6781 VarTemplate->AddSpecialization(D2, InsertToken);
6782
6783 QualType T;
6784 if (Error Err = importInto(T, D->getType()))
6785 return std::move(Err);
6786 D2->setType(T);
6787
6788 auto TInfoOrErr = import(D->getTypeSourceInfo());
6789 if (!TInfoOrErr)
6790 return TInfoOrErr.takeError();
6791 D2->setTypeSourceInfo(*TInfoOrErr);
6792
6793 if (D->getPointOfInstantiation().isValid()) {
6794 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6795 D2->setPointOfInstantiation(*POIOrErr);
6796 else
6797 return POIOrErr.takeError();
6798 }
6799
6801
6802 if (D->getTemplateArgsAsWritten())
6803 D2->setTemplateArgsAsWritten(ToTAInfo);
6804
6805 if (auto LocOrErr = import(D->getQualifierLoc()))
6806 D2->setQualifierInfo(*LocOrErr);
6807 else
6808 return LocOrErr.takeError();
6809
6810 if (D->isConstexpr())
6811 D2->setConstexpr(true);
6812
6813 D2->setAccess(D->getAccess());
6814
6815 if (Error Err = ImportInitializer(D, D2))
6816 return std::move(Err);
6817
6818 if (FoundSpecialization)
6819 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6820
6821 addDeclToContexts(D, D2);
6822
6823 // Import the rest of the chain. I.e. import all subsequent declarations.
6824 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6825 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6826 if (!RedeclOrErr)
6827 return RedeclOrErr.takeError();
6828 }
6829
6830 return D2;
6831}
6832
6835 DeclContext *DC, *LexicalDC;
6836 DeclarationName Name;
6837 SourceLocation Loc;
6838 NamedDecl *ToD;
6839
6840 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6841 return std::move(Err);
6842
6843 if (ToD)
6844 return ToD;
6845
6846 const FunctionTemplateDecl *FoundByLookup = nullptr;
6847
6848 // Try to find a function in our own ("to") context with the same name, same
6849 // type, and in the same context as the function we're importing.
6850 // FIXME Split this into a separate function.
6851 if (!LexicalDC->isFunctionOrMethod()) {
6853 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6854 for (auto *FoundDecl : FoundDecls) {
6855 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6856 continue;
6857
6858 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6859 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6860 continue;
6861 if (IsStructuralMatch(D, FoundTemplate)) {
6862 FunctionTemplateDecl *TemplateWithDef =
6863 getTemplateDefinition(FoundTemplate);
6864 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6865 return Importer.MapImported(D, TemplateWithDef);
6866
6867 FoundByLookup = FoundTemplate;
6868 break;
6869 // TODO: handle conflicting names
6870 }
6871 }
6872 }
6873 }
6874
6875 auto ParamsOrErr = import(D->getTemplateParameters());
6876 if (!ParamsOrErr)
6877 return ParamsOrErr.takeError();
6878 TemplateParameterList *Params = *ParamsOrErr;
6879
6880 FunctionDecl *TemplatedFD;
6881 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6882 return std::move(Err);
6883
6884 // At creation of the template the template parameters are "adopted"
6885 // (DeclContext is changed). After this possible change the lookup table
6886 // must be updated.
6887 // At deduction guides the DeclContext of the template parameters may be
6888 // different from what we would expect, it may be the class template, or a
6889 // probably different CXXDeductionGuideDecl. This may come from the fact that
6890 // the template parameter objects may be shared between deduction guides or
6891 // the class template, and at creation of multiple FunctionTemplateDecl
6892 // objects (for deduction guides) the same parameters are re-used. The
6893 // "adoption" happens multiple times with different parent, even recursively
6894 // for TemplateTemplateParmDecl. The same happens at import when the
6895 // FunctionTemplateDecl objects are created, but in different order.
6896 // In this way the DeclContext of these template parameters is not necessarily
6897 // the same as in the "from" context.
6899 OldParamDC.reserve(Params->size());
6900 llvm::transform(*Params, std::back_inserter(OldParamDC),
6901 [](NamedDecl *ND) { return ND->getDeclContext(); });
6902
6903 FunctionTemplateDecl *ToFunc;
6904 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6905 Params, TemplatedFD))
6906 return ToFunc;
6907
6908 // Fail if TemplatedFD is already part of a template.
6909 // The template should have been found by structural equivalence check before,
6910 // or ToFunc should be already imported.
6911 // If not, there is AST incompatibility that can be caused by previous import
6912 // errors. (NameConflict is not exact here.)
6913 if (TemplatedFD->getDescribedTemplate())
6914 return make_error<ASTImportError>(ASTImportError::NameConflict);
6915
6916 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6917
6918 ToFunc->setAccess(D->getAccess());
6919 ToFunc->setLexicalDeclContext(LexicalDC);
6920 addDeclToContexts(D, ToFunc);
6921
6922 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6923 if (LT && !OldParamDC.empty()) {
6924 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6925 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6926 }
6927
6928 if (FoundByLookup) {
6929 auto *Recent =
6930 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6931 if (!TemplatedFD->getPreviousDecl()) {
6932 assert(FoundByLookup->getTemplatedDecl() &&
6933 "Found decl must have its templated decl set");
6934 auto *PrevTemplated =
6935 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6936 if (TemplatedFD != PrevTemplated)
6937 TemplatedFD->setPreviousDecl(PrevTemplated);
6938 }
6939 ToFunc->setPreviousDecl(Recent);
6940 }
6941
6942 return ToFunc;
6943}
6944
6946 DeclContext *DC, *LexicalDC;
6947 Error Err = ImportDeclContext(D, DC, LexicalDC);
6948 auto LocationOrErr = importChecked(Err, D->getLocation());
6949 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6950 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6951 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6952 if (Err)
6953 return std::move(Err);
6954
6955 ConceptDecl *To;
6956 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6957 NameDeclOrErr, ToTemplateParameters,
6958 ConstraintExpr))
6959 return To;
6960 To->setLexicalDeclContext(LexicalDC);
6961 LexicalDC->addDeclInternal(To);
6962 return To;
6963}
6964
6967 DeclContext *DC, *LexicalDC;
6968 Error Err = ImportDeclContext(D, DC, LexicalDC);
6969 auto RequiresLoc = importChecked(Err, D->getLocation());
6970 if (Err)
6971 return std::move(Err);
6972
6974 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
6975 return To;
6976 To->setLexicalDeclContext(LexicalDC);
6977 LexicalDC->addDeclInternal(To);
6978 return To;
6979}
6980
6983 DeclContext *DC, *LexicalDC;
6984 Error Err = ImportDeclContext(D, DC, LexicalDC);
6985 auto ToSL = importChecked(Err, D->getLocation());
6986 if (Err)
6987 return std::move(Err);
6988
6990 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
6991 return std::move(Err);
6992
6994 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
6995 return To;
6996 To->setLexicalDeclContext(LexicalDC);
6997 LexicalDC->addDeclInternal(To);
6998 return To;
6999}
7000
7001//----------------------------------------------------------------------------
7002// Import Statements
7003//----------------------------------------------------------------------------
7004
7006 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7007 << S->getStmtClassName();
7008 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7009}
7010
7011
7013 if (Importer.returnWithErrorInTest())
7014 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7016 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7017 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7018 // ToII is nullptr when no symbolic name is given for output operand
7019 // see ParseStmtAsm::ParseAsmOperandsOpt
7020 Names.push_back(ToII);
7021 }
7022
7023 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7024 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7025 // ToII is nullptr when no symbolic name is given for input operand
7026 // see ParseStmtAsm::ParseAsmOperandsOpt
7027 Names.push_back(ToII);
7028 }
7029
7030 SmallVector<Expr *, 4> Clobbers;
7031 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7032 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7033 Clobbers.push_back(*ClobberOrErr);
7034 else
7035 return ClobberOrErr.takeError();
7036
7037 }
7038
7039 SmallVector<Expr *, 4> Constraints;
7040 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7041 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7042 Constraints.push_back(*OutputOrErr);
7043 else
7044 return OutputOrErr.takeError();
7045 }
7046
7047 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7048 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7049 Constraints.push_back(*InputOrErr);
7050 else
7051 return InputOrErr.takeError();
7052 }
7053
7055 S->getNumLabels());
7056 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7057 return std::move(Err);
7058
7059 if (Error Err =
7060 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7061 return std::move(Err);
7062
7063 if (Error Err = ImportArrayChecked(
7064 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7065 return std::move(Err);
7066
7067 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7068 if (!AsmLocOrErr)
7069 return AsmLocOrErr.takeError();
7070 auto AsmStrOrErr = import(S->getAsmStringExpr());
7071 if (!AsmStrOrErr)
7072 return AsmStrOrErr.takeError();
7073 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7074 if (!RParenLocOrErr)
7075 return RParenLocOrErr.takeError();
7076
7077 return new (Importer.getToContext()) GCCAsmStmt(
7078 Importer.getToContext(),
7079 *AsmLocOrErr,
7080 S->isSimple(),
7081 S->isVolatile(),
7082 S->getNumOutputs(),
7083 S->getNumInputs(),
7084 Names.data(),
7085 Constraints.data(),
7086 Exprs.data(),
7087 *AsmStrOrErr,
7088 S->getNumClobbers(),
7089 Clobbers.data(),
7090 S->getNumLabels(),
7091 *RParenLocOrErr);
7092}
7093
7095
7096 Error Err = Error::success();
7097 auto ToDG = importChecked(Err, S->getDeclGroup());
7098 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7099 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7100 if (Err)
7101 return std::move(Err);
7102 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7103}
7104
7106 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7107 if (!ToSemiLocOrErr)
7108 return ToSemiLocOrErr.takeError();
7109 return new (Importer.getToContext()) NullStmt(
7110 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7111}
7112
7114 SmallVector<Stmt *, 8> ToStmts(S->size());
7115
7116 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7117 return std::move(Err);
7118
7119 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7120 if (!ToLBracLocOrErr)
7121 return ToLBracLocOrErr.takeError();
7122
7123 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7124 if (!ToRBracLocOrErr)
7125 return ToRBracLocOrErr.takeError();
7126
7127 FPOptionsOverride FPO =
7129 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7130 *ToLBracLocOrErr, *ToRBracLocOrErr);
7131}
7132
7134
7135 Error Err = Error::success();
7136 auto ToLHS = importChecked(Err, S->getLHS());
7137 auto ToRHS = importChecked(Err, S->getRHS());
7138 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7139 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7140 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7141 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7142 if (Err)
7143 return std::move(Err);
7144
7145 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7146 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7147 ToStmt->setSubStmt(ToSubStmt);
7148
7149 return ToStmt;
7150}
7151
7153
7154 Error Err = Error::success();
7155 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7156 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7157 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7158 if (Err)
7159 return std::move(Err);
7160
7161 return new (Importer.getToContext()) DefaultStmt(
7162 ToDefaultLoc, ToColonLoc, ToSubStmt);
7163}
7164
7166
7167 Error Err = Error::success();
7168 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7169 auto ToLabelDecl = importChecked(Err, S->getDecl());
7170 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7171 if (Err)
7172 return std::move(Err);
7173
7174 return new (Importer.getToContext()) LabelStmt(
7175 ToIdentLoc, ToLabelDecl, ToSubStmt);
7176}
7177
7179 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7180 if (!ToAttrLocOrErr)
7181 return ToAttrLocOrErr.takeError();
7182 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7183 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7184 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7185 return std::move(Err);
7186 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7187 if (!ToSubStmtOrErr)
7188 return ToSubStmtOrErr.takeError();
7189
7191 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7192}
7193
7195
7196 Error Err = Error::success();
7197 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7198 auto ToInit = importChecked(Err, S->getInit());
7199 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7200 auto ToCond = importChecked(Err, S->getCond());
7201 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7202 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7203 auto ToThen = importChecked(Err, S->getThen());
7204 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7205 auto ToElse = importChecked(Err, S->getElse());
7206 if (Err)
7207 return std::move(Err);
7208
7209 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7210 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7211 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7212}
7213
7215
7216 Error Err = Error::success();
7217 auto ToInit = importChecked(Err, S->getInit());
7218 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7219 auto ToCond = importChecked(Err, S->getCond());
7220 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7221 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7222 auto ToBody = importChecked(Err, S->getBody());
7223 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7224 if (Err)
7225 return std::move(Err);
7226
7227 auto *ToStmt =
7228 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7229 ToCond, ToLParenLoc, ToRParenLoc);
7230 ToStmt->setBody(ToBody);
7231 ToStmt->setSwitchLoc(ToSwitchLoc);
7232
7233 // Now we have to re-chain the cases.
7234 SwitchCase *LastChainedSwitchCase = nullptr;
7235 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7236 SC = SC->getNextSwitchCase()) {
7237 Expected<SwitchCase *> ToSCOrErr = import(SC);
7238 if (!ToSCOrErr)
7239 return ToSCOrErr.takeError();
7240 if (LastChainedSwitchCase)
7241 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7242 else
7243 ToStmt->setSwitchCaseList(*ToSCOrErr);
7244 LastChainedSwitchCase = *ToSCOrErr;
7245 }
7246
7247 return ToStmt;
7248}
7249
7251
7252 Error Err = Error::success();
7253 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7254 auto ToCond = importChecked(Err, S->getCond());
7255 auto ToBody = importChecked(Err, S->getBody());
7256 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7257 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7258 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7259 if (Err)
7260 return std::move(Err);
7261
7262 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7263 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7264}
7265
7267
7268 Error Err = Error::success();
7269 auto ToBody = importChecked(Err, S->getBody());
7270 auto ToCond = importChecked(Err, S->getCond());
7271 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7272 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7273 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7274 if (Err)
7275 return std::move(Err);
7276
7277 return new (Importer.getToContext()) DoStmt(
7278 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7279}
7280
7282
7283 Error Err = Error::success();
7284 auto ToInit = importChecked(Err, S->getInit());
7285 auto ToCond = importChecked(Err, S->getCond());
7286 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7287 auto ToInc = importChecked(Err, S->getInc());
7288 auto ToBody = importChecked(Err, S->getBody());
7289 auto ToForLoc = importChecked(Err, S->getForLoc());
7290 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7291 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7292 if (Err)
7293 return std::move(Err);
7294
7295 return new (Importer.getToContext()) ForStmt(
7296 Importer.getToContext(),
7297 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7298 ToRParenLoc);
7299}
7300
7302
7303 Error Err = Error::success();
7304 auto ToLabel = importChecked(Err, S->getLabel());
7305 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7306 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7307 if (Err)
7308 return std::move(Err);
7309
7310 return new (Importer.getToContext()) GotoStmt(
7311 ToLabel, ToGotoLoc, ToLabelLoc);
7312}
7313
7315
7316 Error Err = Error::success();
7317 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7318 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7319 auto ToTarget = importChecked(Err, S->getTarget());
7320 if (Err)
7321 return std::move(Err);
7322
7323 return new (Importer.getToContext()) IndirectGotoStmt(
7324 ToGotoLoc, ToStarLoc, ToTarget);
7325}
7326
7327template <typename StmtClass>
7329 ASTImporter &Importer, StmtClass *S) {
7330 Error Err = Error::success();
7331 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7332 auto ToLabelLoc = S->hasLabelTarget()
7333 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7334 : SourceLocation();
7335 auto ToDecl = S->hasLabelTarget()
7336 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7337 : nullptr;
7338 if (Err)
7339 return std::move(Err);
7340 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7341}
7342
7346
7350
7352
7353 Error Err = Error::success();
7354 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7355 auto ToRetValue = importChecked(Err, S->getRetValue());
7356 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7357 if (Err)
7358 return std::move(Err);
7359
7360 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7361 ToNRVOCandidate);
7362}
7363
7365
7366 Error Err = Error::success();
7367 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7368 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7369 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7370 if (Err)
7371 return std::move(Err);
7372
7373 return new (Importer.getToContext()) CXXCatchStmt (
7374 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7375}
7376
7378 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7379 if (!ToTryLocOrErr)
7380 return ToTryLocOrErr.takeError();
7381
7382 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7383 if (!ToTryBlockOrErr)
7384 return ToTryBlockOrErr.takeError();
7385
7386 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7387 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7388 CXXCatchStmt *FromHandler = S->getHandler(HI);
7389 if (auto ToHandlerOrErr = import(FromHandler))
7390 ToHandlers[HI] = *ToHandlerOrErr;
7391 else
7392 return ToHandlerOrErr.takeError();
7393 }
7394
7395 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7396 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7397}
7398
7400
7401 Error Err = Error::success();
7402 auto ToInit = importChecked(Err, S->getInit());
7403 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7404 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7405 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7406 auto ToCond = importChecked(Err, S->getCond());
7407 auto ToInc = importChecked(Err, S->getInc());
7408 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7409 auto ToBody = importChecked(Err, S->getBody());
7410 auto ToForLoc = importChecked(Err, S->getForLoc());
7411 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7412 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7413 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7414 if (Err)
7415 return std::move(Err);
7416
7417 return new (Importer.getToContext()) CXXForRangeStmt(
7418 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7419 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7420}
7421
7424 Error Err = Error::success();
7425 auto ToESD = importChecked(Err, S->getDecl());
7426 auto ToInit = importChecked(Err, S->getInit());
7427 auto ToExpansionVar = importChecked(Err, S->getExpansionVarStmt());
7428 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7429 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7430 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7431 if (Err)
7432 return std::move(Err);
7433
7434 switch (S->getKind()) {
7437 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToLParenLoc,
7438 ToColonLoc, ToRParenLoc);
7439
7441 auto ToRange = importChecked(Err, S->getRangeVarStmt());
7442 auto ToBegin = importChecked(Err, S->getBeginVarStmt());
7443 auto ToIter = importChecked(Err, S->getIterVarStmt());
7444 if (Err)
7445 return std::move(Err);
7446
7448 Importer.getToContext(), ToESD, ToInit, ToExpansionVar, ToRange,
7449 ToBegin, ToIter, ToLParenLoc, ToColonLoc, ToRParenLoc);
7450 }
7451
7453 auto ToDecompositionDeclStmt =
7455 if (Err)
7456 return std::move(Err);
7457
7459 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7460 ToDecompositionDeclStmt, ToLParenLoc, ToColonLoc, ToRParenLoc);
7461 }
7462
7464 auto ToExpansionInitializer =
7466 if (Err)
7467 return std::move(Err);
7469 Importer.getToContext(), ToESD, ToInit, ToExpansionVar,
7470 ToExpansionInitializer, ToLParenLoc, ToColonLoc, ToRParenLoc);
7471 }
7472 }
7473
7474 llvm_unreachable("invalid pattern kind");
7475}
7476
7479 Error Err = Error::success();
7480 SmallVector<Stmt *> ToInstantiations;
7481 SmallVector<Stmt *> ToSharedStmts;
7482 auto ToParent = importChecked(Err, S->getParent());
7483 for (Stmt *FromInst : S->getInstantiations())
7484 ToInstantiations.push_back(importChecked(Err, FromInst));
7485 for (Stmt *FromShared : S->getPreambleStmts())
7486 ToSharedStmts.push_back(importChecked(Err, FromShared));
7487
7488 if (Err)
7489 return std::move(Err);
7490
7492 Importer.getToContext(), ToParent, ToInstantiations, ToSharedStmts,
7494}
7495
7498 Error Err = Error::success();
7499 auto ToElement = importChecked(Err, S->getElement());
7500 auto ToCollection = importChecked(Err, S->getCollection());
7501 auto ToBody = importChecked(Err, S->getBody());
7502 auto ToForLoc = importChecked(Err, S->getForLoc());
7503 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7504 if (Err)
7505 return std::move(Err);
7506
7507 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7508 ToCollection,
7509 ToBody,
7510 ToForLoc,
7511 ToRParenLoc);
7512}
7513
7515
7516 Error Err = Error::success();
7517 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7518 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7519 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7520 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7521 if (Err)
7522 return std::move(Err);
7523
7524 return new (Importer.getToContext()) ObjCAtCatchStmt (
7525 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7526}
7527
7529 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7530 if (!ToAtFinallyLocOrErr)
7531 return ToAtFinallyLocOrErr.takeError();
7532 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7533 if (!ToAtFinallyStmtOrErr)
7534 return ToAtFinallyStmtOrErr.takeError();
7535 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7536 *ToAtFinallyStmtOrErr);
7537}
7538
7540
7541 Error Err = Error::success();
7542 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7543 auto ToTryBody = importChecked(Err, S->getTryBody());
7544 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7545 if (Err)
7546 return std::move(Err);
7547
7548 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7549 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7550 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7551 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7552 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7553 else
7554 return ToCatchStmtOrErr.takeError();
7555 }
7556
7557 return ObjCAtTryStmt::Create(Importer.getToContext(),
7558 ToAtTryLoc, ToTryBody,
7559 ToCatchStmts.begin(), ToCatchStmts.size(),
7560 ToFinallyStmt);
7561}
7562
7565
7566 Error Err = Error::success();
7567 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7568 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7569 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7570 if (Err)
7571 return std::move(Err);
7572
7573 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7574 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7575}
7576
7578 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7579 if (!ToThrowLocOrErr)
7580 return ToThrowLocOrErr.takeError();
7581 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7582 if (!ToThrowExprOrErr)
7583 return ToThrowExprOrErr.takeError();
7584 return new (Importer.getToContext()) ObjCAtThrowStmt(
7585 *ToThrowLocOrErr, *ToThrowExprOrErr);
7586}
7587
7590 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7591 if (!ToAtLocOrErr)
7592 return ToAtLocOrErr.takeError();
7593 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7594 if (!ToSubStmtOrErr)
7595 return ToSubStmtOrErr.takeError();
7596 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7597 *ToSubStmtOrErr);
7598}
7599
7600//----------------------------------------------------------------------------
7601// Import Expressions
7602//----------------------------------------------------------------------------
7604 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7605 << E->getStmtClassName();
7606 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7607}
7608
7610 Error Err = Error::success();
7611 auto ToType = importChecked(Err, E->getType());
7612 auto BLoc = importChecked(Err, E->getBeginLoc());
7613 auto RParenLoc = importChecked(Err, E->getEndLoc());
7614 if (Err)
7615 return std::move(Err);
7616 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7617 if (!ParentContextOrErr)
7618 return ParentContextOrErr.takeError();
7619
7620 return new (Importer.getToContext())
7621 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7622 RParenLoc, *ParentContextOrErr);
7623}
7624
7626
7627 Error Err = Error::success();
7628 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7629 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7630 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7631 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7632 auto ToType = importChecked(Err, E->getType());
7633 if (Err)
7634 return std::move(Err);
7635
7636 return new (Importer.getToContext())
7637 VAArgExpr(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7638 E->getVarargABI());
7639}
7640
7642
7643 Error Err = Error::success();
7644 auto ToCond = importChecked(Err, E->getCond());
7645 auto ToLHS = importChecked(Err, E->getLHS());
7646 auto ToRHS = importChecked(Err, E->getRHS());
7647 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7648 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7649 auto ToType = importChecked(Err, E->getType());
7650 if (Err)
7651 return std::move(Err);
7652
7654 ExprObjectKind OK = E->getObjectKind();
7655
7656 // The value of CondIsTrue only matters if the value is not
7657 // condition-dependent.
7658 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7659
7660 return new (Importer.getToContext())
7661 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7662 ToRParenLoc, CondIsTrue);
7663}
7664
7666 Error Err = Error::success();
7667 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7668 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7669 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7670 auto ToType = importChecked(Err, E->getType());
7671 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7672 if (Err)
7673 return std::move(Err);
7674
7676 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7677 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7679}
7680
7682 Error Err = Error::success();
7683 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7684 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7685 auto ToType = importChecked(Err, E->getType());
7686 const unsigned NumSubExprs = E->getNumSubExprs();
7687
7689 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7690 ToSubExprs.resize(NumSubExprs);
7691
7692 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7693 return std::move(Err);
7694
7695 return new (Importer.getToContext()) ShuffleVectorExpr(
7696 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7697}
7698
7700 ExpectedType TypeOrErr = import(E->getType());
7701 if (!TypeOrErr)
7702 return TypeOrErr.takeError();
7703
7704 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7705 if (!BeginLocOrErr)
7706 return BeginLocOrErr.takeError();
7707
7708 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7709}
7710
7713 Error Err = Error::success();
7714 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7715 Expr *ToControllingExpr = nullptr;
7716 TypeSourceInfo *ToControllingType = nullptr;
7717 if (E->isExprPredicate())
7718 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7719 else
7720 ToControllingType = importChecked(Err, E->getControllingType());
7721 assert((ToControllingExpr || ToControllingType) &&
7722 "Either the controlling expr or type must be nonnull");
7723 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7724 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7725 if (Err)
7726 return std::move(Err);
7727
7729 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7730 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7731 return std::move(Err);
7732
7733 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7734 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7735 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7736 return std::move(Err);
7737
7738 const ASTContext &ToCtx = Importer.getToContext();
7739 if (E->isResultDependent()) {
7740 if (ToControllingExpr) {
7742 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7743 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7745 }
7747 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7748 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7750 }
7751
7752 if (ToControllingExpr) {
7754 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7755 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7757 }
7759 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7760 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7762}
7763
7765
7766 Error Err = Error::success();
7767 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7768 auto ToType = importChecked(Err, E->getType());
7769 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7770 if (Err)
7771 return std::move(Err);
7772
7773 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7774 E->getIdentKind(), E->isTransparent(),
7775 ToFunctionName);
7776}
7777
7779
7780 Error Err = Error::success();
7781 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7782 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7783 auto ToDecl = importChecked(Err, E->getDecl());
7784 auto ToLocation = importChecked(Err, E->getLocation());
7785 auto ToType = importChecked(Err, E->getType());
7786 if (Err)
7787 return std::move(Err);
7788
7789 NamedDecl *ToFoundD = nullptr;
7790 if (E->getDecl() != E->getFoundDecl()) {
7791 auto FoundDOrErr = import(E->getFoundDecl());
7792 if (!FoundDOrErr)
7793 return FoundDOrErr.takeError();
7794 ToFoundD = *FoundDOrErr;
7795 }
7796
7797 TemplateArgumentListInfo ToTAInfo;
7798 TemplateArgumentListInfo *ToResInfo = nullptr;
7799 if (E->hasExplicitTemplateArgs()) {
7800 if (Error Err =
7802 E->template_arguments(), ToTAInfo))
7803 return std::move(Err);
7804 ToResInfo = &ToTAInfo;
7805 }
7806
7807 auto *ToE = DeclRefExpr::Create(
7808 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7809 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7810 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7811 if (E->hadMultipleCandidates())
7812 ToE->setHadMultipleCandidates(true);
7813 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7814 return ToE;
7815}
7816
7818 ExpectedType TypeOrErr = import(E->getType());
7819 if (!TypeOrErr)
7820 return TypeOrErr.takeError();
7821
7822 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7823}
7824
7826 ExpectedExpr ToInitOrErr = import(E->getInit());
7827 if (!ToInitOrErr)
7828 return ToInitOrErr.takeError();
7829
7830 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7831 if (!ToEqualOrColonLocOrErr)
7832 return ToEqualOrColonLocOrErr.takeError();
7833
7834 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7835 // List elements from the second, the first is Init itself
7836 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7837 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7838 ToIndexExprs[I - 1] = *ToArgOrErr;
7839 else
7840 return ToArgOrErr.takeError();
7841 }
7842
7843 SmallVector<Designator, 4> ToDesignators(E->size());
7844 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7845 return std::move(Err);
7846
7848 Importer.getToContext(), ToDesignators,
7849 ToIndexExprs, *ToEqualOrColonLocOrErr,
7850 E->usesGNUSyntax(), *ToInitOrErr);
7851}
7852
7855 ExpectedType ToTypeOrErr = import(E->getType());
7856 if (!ToTypeOrErr)
7857 return ToTypeOrErr.takeError();
7858
7859 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7860 if (!ToLocationOrErr)
7861 return ToLocationOrErr.takeError();
7862
7863 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7864 *ToTypeOrErr, *ToLocationOrErr);
7865}
7866
7868 ExpectedType ToTypeOrErr = import(E->getType());
7869 if (!ToTypeOrErr)
7870 return ToTypeOrErr.takeError();
7871
7872 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7873 if (!ToLocationOrErr)
7874 return ToLocationOrErr.takeError();
7875
7877 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7878}
7879
7880
7882 ExpectedType ToTypeOrErr = import(E->getType());
7883 if (!ToTypeOrErr)
7884 return ToTypeOrErr.takeError();
7885
7886 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7887 if (!ToLocationOrErr)
7888 return ToLocationOrErr.takeError();
7889
7891 Importer.getToContext(), E->getValue(), E->isExact(),
7892 *ToTypeOrErr, *ToLocationOrErr);
7893}
7894
7896 auto ToTypeOrErr = import(E->getType());
7897 if (!ToTypeOrErr)
7898 return ToTypeOrErr.takeError();
7899
7900 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7901 if (!ToSubExprOrErr)
7902 return ToSubExprOrErr.takeError();
7903
7904 return new (Importer.getToContext()) ImaginaryLiteral(
7905 *ToSubExprOrErr, *ToTypeOrErr);
7906}
7907
7909 auto ToTypeOrErr = import(E->getType());
7910 if (!ToTypeOrErr)
7911 return ToTypeOrErr.takeError();
7912
7913 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7914 if (!ToLocationOrErr)
7915 return ToLocationOrErr.takeError();
7916
7917 return new (Importer.getToContext()) FixedPointLiteral(
7918 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7919 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7920}
7921
7923 ExpectedType ToTypeOrErr = import(E->getType());
7924 if (!ToTypeOrErr)
7925 return ToTypeOrErr.takeError();
7926
7927 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7928 if (!ToLocationOrErr)
7929 return ToLocationOrErr.takeError();
7930
7931 return new (Importer.getToContext()) CharacterLiteral(
7932 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7933}
7934
7936 ExpectedType ToTypeOrErr = import(E->getType());
7937 if (!ToTypeOrErr)
7938 return ToTypeOrErr.takeError();
7939
7941 if (Error Err = ImportArrayChecked(
7942 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7943 return std::move(Err);
7944
7945 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7946 E->getKind(), E->isPascal(), *ToTypeOrErr,
7947 ToLocations);
7948}
7949
7951
7952 Error Err = Error::success();
7953 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7954 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7955 auto ToType = importChecked(Err, E->getType());
7956 auto ToInitializer = importChecked(Err, E->getInitializer());
7957 if (Err)
7958 return std::move(Err);
7959
7960 return new (Importer.getToContext()) CompoundLiteralExpr(
7961 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7962 ToInitializer, E->isFileScope());
7963}
7964
7966
7967 Error Err = Error::success();
7968 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7969 auto ToType = importChecked(Err, E->getType());
7970 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7971 if (Err)
7972 return std::move(Err);
7973
7975 if (Error Err = ImportArrayChecked(
7976 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7977 ToExprs.begin()))
7978 return std::move(Err);
7979
7980 return new (Importer.getToContext()) AtomicExpr(
7981
7982 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7983}
7984
7986 Error Err = Error::success();
7987 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7988 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7989 auto ToLabel = importChecked(Err, E->getLabel());
7990 auto ToType = importChecked(Err, E->getType());
7991 if (Err)
7992 return std::move(Err);
7993
7994 return new (Importer.getToContext()) AddrLabelExpr(
7995 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7996}
7998 Error Err = Error::success();
7999 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8000 auto ToResult = importChecked(Err, E->getAPValueResult());
8001 if (Err)
8002 return std::move(Err);
8003
8004 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
8005}
8007 Error Err = Error::success();
8008 auto ToLParen = importChecked(Err, E->getLParen());
8009 auto ToRParen = importChecked(Err, E->getRParen());
8010 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8011 if (Err)
8012 return std::move(Err);
8013
8014 return new (Importer.getToContext())
8015 ParenExpr(ToLParen, ToRParen, ToSubExpr);
8016}
8017
8019 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
8020 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
8021 return std::move(Err);
8022
8023 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
8024 if (!ToLParenLocOrErr)
8025 return ToLParenLocOrErr.takeError();
8026
8027 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
8028 if (!ToRParenLocOrErr)
8029 return ToRParenLocOrErr.takeError();
8030
8031 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
8032 ToExprs, *ToRParenLocOrErr);
8033}
8034
8036 Error Err = Error::success();
8037 auto ToSubStmt = importChecked(Err, E->getSubStmt());
8038 auto ToType = importChecked(Err, E->getType());
8039 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8040 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8041 if (Err)
8042 return std::move(Err);
8043
8044 return new (Importer.getToContext())
8045 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
8046 E->getTemplateDepth());
8047}
8048
8050 Error Err = Error::success();
8051 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8052 auto ToType = importChecked(Err, E->getType());
8053 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8054 if (Err)
8055 return std::move(Err);
8056
8057 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
8058 E->hasStoredFPFeatures());
8059 UO->setType(ToType);
8060 UO->setSubExpr(ToSubExpr);
8061 UO->setOpcode(E->getOpcode());
8062 UO->setOperatorLoc(ToOperatorLoc);
8063 UO->setCanOverflow(E->canOverflow());
8064 if (E->hasStoredFPFeatures())
8065 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8066
8067 return UO;
8068}
8069
8071
8073 Error Err = Error::success();
8074 auto ToType = importChecked(Err, E->getType());
8075 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8076 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8077 if (Err)
8078 return std::move(Err);
8079
8080 if (E->isArgumentType()) {
8081 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8082 import(E->getArgumentTypeInfo());
8083 if (!ToArgumentTypeInfoOrErr)
8084 return ToArgumentTypeInfoOrErr.takeError();
8085
8086 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8087 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8088 ToRParenLoc);
8089 }
8090
8091 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8092 if (!ToArgumentExprOrErr)
8093 return ToArgumentExprOrErr.takeError();
8094
8095 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8096 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8097}
8098
8100 Error Err = Error::success();
8101 auto ToLHS = importChecked(Err, E->getLHS());
8102 auto ToRHS = importChecked(Err, E->getRHS());
8103 auto ToType = importChecked(Err, E->getType());
8104 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8105 if (Err)
8106 return std::move(Err);
8107
8109 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8110 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8111 E->getFPFeatures());
8112}
8113
8115 Error Err = Error::success();
8116 auto ToCond = importChecked(Err, E->getCond());
8117 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8118 auto ToLHS = importChecked(Err, E->getLHS());
8119 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8120 auto ToRHS = importChecked(Err, E->getRHS());
8121 auto ToType = importChecked(Err, E->getType());
8122 if (Err)
8123 return std::move(Err);
8124
8125 return new (Importer.getToContext()) ConditionalOperator(
8126 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8127 E->getValueKind(), E->getObjectKind());
8128}
8129
8132 Error Err = Error::success();
8133 auto ToCommon = importChecked(Err, E->getCommon());
8134 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8135 auto ToCond = importChecked(Err, E->getCond());
8136 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8137 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8138 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8139 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8140 auto ToType = importChecked(Err, E->getType());
8141 if (Err)
8142 return std::move(Err);
8143
8144 return new (Importer.getToContext()) BinaryConditionalOperator(
8145 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8146 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8147 E->getObjectKind());
8148}
8149
8152 Error Err = Error::success();
8153 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8154 if (Err)
8155 return std::move(Err);
8156
8157 return new (Importer.getToContext())
8158 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8159}
8160
8162 Error Err = Error::success();
8163 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8164 auto ToQueriedTypeSourceInfo =
8166 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8167 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8168 auto ToType = importChecked(Err, E->getType());
8169 if (Err)
8170 return std::move(Err);
8171
8172 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8173 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8174 ToDimensionExpression, ToEndLoc, ToType);
8175}
8176
8178 Error Err = Error::success();
8179 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8180 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8181 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8182 auto ToType = importChecked(Err, E->getType());
8183 if (Err)
8184 return std::move(Err);
8185
8186 return new (Importer.getToContext()) ExpressionTraitExpr(
8187 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8188 ToEndLoc, ToType);
8189}
8190
8192 Error Err = Error::success();
8193 auto ToLocation = importChecked(Err, E->getLocation());
8194 auto ToType = importChecked(Err, E->getType());
8195 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8196 if (Err)
8197 return std::move(Err);
8198
8199 return new (Importer.getToContext()) OpaqueValueExpr(
8200 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8201}
8202
8204 Error Err = Error::success();
8205 auto ToLHS = importChecked(Err, E->getLHS());
8206 auto ToRHS = importChecked(Err, E->getRHS());
8207 auto ToType = importChecked(Err, E->getType());
8208 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8209 if (Err)
8210 return std::move(Err);
8211
8212 return new (Importer.getToContext()) ArraySubscriptExpr(
8213 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8214 ToRBracketLoc);
8215}
8216
8219 Error Err = Error::success();
8220 auto ToLHS = importChecked(Err, E->getLHS());
8221 auto ToRHS = importChecked(Err, E->getRHS());
8222 auto ToType = importChecked(Err, E->getType());
8223 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8224 auto ToComputationResultType =
8226 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8227 if (Err)
8228 return std::move(Err);
8229
8231 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8232 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8233 E->getFPFeatures(),
8234 ToComputationLHSType, ToComputationResultType);
8235}
8236
8239 CXXCastPath Path;
8240 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8241 if (auto SpecOrErr = import(*I))
8242 Path.push_back(*SpecOrErr);
8243 else
8244 return SpecOrErr.takeError();
8245 }
8246 return Path;
8247}
8248
8250 ExpectedType ToTypeOrErr = import(E->getType());
8251 if (!ToTypeOrErr)
8252 return ToTypeOrErr.takeError();
8253
8254 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8255 if (!ToSubExprOrErr)
8256 return ToSubExprOrErr.takeError();
8257
8258 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8259 if (!ToBasePathOrErr)
8260 return ToBasePathOrErr.takeError();
8261
8263 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8264 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8265}
8266
8268 Error Err = Error::success();
8269 auto ToType = importChecked(Err, E->getType());
8270 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8271 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8272 if (Err)
8273 return std::move(Err);
8274
8275 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8276 if (!ToBasePathOrErr)
8277 return ToBasePathOrErr.takeError();
8278 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8279
8280 switch (E->getStmtClass()) {
8281 case Stmt::CStyleCastExprClass: {
8282 auto *CCE = cast<CStyleCastExpr>(E);
8283 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8284 if (!ToLParenLocOrErr)
8285 return ToLParenLocOrErr.takeError();
8286 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8287 if (!ToRParenLocOrErr)
8288 return ToRParenLocOrErr.takeError();
8290 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8291 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8292 *ToLParenLocOrErr, *ToRParenLocOrErr);
8293 }
8294
8295 case Stmt::CXXFunctionalCastExprClass: {
8296 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8297 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8298 if (!ToLParenLocOrErr)
8299 return ToLParenLocOrErr.takeError();
8300 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8301 if (!ToRParenLocOrErr)
8302 return ToRParenLocOrErr.takeError();
8304 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8305 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8306 *ToLParenLocOrErr, *ToRParenLocOrErr);
8307 }
8308
8309 case Stmt::ObjCBridgedCastExprClass: {
8310 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8311 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8312 if (!ToLParenLocOrErr)
8313 return ToLParenLocOrErr.takeError();
8314 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8315 if (!ToBridgeKeywordLocOrErr)
8316 return ToBridgeKeywordLocOrErr.takeError();
8317 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8318 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8319 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8320 }
8321 case Stmt::BuiltinBitCastExprClass: {
8322 auto *BBC = cast<BuiltinBitCastExpr>(E);
8323 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8324 if (!ToKWLocOrErr)
8325 return ToKWLocOrErr.takeError();
8326 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8327 if (!ToRParenLocOrErr)
8328 return ToRParenLocOrErr.takeError();
8329 return new (Importer.getToContext()) BuiltinBitCastExpr(
8330 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8331 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8332 }
8333 default:
8334 llvm_unreachable("Cast expression of unsupported type!");
8335 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8336 }
8337}
8338
8341 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8342 const OffsetOfNode &FromNode = E->getComponent(I);
8343
8344 SourceLocation ToBeginLoc, ToEndLoc;
8345
8346 if (FromNode.getKind() != OffsetOfNode::Base) {
8347 Error Err = Error::success();
8348 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8349 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8350 if (Err)
8351 return std::move(Err);
8352 }
8353
8354 switch (FromNode.getKind()) {
8356 ToNodes.push_back(
8357 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8358 break;
8359 case OffsetOfNode::Base: {
8360 auto ToBSOrErr = import(FromNode.getBase());
8361 if (!ToBSOrErr)
8362 return ToBSOrErr.takeError();
8363 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8364 break;
8365 }
8366 case OffsetOfNode::Field: {
8367 auto ToFieldOrErr = import(FromNode.getField());
8368 if (!ToFieldOrErr)
8369 return ToFieldOrErr.takeError();
8370 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8371 break;
8372 }
8374 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8375 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8376 break;
8377 }
8378 }
8379 }
8380
8382 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8383 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8384 if (!ToIndexExprOrErr)
8385 return ToIndexExprOrErr.takeError();
8386 ToExprs[I] = *ToIndexExprOrErr;
8387 }
8388
8389 Error Err = Error::success();
8390 auto ToType = importChecked(Err, E->getType());
8391 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8392 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8393 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8394 if (Err)
8395 return std::move(Err);
8396
8397 return OffsetOfExpr::Create(
8398 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8399 ToExprs, ToRParenLoc);
8400}
8401
8403 Error Err = Error::success();
8404 auto ToType = importChecked(Err, E->getType());
8405 auto ToOperand = importChecked(Err, E->getOperand());
8406 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8407 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8408 if (Err)
8409 return std::move(Err);
8410
8411 CanThrowResult ToCanThrow;
8412 if (E->isValueDependent())
8413 ToCanThrow = CT_Dependent;
8414 else
8415 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8416
8417 return new (Importer.getToContext()) CXXNoexceptExpr(
8418 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8419}
8420
8422 Error Err = Error::success();
8423 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8424 auto ToType = importChecked(Err, E->getType());
8425 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8426 if (Err)
8427 return std::move(Err);
8428
8429 return new (Importer.getToContext()) CXXThrowExpr(
8430 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8431}
8432
8434 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8435 if (!ToUsedLocOrErr)
8436 return ToUsedLocOrErr.takeError();
8437
8438 auto ToParamOrErr = import(E->getParam());
8439 if (!ToParamOrErr)
8440 return ToParamOrErr.takeError();
8441
8442 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8443 if (!UsedContextOrErr)
8444 return UsedContextOrErr.takeError();
8445
8446 // Import the default arg if it was not imported yet.
8447 // This is needed because it can happen that during the import of the
8448 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8449 // encountered here. The default argument for a ParmVarDecl is set in the
8450 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8451 // see VisitParmVarDecl).
8452 ParmVarDecl *ToParam = *ToParamOrErr;
8453 if (!ToParam->getDefaultArg()) {
8454 std::optional<ParmVarDecl *> FromParam =
8455 Importer.getImportedFromDecl(ToParam);
8456 assert(FromParam && "ParmVarDecl was not imported?");
8457
8458 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8459 return std::move(Err);
8460 }
8461 Expr *RewrittenInit = nullptr;
8462 if (E->hasRewrittenInit()) {
8463 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8464 if (!ExprOrErr)
8465 return ExprOrErr.takeError();
8466 RewrittenInit = ExprOrErr.get();
8467 }
8468 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8469 *ToParamOrErr, RewrittenInit,
8470 *UsedContextOrErr);
8471}
8472
8475 Error Err = Error::success();
8476 auto ToType = importChecked(Err, E->getType());
8477 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8478 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8479 if (Err)
8480 return std::move(Err);
8481
8482 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8483 ToType, ToTypeSourceInfo, ToRParenLoc);
8484}
8485
8488 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8489 if (!ToSubExprOrErr)
8490 return ToSubExprOrErr.takeError();
8491
8492 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8493 if (!ToDtorOrErr)
8494 return ToDtorOrErr.takeError();
8495
8496 ASTContext &ToCtx = Importer.getToContext();
8497 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8498 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8499}
8500
8502
8504 Error Err = Error::success();
8505 auto ToConstructor = importChecked(Err, E->getConstructor());
8506 auto ToType = importChecked(Err, E->getType());
8507 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8508 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8509 if (Err)
8510 return std::move(Err);
8511
8513 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8514 return std::move(Err);
8515
8517 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8518 ToParenOrBraceRange, E->hadMultipleCandidates(),
8521}
8522
8525 DeclContext *DC, *LexicalDC;
8526 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8527 return std::move(Err);
8528
8529 Error Err = Error::success();
8530 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8531 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8532 if (Err)
8533 return std::move(Err);
8534 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8535
8537 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8538 D->getManglingNumber()))
8539 return To;
8540
8541 To->setLexicalDeclContext(LexicalDC);
8542 LexicalDC->addDeclInternal(To);
8543 return To;
8544}
8545
8548 Error Err = Error::success();
8549 auto ToType = importChecked(Err, E->getType());
8550 Expr *ToTemporaryExpr = importChecked(
8551 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8552 auto ToMaterializedDecl =
8554 if (Err)
8555 return std::move(Err);
8556
8557 if (!ToTemporaryExpr)
8558 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8559
8560 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8561 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8562 ToMaterializedDecl);
8563
8564 return ToMTE;
8565}
8566
8568 Error Err = Error::success();
8569 auto *ToPattern = importChecked(Err, E->getPattern());
8570 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8571 if (Err)
8572 return std::move(Err);
8573
8574 return new (Importer.getToContext())
8575 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8576}
8577
8579 Error Err = Error::success();
8580 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8581 auto ToPack = importChecked(Err, E->getPack());
8582 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8583 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8584 if (Err)
8585 return std::move(Err);
8586
8587 UnsignedOrNone Length = std::nullopt;
8588 if (!E->isValueDependent())
8589 Length = E->getPackLength();
8590
8591 SmallVector<TemplateArgument, 8> ToPartialArguments;
8592 if (E->isPartiallySubstituted()) {
8594 ToPartialArguments))
8595 return std::move(Err);
8596 }
8597
8599 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8600 Length, ToPartialArguments);
8601}
8602
8603
8605 Error Err = Error::success();
8606 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8607 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8608 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8609 auto ToArraySize = importChecked(Err, E->getArraySize());
8610 auto ToInitializer = importChecked(Err, E->getInitializer());
8611 auto ToType = importChecked(Err, E->getType());
8612 auto ToAllocatedTypeSourceInfo =
8614 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8615 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8616 if (Err)
8617 return std::move(Err);
8618
8619 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8620 if (Error Err =
8621 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8622 return std::move(Err);
8623
8624 return CXXNewExpr::Create(
8625 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8626 ToOperatorDelete, E->implicitAllocationParameters(),
8627 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8628 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8629 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8630}
8631
8633 Error Err = Error::success();
8634 auto ToType = importChecked(Err, E->getType());
8635 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8636 auto ToArgument = importChecked(Err, E->getArgument());
8637 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8638 if (Err)
8639 return std::move(Err);
8640
8641 return new (Importer.getToContext()) CXXDeleteExpr(
8642 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8643 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8644 ToBeginLoc);
8645}
8646
8648 Error Err = Error::success();
8649 auto ToType = importChecked(Err, E->getType());
8650 auto ToLocation = importChecked(Err, E->getLocation());
8651 auto ToConstructor = importChecked(Err, E->getConstructor());
8652 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8653 if (Err)
8654 return std::move(Err);
8655
8657 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8658 return std::move(Err);
8659
8661 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8662 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8665 ToParenOrBraceRange);
8667 return ToE;
8668}
8669
8671 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8672 if (!ToSubExprOrErr)
8673 return ToSubExprOrErr.takeError();
8674
8676 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8677 return std::move(Err);
8678
8680 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8681 ToObjects);
8682}
8683
8685 Error Err = Error::success();
8686 auto ToCallee = importChecked(Err, E->getCallee());
8687 auto ToType = importChecked(Err, E->getType());
8688 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8689 if (Err)
8690 return std::move(Err);
8691
8693 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8694 return std::move(Err);
8695
8696 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8697 ToType, E->getValueKind(), ToRParenLoc,
8698 E->getFPFeatures());
8699}
8700
8702 ExpectedType ToTypeOrErr = import(E->getType());
8703 if (!ToTypeOrErr)
8704 return ToTypeOrErr.takeError();
8705
8706 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8707 if (!ToLocationOrErr)
8708 return ToLocationOrErr.takeError();
8709
8710 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8711 *ToTypeOrErr, E->isImplicit());
8712}
8713
8715 ExpectedType ToTypeOrErr = import(E->getType());
8716 if (!ToTypeOrErr)
8717 return ToTypeOrErr.takeError();
8718
8719 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8720 if (!ToLocationOrErr)
8721 return ToLocationOrErr.takeError();
8722
8723 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8724 *ToTypeOrErr, *ToLocationOrErr);
8725}
8726
8728 Error Err = Error::success();
8729 auto ToBase = importChecked(Err, E->getBase());
8730 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8731 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8732 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8733 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8734 auto ToType = importChecked(Err, E->getType());
8735 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8736 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8737 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8738 if (Err)
8739 return std::move(Err);
8740
8741 DeclAccessPair ToFoundDecl =
8743
8744 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8745
8746 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8747 if (E->hasExplicitTemplateArgs()) {
8748 if (Error Err =
8750 E->template_arguments(), ToTAInfo))
8751 return std::move(Err);
8752 ResInfo = &ToTAInfo;
8753 }
8754
8755 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8756 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8757 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8758 ResInfo, ToType, E->getValueKind(),
8759 E->getObjectKind(), E->isNonOdrUse());
8760}
8761
8764 Error Err = Error::success();
8765 auto ToBase = importChecked(Err, E->getBase());
8766 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8767 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8768 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8769 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8770 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8771 if (Err)
8772 return std::move(Err);
8773
8775 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8776 const IdentifierInfo *ToII = Importer.Import(FromII);
8777 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8778 if (!ToDestroyedTypeLocOrErr)
8779 return ToDestroyedTypeLocOrErr.takeError();
8780 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8781 } else {
8782 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8783 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8784 else
8785 return ToTIOrErr.takeError();
8786 }
8787
8788 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8789 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8790 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8791}
8792
8795 Error Err = Error::success();
8796 auto ToType = importChecked(Err, E->getType());
8797 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8798 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8799 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8800 auto ToFirstQualifierFoundInScope =
8802 if (Err)
8803 return std::move(Err);
8804
8805 Expr *ToBase = nullptr;
8806 if (!E->isImplicitAccess()) {
8807 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8808 ToBase = *ToBaseOrErr;
8809 else
8810 return ToBaseOrErr.takeError();
8811 }
8812
8813 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8814
8815 if (E->hasExplicitTemplateArgs()) {
8816 if (Error Err =
8818 E->template_arguments(), ToTAInfo))
8819 return std::move(Err);
8820 ResInfo = &ToTAInfo;
8821 }
8822 auto ToMember = importChecked(Err, E->getMember());
8823 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8824 if (Err)
8825 return std::move(Err);
8826 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8827
8828 // Import additional name location/type info.
8829 if (Error Err =
8830 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8831 return std::move(Err);
8832
8834 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8835 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8836 ToMemberNameInfo, ResInfo);
8837}
8838
8841 Error Err = Error::success();
8842 auto ToName = importChecked(Err, E->getTemplateName());
8843 auto ToDeclName = importChecked(Err, E->getName());
8844 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8845 if (Err)
8846 return std::move(Err);
8847
8848 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8849 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8850 return std::move(Err);
8851
8852 TemplateArgumentListInfo ToTAInfo;
8853 if (Error Err =
8855 E->template_arguments(), ToTAInfo))
8856 return std::move(Err);
8857
8858 return DependentTemplateIdExpr::Create(Importer.getToContext(), ToNameInfo,
8859 ToName, ToTAInfo);
8860}
8861
8864 Error Err = Error::success();
8865 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8866 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8867 auto ToDeclName = importChecked(Err, E->getDeclName());
8868 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8869 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8870 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8871 if (Err)
8872 return std::move(Err);
8873
8874 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8875 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8876 return std::move(Err);
8877
8878 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8879 TemplateArgumentListInfo *ResInfo = nullptr;
8880 if (E->hasExplicitTemplateArgs()) {
8881 if (Error Err =
8883 return std::move(Err);
8884 ResInfo = &ToTAInfo;
8885 }
8886
8888 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8889 ToNameInfo, ResInfo);
8890}
8891
8894 Error Err = Error::success();
8895 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8896 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8897 auto ToType = importChecked(Err, E->getType());
8898 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8899 if (Err)
8900 return std::move(Err);
8901
8903 if (Error Err =
8904 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8905 return std::move(Err);
8906
8908 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8909 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8910}
8911
8914 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8915 if (!ToNamingClassOrErr)
8916 return ToNamingClassOrErr.takeError();
8917
8918 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8919 if (!ToQualifierLocOrErr)
8920 return ToQualifierLocOrErr.takeError();
8921
8922 Error Err = Error::success();
8923 auto ToName = importChecked(Err, E->getName());
8924 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8925 if (Err)
8926 return std::move(Err);
8927 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8928
8929 // Import additional name location/type info.
8930 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8931 return std::move(Err);
8932
8933 UnresolvedSet<8> ToDecls;
8934 for (auto *D : E->decls())
8935 if (auto ToDOrErr = import(D))
8936 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8937 else
8938 return ToDOrErr.takeError();
8939
8940 if (E->hasExplicitTemplateArgs()) {
8941 TemplateArgumentListInfo ToTAInfo;
8944 ToTAInfo))
8945 return std::move(Err);
8946
8947 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8948 if (!ToTemplateKeywordLocOrErr)
8949 return ToTemplateKeywordLocOrErr.takeError();
8950
8951 const bool KnownDependent =
8952 (E->getDependence() & ExprDependence::TypeValue) ==
8953 ExprDependence::TypeValue;
8955 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8956 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8957 ToDecls.begin(), ToDecls.end(), KnownDependent,
8958 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8959 }
8960
8962 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8963 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8964 /*KnownDependent=*/E->isTypeDependent(),
8965 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8966}
8967
8970 Error Err = Error::success();
8971 auto ToType = importChecked(Err, E->getType());
8972 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8973 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8974 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8975 auto ToName = importChecked(Err, E->getName());
8976 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8977 if (Err)
8978 return std::move(Err);
8979
8980 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8981 // Import additional name location/type info.
8982 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8983 return std::move(Err);
8984
8985 UnresolvedSet<8> ToDecls;
8986 for (Decl *D : E->decls())
8987 if (auto ToDOrErr = import(D))
8988 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8989 else
8990 return ToDOrErr.takeError();
8991
8992 TemplateArgumentListInfo ToTAInfo;
8993 TemplateArgumentListInfo *ResInfo = nullptr;
8994 if (E->hasExplicitTemplateArgs()) {
8995 TemplateArgumentListInfo FromTAInfo;
8996 E->copyTemplateArgumentsInto(FromTAInfo);
8997 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8998 return std::move(Err);
8999 ResInfo = &ToTAInfo;
9000 }
9001
9002 Expr *ToBase = nullptr;
9003 if (!E->isImplicitAccess()) {
9004 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
9005 ToBase = *ToBaseOrErr;
9006 else
9007 return ToBaseOrErr.takeError();
9008 }
9009
9011 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
9012 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
9013 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
9014}
9015
9017 Error Err = Error::success();
9018 auto ToCallee = importChecked(Err, E->getCallee());
9019 auto ToType = importChecked(Err, E->getType());
9020 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9021 if (Err)
9022 return std::move(Err);
9023
9024 unsigned NumArgs = E->getNumArgs();
9025 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
9026 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
9027 return std::move(Err);
9028
9029 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
9031 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
9032 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
9033 OCE->getADLCallKind());
9034 }
9035
9036 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
9037 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
9038 /*MinNumArgs=*/0, E->getADLCallKind());
9039}
9040
9042 CXXRecordDecl *FromClass = E->getLambdaClass();
9043 auto ToClassOrErr = import(FromClass);
9044 if (!ToClassOrErr)
9045 return ToClassOrErr.takeError();
9046 CXXRecordDecl *ToClass = *ToClassOrErr;
9047
9048 auto ToCallOpOrErr = import(E->getCallOperator());
9049 if (!ToCallOpOrErr)
9050 return ToCallOpOrErr.takeError();
9051
9052 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
9053 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
9054 return std::move(Err);
9055
9056 Error Err = Error::success();
9057 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
9058 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
9059 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9060 if (Err)
9061 return std::move(Err);
9062
9063 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
9064 E->getCaptureDefault(), ToCaptureDefaultLoc,
9066 E->hasExplicitResultType(), ToCaptureInits,
9067 ToEndLoc, E->containsUnexpandedParameterPack());
9068}
9069
9070
9072 Error Err = Error::success();
9073 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
9074 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
9075 auto ToType = importChecked(Err, E->getType());
9076 if (Err)
9077 return std::move(Err);
9078
9079 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
9080 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
9081 return std::move(Err);
9082
9083 ASTContext &ToCtx = Importer.getToContext();
9084 InitListExpr *To = new (ToCtx)
9085 InitListExpr(ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc, E->isExplicit());
9086 To->setType(ToType);
9087
9088 if (E->hasArrayFiller()) {
9089 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9090 To->setArrayFiller(*ToFillerOrErr);
9091 else
9092 return ToFillerOrErr.takeError();
9093 }
9094
9095 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9096 if (auto ToFDOrErr = import(FromFD))
9097 To->setInitializedFieldInUnion(*ToFDOrErr);
9098 else
9099 return ToFDOrErr.takeError();
9100 }
9101
9102 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9103 if (auto ToSyntFormOrErr = import(SyntForm))
9104 To->setSyntacticForm(*ToSyntFormOrErr);
9105 else
9106 return ToSyntFormOrErr.takeError();
9107 }
9108
9109 // Copy InitListExprBitfields, which are not handled in the ctor of
9110 // InitListExpr.
9112
9113 return To;
9114}
9115
9118 ExpectedType ToTypeOrErr = import(E->getType());
9119 if (!ToTypeOrErr)
9120 return ToTypeOrErr.takeError();
9121
9122 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9123 if (!ToSubExprOrErr)
9124 return ToSubExprOrErr.takeError();
9125
9126 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9127 *ToTypeOrErr, *ToSubExprOrErr);
9128}
9129
9132 Error Err = Error::success();
9133 auto ToLocation = importChecked(Err, E->getLocation());
9134 auto ToType = importChecked(Err, E->getType());
9135 auto ToConstructor = importChecked(Err, E->getConstructor());
9136 if (Err)
9137 return std::move(Err);
9138
9139 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9140 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9141 E->inheritedFromVBase());
9142}
9143
9145 Error Err = Error::success();
9146 auto ToType = importChecked(Err, E->getType());
9147 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9148 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9149 if (Err)
9150 return std::move(Err);
9151
9152 return new (Importer.getToContext()) ArrayInitLoopExpr(
9153 ToType, ToCommonExpr, ToSubExpr);
9154}
9155
9157 ExpectedType ToTypeOrErr = import(E->getType());
9158 if (!ToTypeOrErr)
9159 return ToTypeOrErr.takeError();
9160 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9161}
9162
9164 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9165 if (!ToBeginLocOrErr)
9166 return ToBeginLocOrErr.takeError();
9167
9168 auto ToFieldOrErr = import(E->getField());
9169 if (!ToFieldOrErr)
9170 return ToFieldOrErr.takeError();
9171
9172 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9173 if (!UsedContextOrErr)
9174 return UsedContextOrErr.takeError();
9175
9176 FieldDecl *ToField = *ToFieldOrErr;
9177 assert(ToField->hasInClassInitializer() &&
9178 "Field should have in-class initializer if there is a default init "
9179 "expression that uses it.");
9180 if (!ToField->getInClassInitializer()) {
9181 // The in-class initializer may be not yet set in "To" AST even if the
9182 // field is already there. This must be set here to make construction of
9183 // CXXDefaultInitExpr work.
9184 auto ToInClassInitializerOrErr =
9185 import(E->getField()->getInClassInitializer());
9186 if (!ToInClassInitializerOrErr)
9187 return ToInClassInitializerOrErr.takeError();
9188 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9189 }
9190
9191 Expr *RewrittenInit = nullptr;
9192 if (E->hasRewrittenInit()) {
9193 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9194 if (!ExprOrErr)
9195 return ExprOrErr.takeError();
9196 RewrittenInit = ExprOrErr.get();
9197 }
9198
9199 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9200 ToField, *UsedContextOrErr, RewrittenInit);
9201}
9202
9204 Error Err = Error::success();
9205 auto ToType = importChecked(Err, E->getType());
9206 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9207 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9208 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9209 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9210 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9211 if (Err)
9212 return std::move(Err);
9213
9215 CastKind CK = E->getCastKind();
9216 auto ToBasePathOrErr = ImportCastPath(E);
9217 if (!ToBasePathOrErr)
9218 return ToBasePathOrErr.takeError();
9219
9220 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9222 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9223 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9224 ToAngleBrackets);
9225 } else if (isa<CXXDynamicCastExpr>(E)) {
9227 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9228 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9229 } else if (isa<CXXReinterpretCastExpr>(E)) {
9231 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9232 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9233 } else if (isa<CXXConstCastExpr>(E)) {
9235 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9236 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9237 } else {
9238 llvm_unreachable("Unknown cast type");
9239 return make_error<ASTImportError>();
9240 }
9241}
9242
9245 Error Err = Error::success();
9246 auto ToType = importChecked(Err, E->getType());
9247 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9248 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9249 auto ToParamType = importChecked(Err, E->getParameterType());
9250 auto ToReplacement = importChecked(Err, E->getReplacement());
9251 if (Err)
9252 return std::move(Err);
9253
9254 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9255 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9256 ToParamType, E->getIndex(), E->getPackIndex(), E->getFinal());
9257}
9258
9260 Error Err = Error::success();
9261 auto ToType = importChecked(Err, E->getType());
9262 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9263 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9264 if (Err)
9265 return std::move(Err);
9266
9268 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9269 return std::move(Err);
9270
9271 if (E->isStoredAsBoolean()) {
9272 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9273 // Value is always false.
9274 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9275 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9276 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9277 }
9278 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9279 E->getTrait(), ToArgs, ToEndLoc,
9280 E->getAPValue());
9281}
9282
9284 ExpectedType ToTypeOrErr = import(E->getType());
9285 if (!ToTypeOrErr)
9286 return ToTypeOrErr.takeError();
9287
9288 auto ToSourceRangeOrErr = import(E->getSourceRange());
9289 if (!ToSourceRangeOrErr)
9290 return ToSourceRangeOrErr.takeError();
9291
9292 if (E->isTypeOperand()) {
9293 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9294 return new (Importer.getToContext()) CXXTypeidExpr(
9295 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9296 else
9297 return ToTSIOrErr.takeError();
9298 }
9299
9300 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9301 if (!ToExprOperandOrErr)
9302 return ToExprOperandOrErr.takeError();
9303
9304 return new (Importer.getToContext()) CXXTypeidExpr(
9305 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9306}
9307
9309 Error Err = Error::success();
9310
9311 QualType ToType = importChecked(Err, E->getType());
9312 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9313 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9314 Expr *ToLHS = importChecked(Err, E->getLHS());
9315 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9316 Expr *ToRHS = importChecked(Err, E->getRHS());
9317 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9318
9319 if (Err)
9320 return std::move(Err);
9321
9322 return new (Importer.getToContext())
9323 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9324 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9325}
9326
9328 Error Err = Error::success();
9329 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9330 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9331 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9332
9333 auto Body = importChecked(Err, E->getBody());
9334 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9335 if (Err)
9336 return std::move(Err);
9337 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9338 if (Error Err =
9339 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9340 return std::move(Err);
9342 E->getRequirements().size());
9343 if (Error Err =
9344 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9345 return std::move(Err);
9346 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9347 LParenLoc, LocalParameters, RParenLoc,
9348 Requirements, RBraceLoc);
9349}
9350
9353 Error Err = Error::success();
9354 auto CL = importChecked(Err, E->getConceptReference());
9355 auto CSD = importChecked(Err, E->getSpecializationDecl());
9356 if (Err)
9357 return std::move(Err);
9358 if (E->isValueDependent())
9360 Importer.getToContext(), CL,
9361 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9362 ConstraintSatisfaction Satisfaction;
9363 if (Error Err =
9365 return std::move(Err);
9367 Importer.getToContext(), CL,
9368 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9369}
9370
9373 Error Err = Error::success();
9374 auto ToType = importChecked(Err, E->getType());
9375 auto ToPackLoc = importChecked(Err, E->getParameterPackLocation());
9376 auto ToArgPack = importChecked(Err, E->getArgumentPack());
9377 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9378 if (Err)
9379 return std::move(Err);
9380
9381 return new (Importer.getToContext()) SubstNonTypeTemplateParmPackExpr(
9382 ToType, E->getValueKind(), ToPackLoc, ToArgPack, ToAssociatedDecl,
9383 E->getIndex(), E->getFinal());
9384}
9385
9388 if (Error Err = ImportContainerChecked(E->semantics(), ToSemantics))
9389 return std::move(Err);
9390 auto ToSyntOrErr = import(E->getSyntacticForm());
9391 if (!ToSyntOrErr)
9392 return ToSyntOrErr.takeError();
9393 return PseudoObjectExpr::Create(Importer.getToContext(), *ToSyntOrErr,
9394 ToSemantics, E->getResultExprIndex());
9395}
9396
9399 Error Err = Error::success();
9400 auto ToType = importChecked(Err, E->getType());
9401 auto ToInitLoc = importChecked(Err, E->getInitLoc());
9402 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9403 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9404 if (Err)
9405 return std::move(Err);
9406
9407 SmallVector<Expr *, 4> ToArgs(E->getInitExprs().size());
9408 if (Error Err = ImportContainerChecked(E->getInitExprs(), ToArgs))
9409 return std::move(Err);
9410 return CXXParenListInitExpr::Create(Importer.getToContext(), ToArgs, ToType,
9411 E->getUserSpecifiedInitExprs().size(),
9412 ToInitLoc, ToBeginLoc, ToEndLoc);
9413}
9414
9417 Error Err = Error::success();
9418 auto ToRange = importChecked(Err, E->getRangeExpr());
9419 auto ToIndex = importChecked(Err, E->getIndexExpr());
9420 if (Err)
9421 return std::move(Err);
9422
9423 return new (Importer.getToContext())
9424 CXXExpansionSelectExpr(Importer.getToContext(), ToRange, ToIndex);
9425}
9426
9428 CXXMethodDecl *FromMethod) {
9429 Error ImportErrors = Error::success();
9430 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9431 if (auto ImportedOrErr = import(FromOverriddenMethod))
9433 (*ImportedOrErr)->getCanonicalDecl()));
9434 else
9435 ImportErrors =
9436 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9437 }
9438 return ImportErrors;
9439}
9440
9442 ASTContext &FromContext, FileManager &FromFileManager,
9443 bool MinimalImport,
9444 std::shared_ptr<ASTImporterSharedState> SharedState)
9445 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9446 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9447 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9448
9449 // Create a default state without the lookup table: LLDB case.
9450 if (!SharedState) {
9451 this->SharedState = std::make_shared<ASTImporterSharedState>();
9452 }
9453
9454 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9455 ToContext.getTranslationUnitDecl();
9456}
9457
9458ASTImporter::~ASTImporter() = default;
9459
9461 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9462 "Try to get field index for non-field.");
9463
9464 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9465 if (!Owner)
9466 return std::nullopt;
9467
9468 unsigned Index = 0;
9469 for (const auto *D : Owner->decls()) {
9470 if (D == F)
9471 return Index;
9472
9474 ++Index;
9475 }
9476
9477 llvm_unreachable("Field was not found in its parent context.");
9478
9479 return std::nullopt;
9480}
9481
9482ASTImporter::FoundDeclsTy
9483ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9484 // We search in the redecl context because of transparent contexts.
9485 // E.g. a simple C language enum is a transparent context:
9486 // enum E { A, B };
9487 // Now if we had a global variable in the TU
9488 // int A;
9489 // then the enum constant 'A' and the variable 'A' violates ODR.
9490 // We can diagnose this only if we search in the redecl context.
9491 DeclContext *ReDC = DC->getRedeclContext();
9492 if (SharedState->getLookupTable()) {
9493 if (ReDC->isNamespace()) {
9494 // Namespaces can be reopened.
9495 // Lookup table does not handle this, we must search here in all linked
9496 // namespaces.
9497 FoundDeclsTy Result;
9498 SmallVector<Decl *, 2> NSChain =
9500 dyn_cast<NamespaceDecl>(ReDC));
9501 for (auto *D : NSChain) {
9503 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9504 Name);
9506 }
9507 return Result;
9508 } else {
9510 SharedState->getLookupTable()->lookup(ReDC, Name);
9511 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9512 }
9513 } else {
9514 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9515 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9516 // We must search by the slow case of localUncachedLookup because that is
9517 // working even if there is no LookupPtr for the DC. We could use
9518 // DC::buildLookup() to create the LookupPtr, but that would load external
9519 // decls again, we must avoid that case.
9520 // Also, even if we had the LookupPtr, we must find Decls which are not
9521 // in the LookupPtr, so we need the slow case.
9522 // These cases are handled in ASTImporterLookupTable, but we cannot use
9523 // that with LLDB since that traverses through the AST which initiates the
9524 // load of external decls again via DC::decls(). And again, we must avoid
9525 // loading external decls during the import.
9526 if (Result.empty())
9527 ReDC->localUncachedLookup(Name, Result);
9528 return Result;
9529 }
9530}
9531
9532void ASTImporter::AddToLookupTable(Decl *ToD) {
9533 SharedState->addDeclToLookup(ToD);
9534}
9535
9537 // Import the decl using ASTNodeImporter.
9538 ASTNodeImporter Importer(*this);
9539 return Importer.Visit(FromD);
9540}
9541
9543 MapImported(FromD, ToD);
9544}
9545
9548 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9549 if (Expected<Expr *> R = Import(CLE))
9551 }
9552
9553 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9554 // ASTNodeImporter.
9555 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9556}
9557
9559 if (!FromT)
9560 return FromT;
9561
9562 // Check whether we've already imported this type.
9563 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9564 ImportedTypes.find(FromT);
9565 if (Pos != ImportedTypes.end())
9566 return Pos->second;
9567
9568 // Import the type.
9569 ASTNodeImporter Importer(*this);
9570 ExpectedType ToTOrErr = Importer.Visit(FromT);
9571 if (!ToTOrErr)
9572 return ToTOrErr.takeError();
9573
9574 // Record the imported type.
9575 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9576
9577 return ToTOrErr->getTypePtr();
9578}
9579
9581 if (FromT.isNull())
9582 return QualType{};
9583
9584 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9585 if (!ToTyOrErr)
9586 return ToTyOrErr.takeError();
9587
9588 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9589}
9590
9592 if (!FromTSI)
9593 return FromTSI;
9594
9595 // FIXME: For now we just create a "trivial" type source info based
9596 // on the type and a single location. Implement a real version of this.
9597 ExpectedType TOrErr = Import(FromTSI->getType());
9598 if (!TOrErr)
9599 return TOrErr.takeError();
9600 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9601 if (!BeginLocOrErr)
9602 return BeginLocOrErr.takeError();
9603
9604 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9605}
9606
9607namespace {
9608// To use this object, it should be created before the new attribute is created,
9609// and destructed after it is created. The construction already performs the
9610// import of the data.
9611template <typename T> struct AttrArgImporter {
9612 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9613 AttrArgImporter(AttrArgImporter<T> &&) = default;
9614 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9615 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9616
9617 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9618 : To(I.importChecked(Err, From)) {}
9619
9620 const T &value() { return To; }
9621
9622private:
9623 T To;
9624};
9625
9626// To use this object, it should be created before the new attribute is created,
9627// and destructed after it is created. The construction already performs the
9628// import of the data. The array data is accessible in a pointer form, this form
9629// is used by the attribute classes. This object should be created once for the
9630// array data to be imported (the array size is not imported, just copied).
9631template <typename T> struct AttrArgArrayImporter {
9632 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9633 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9634 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9635 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9636
9637 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9638 const llvm::iterator_range<T *> &From,
9639 unsigned ArraySize) {
9640 if (Err)
9641 return;
9642 To.reserve(ArraySize);
9643 Err = I.ImportContainerChecked(From, To);
9644 }
9645
9646 T *value() { return To.data(); }
9647
9648private:
9649 llvm::SmallVector<T, 2> To;
9650};
9651
9652class AttrImporter {
9653 Error Err{Error::success()};
9654 Attr *ToAttr = nullptr;
9655 ASTImporter &Importer;
9656 ASTNodeImporter NImporter;
9657
9658public:
9659 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9660
9661 // Create an "importer" for an attribute parameter.
9662 // Result of the 'value()' of that object is to be passed to the function
9663 // 'importAttr', in the order that is expected by the attribute class.
9664 template <class T> AttrArgImporter<T> importArg(const T &From) {
9665 return AttrArgImporter<T>(NImporter, Err, From);
9666 }
9667
9668 // Create an "importer" for an attribute parameter that has array type.
9669 // Result of the 'value()' of that object is to be passed to the function
9670 // 'importAttr', then the size of the array as next argument.
9671 template <typename T>
9672 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9673 unsigned ArraySize) {
9674 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9675 }
9676
9677 // Create an attribute object with the specified arguments.
9678 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9679 // should be values that are passed to the 'Create' function of the attribute.
9680 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9681 // used here.) As much data is copied or imported from the old attribute
9682 // as possible. The passed arguments should be already imported.
9683 // If an import error happens, the internal error is set to it, and any
9684 // further import attempt is ignored.
9685 template <typename T, typename... Arg>
9686 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9687 static_assert(std::is_base_of<Attr, T>::value,
9688 "T should be subclass of Attr.");
9689 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9690
9691 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9692 const IdentifierInfo *ToScopeName =
9693 Importer.Import(FromAttr->getScopeName());
9694 SourceRange ToAttrRange =
9695 NImporter.importChecked(Err, FromAttr->getRange());
9696 SourceLocation ToScopeLoc =
9697 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9698
9699 if (Err)
9700 return;
9701
9702 AttributeCommonInfo ToI(
9703 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9704 FromAttr->getParsedKind(), FromAttr->getForm());
9705 // The "SemanticSpelling" is not needed to be passed to the constructor.
9706 // That value is recalculated from the SpellingListIndex if needed.
9707 ToAttr = T::Create(Importer.getToContext(),
9708 std::forward<Arg>(ImportedArg)..., ToI);
9709
9710 ToAttr->setImplicit(FromAttr->isImplicit());
9711 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9712 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9713 ToInheritableAttr->setInherited(FromAttr->isInherited());
9714 }
9715
9716 // Create a clone of the 'FromAttr' and import its source range only.
9717 // This causes objects with invalid references to be created if the 'FromAttr'
9718 // contains other data that should be imported.
9719 void cloneAttr(const Attr *FromAttr) {
9720 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9721
9722 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9723 if (Err)
9724 return;
9725
9726 ToAttr = FromAttr->clone(Importer.getToContext());
9727 ToAttr->setRange(ToRange);
9728 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9729 }
9730
9731 // Get the result of the previous import attempt (can be used only once).
9732 llvm::Expected<Attr *> getResult() && {
9733 if (Err)
9734 return std::move(Err);
9735 assert(ToAttr && "Attribute should be created.");
9736 return ToAttr;
9737 }
9738};
9739} // namespace
9740
9742 AttrImporter AI(*this);
9743
9744 // FIXME: Is there some kind of AttrVisitor to use here?
9745 switch (FromAttr->getKind()) {
9746 case attr::Aligned: {
9747 auto *From = cast<AlignedAttr>(FromAttr);
9748 if (From->isAlignmentExpr())
9749 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9750 else
9751 AI.importAttr(From, false,
9752 AI.importArg(From->getAlignmentType()).value());
9753 break;
9754 }
9755
9756 case attr::AlignValue: {
9757 auto *From = cast<AlignValueAttr>(FromAttr);
9758 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9759 break;
9760 }
9761
9762 case attr::Format: {
9763 const auto *From = cast<FormatAttr>(FromAttr);
9764 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9765 From->getFirstArg());
9766 break;
9767 }
9768
9769 case attr::EnableIf: {
9770 const auto *From = cast<EnableIfAttr>(FromAttr);
9771 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9772 From->getMessage());
9773 break;
9774 }
9775
9776 case attr::AssertCapability: {
9777 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9778 AI.importAttr(From,
9779 AI.importArrayArg(From->args(), From->args_size()).value(),
9780 From->args_size());
9781 break;
9782 }
9783 case attr::AcquireCapability: {
9784 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9785 AI.importAttr(From,
9786 AI.importArrayArg(From->args(), From->args_size()).value(),
9787 From->args_size());
9788 break;
9789 }
9790 case attr::TryAcquireCapability: {
9791 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9792 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9793 AI.importArrayArg(From->args(), From->args_size()).value(),
9794 From->args_size());
9795 break;
9796 }
9797 case attr::ReleaseCapability: {
9798 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9799 AI.importAttr(From,
9800 AI.importArrayArg(From->args(), From->args_size()).value(),
9801 From->args_size());
9802 break;
9803 }
9804 case attr::RequiresCapability: {
9805 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9806 AI.importAttr(From,
9807 AI.importArrayArg(From->args(), From->args_size()).value(),
9808 From->args_size());
9809 break;
9810 }
9811 case attr::GuardedBy: {
9812 const auto *From = cast<GuardedByAttr>(FromAttr);
9813 AI.importAttr(From,
9814 AI.importArrayArg(From->args(), From->args_size()).value(),
9815 From->args_size());
9816 break;
9817 }
9818 case attr::PtGuardedBy: {
9819 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9820 AI.importAttr(From,
9821 AI.importArrayArg(From->args(), From->args_size()).value(),
9822 From->args_size());
9823 break;
9824 }
9825 case attr::AcquiredAfter: {
9826 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9827 AI.importAttr(From,
9828 AI.importArrayArg(From->args(), From->args_size()).value(),
9829 From->args_size());
9830 break;
9831 }
9832 case attr::AcquiredBefore: {
9833 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9834 AI.importAttr(From,
9835 AI.importArrayArg(From->args(), From->args_size()).value(),
9836 From->args_size());
9837 break;
9838 }
9839 case attr::LockReturned: {
9840 const auto *From = cast<LockReturnedAttr>(FromAttr);
9841 AI.importAttr(From, AI.importArg(From->getArg()).value());
9842 break;
9843 }
9844 case attr::LocksExcluded: {
9845 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9846 AI.importAttr(From,
9847 AI.importArrayArg(From->args(), From->args_size()).value(),
9848 From->args_size());
9849 break;
9850 }
9851 default: {
9852 // The default branch works for attributes that have no arguments to import.
9853 // FIXME: Handle every attribute type that has arguments of type to import
9854 // (most often Expr* or Decl* or type) in the switch above.
9855 AI.cloneAttr(FromAttr);
9856 break;
9857 }
9858 }
9859
9860 return std::move(AI).getResult();
9861}
9862
9864 return ImportedDecls.lookup(FromD);
9865}
9866
9868 auto FromDPos = ImportedFromDecls.find(ToD);
9869 if (FromDPos == ImportedFromDecls.end())
9870 return nullptr;
9871 return FromDPos->second->getTranslationUnitDecl();
9872}
9873
9875 if (!FromD)
9876 return nullptr;
9877
9878 // Push FromD to the stack, and remove that when we return.
9879 ImportPath.push(FromD);
9880 llvm::scope_exit ImportPathBuilder([this]() { ImportPath.pop(); });
9881
9882 // Check whether there was a previous failed import.
9883 // If yes return the existing error.
9884 if (auto Error = getImportDeclErrorIfAny(FromD))
9885 return make_error<ASTImportError>(*Error);
9886
9887 // Check whether we've already imported this declaration.
9888 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9889 if (ToD) {
9890 // Already imported (possibly from another TU) and with an error.
9891 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9892 setImportDeclError(FromD, *Error);
9893 return make_error<ASTImportError>(*Error);
9894 }
9895
9896 // If FromD has some updated flags after last import, apply it.
9897 updateFlags(FromD, ToD);
9898 // If we encounter a cycle during an import then we save the relevant part
9899 // of the import path associated to the Decl.
9900 if (ImportPath.hasCycleAtBack())
9901 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9902 return ToD;
9903 }
9904
9905 // Import the declaration.
9906 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9907 if (!ToDOrErr) {
9908 // Failed to import.
9909
9910 auto Pos = ImportedDecls.find(FromD);
9911 bool ToDWasCreated = Pos != ImportedDecls.end();
9912 // Capture the mapped decl before erasing: the iterator is invalidated by
9913 // the erase below under backward-shift deletion, but it is still needed
9914 // further down to record the import error.
9915 Decl *CreatedToD = ToDWasCreated ? Pos->second : nullptr;
9916 if (ToDWasCreated) {
9917 // Import failed after the object was created.
9918 // Remove all references to it.
9919 auto *ToD = CreatedToD;
9920 ImportedDecls.erase(Pos);
9921
9922 // Remove the imported type mapping as well.
9923 // The imported type can point to a declaration that failed to import
9924 // later.
9925 if (const auto *FromTD = dyn_cast<TagDecl>(FromD)) {
9926 if (const Type *FromTy =
9927 getFromContext().getCanonicalTagType(FromTD).getTypePtr()) {
9928 ImportedTypes.erase(FromTy);
9929 }
9930 }
9931
9932 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9933 // (e.g. with namespaces) that several decls from the 'from' context are
9934 // mapped to the same decl in the 'to' context. If we removed entries
9935 // from the LookupTable here then we may end up removing them multiple
9936 // times.
9937
9938 // The Lookuptable contains decls only which are in the 'to' context.
9939 // Remove from the Lookuptable only if it is *imported* into the 'to'
9940 // context (and do not remove it if it was added during the initial
9941 // traverse of the 'to' context).
9942 auto PosF = ImportedFromDecls.find(ToD);
9943 if (PosF != ImportedFromDecls.end()) {
9944 // In the case of TypedefNameDecl we create the Decl first and only
9945 // then we import and set its DeclContext. So, the DC might not be set
9946 // when we reach here.
9947 if (ToD->getDeclContext())
9948 SharedState->removeDeclFromLookup(ToD);
9949 ImportedFromDecls.erase(PosF);
9950 }
9951
9952 // FIXME: AST may contain remaining references to the failed object.
9953 // However, the ImportDeclErrors in the shared state contains all the
9954 // failed objects together with their error.
9955 }
9956
9957 // Error encountered for the first time.
9958 // After takeError the error is not usable any more in ToDOrErr.
9959 // Get a copy of the error object (any more simple solution for this?).
9960 ASTImportError ErrOut;
9961 handleAllErrors(ToDOrErr.takeError(),
9962 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9963 setImportDeclError(FromD, ErrOut);
9964 // Set the error for the mapped to Decl, which is in the "to" context.
9965 if (ToDWasCreated)
9966 SharedState->setImportDeclError(CreatedToD, ErrOut);
9967
9968 // Set the error for all nodes which have been created before we
9969 // recognized the error.
9970 for (const auto &Path : SavedImportPaths[FromD]) {
9971 // The import path contains import-dependency nodes first.
9972 // Save the node that was imported as dependency of the current node.
9973 Decl *PrevFromDi = FromD;
9974 for (Decl *FromDi : Path) {
9975 // Begin and end of the path equals 'FromD', skip it.
9976 if (FromDi == FromD)
9977 continue;
9978 // We should not set import error on a node and all following nodes in
9979 // the path if child import errors are ignored.
9980 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9981 PrevFromDi))
9982 break;
9983 PrevFromDi = FromDi;
9984 setImportDeclError(FromDi, ErrOut);
9985
9986 if (const auto *FromTDi = dyn_cast<TagDecl>(FromDi)) {
9987 if (const Type *FromTyi =
9988 getFromContext().getCanonicalTagType(FromTDi).getTypePtr()) {
9989 ImportedTypes.erase(FromTyi);
9990 }
9991 }
9992
9993 //FIXME Should we remove these Decls from ImportedDecls?
9994 // Set the error for the mapped to Decl, which is in the "to" context.
9995 auto Ii = ImportedDecls.find(FromDi);
9996 if (Ii != ImportedDecls.end())
9997 SharedState->setImportDeclError(Ii->second, ErrOut);
9998 // FIXME Should we remove these Decls from the LookupTable,
9999 // and from ImportedFromDecls?
10000 }
10001 }
10002 SavedImportPaths.erase(FromD);
10003
10004 // Do not return ToDOrErr, error was taken out of it.
10005 return make_error<ASTImportError>(ErrOut);
10006 }
10007
10008 ToD = *ToDOrErr;
10009
10010 // FIXME: Handle the "already imported with error" case. We can get here
10011 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
10012 // previously failed create was requested).
10013 // Later GetImportedOrCreateDecl can be updated to return the error.
10014 if (!ToD) {
10015 auto Err = getImportDeclErrorIfAny(FromD);
10016 assert(Err);
10017 return make_error<ASTImportError>(*Err);
10018 }
10019
10020 // We could import from the current TU without error. But previously we
10021 // already had imported a Decl as `ToD` from another TU (with another
10022 // ASTImporter object) and with an error.
10023 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
10024 setImportDeclError(FromD, *Error);
10025 return make_error<ASTImportError>(*Error);
10026 }
10027 // Make sure that ImportImpl registered the imported decl.
10028 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
10029
10030 if (FromD->hasAttrs())
10031 for (const Attr *FromAttr : FromD->getAttrs()) {
10032 auto ToAttrOrErr = Import(FromAttr);
10033 if (ToAttrOrErr)
10034 ToD->addAttr(*ToAttrOrErr);
10035 else
10036 return ToAttrOrErr.takeError();
10037 }
10038
10039 // Notify subclasses.
10040 Imported(FromD, ToD);
10041
10042 updateFlags(FromD, ToD);
10043 SavedImportPaths.erase(FromD);
10044 return ToDOrErr;
10045}
10046
10049 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
10050}
10051
10053 if (!FromDC)
10054 return FromDC;
10055
10056 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
10057 if (!ToDCOrErr)
10058 return ToDCOrErr.takeError();
10059 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
10060
10061 // When we're using a record/enum/Objective-C class/protocol as a context, we
10062 // need it to have a definition.
10063 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
10064 auto *FromRecord = cast<RecordDecl>(FromDC);
10065 if (ToRecord->isCompleteDefinition())
10066 return ToDC;
10067
10068 // If FromRecord is not defined we need to force it to be.
10069 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
10070 // it will start the definition but we never finish it.
10071 // If there are base classes they won't be imported and we will
10072 // be missing anything that we inherit from those bases.
10073 if (FromRecord->getASTContext().getExternalSource() &&
10074 !FromRecord->isCompleteDefinition())
10075 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
10076
10077 if (FromRecord->isCompleteDefinition())
10078 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10079 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
10080 return std::move(Err);
10081 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
10082 auto *FromEnum = cast<EnumDecl>(FromDC);
10083 if (ToEnum->isCompleteDefinition()) {
10084 // Do nothing.
10085 } else if (FromEnum->isCompleteDefinition()) {
10086 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10087 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
10088 return std::move(Err);
10089 } else {
10090 CompleteDecl(ToEnum);
10091 }
10092 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
10093 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
10094 if (ToClass->getDefinition()) {
10095 // Do nothing.
10096 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
10097 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10098 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
10099 return std::move(Err);
10100 } else {
10101 CompleteDecl(ToClass);
10102 }
10103 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
10104 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
10105 if (ToProto->getDefinition()) {
10106 // Do nothing.
10107 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
10108 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
10109 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
10110 return std::move(Err);
10111 } else {
10112 CompleteDecl(ToProto);
10113 }
10114 }
10115
10116 return ToDC;
10117}
10118
10120 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
10121 return cast_or_null<Expr>(*ToSOrErr);
10122 else
10123 return ToSOrErr.takeError();
10124}
10125
10127 if (!FromS)
10128 return nullptr;
10129
10130 // Check whether we've already imported this statement.
10131 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
10132 if (Pos != ImportedStmts.end())
10133 return Pos->second;
10134
10135 // Import the statement.
10136 ASTNodeImporter Importer(*this);
10137 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
10138 if (!ToSOrErr)
10139 return ToSOrErr;
10140
10141 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
10142 auto *FromE = cast<Expr>(FromS);
10143 // Copy ExprBitfields, which may not be handled in Expr subclasses
10144 // constructors.
10145 ToE->setValueKind(FromE->getValueKind());
10146 ToE->setObjectKind(FromE->getObjectKind());
10147 ToE->setDependence(FromE->getDependence());
10148 }
10149
10150 // Record the imported statement object.
10151 ImportedStmts[FromS] = *ToSOrErr;
10152 return ToSOrErr;
10153}
10154
10156 switch (FromNNS.getKind()) {
10159 return FromNNS;
10161 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10162 auto NSOrErr = Import(Namespace);
10163 if (!NSOrErr)
10164 return NSOrErr.takeError();
10165 auto PrefixOrErr = Import(Prefix);
10166 if (!PrefixOrErr)
10167 return PrefixOrErr.takeError();
10168 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10169 *PrefixOrErr);
10170 }
10172 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10173 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10174 else
10175 return RDOrErr.takeError();
10177 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10178 return NestedNameSpecifier(*TyOrErr);
10179 } else {
10180 return TyOrErr.takeError();
10181 }
10182 }
10183 llvm_unreachable("Invalid nested name specifier kind");
10184}
10185
10188 // Copied from NestedNameSpecifier mostly.
10190 NestedNameSpecifierLoc NNS = FromNNS;
10191
10192 // Push each of the nested-name-specifiers's onto a stack for
10193 // serialization in reverse order.
10194 while (NNS) {
10195 NestedNames.push_back(NNS);
10196 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10197 }
10198
10200
10201 while (!NestedNames.empty()) {
10202 NNS = NestedNames.pop_back_val();
10203 NestedNameSpecifier Spec = std::nullopt;
10204 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10205 return std::move(Err);
10206
10207 NestedNameSpecifier::Kind Kind = Spec.getKind();
10208
10209 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10211 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10212 return std::move(Err);
10213
10215 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10216 return std::move(Err);
10217 }
10218
10219 switch (Kind) {
10221 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10222 ToLocalBeginLoc, ToLocalEndLoc);
10223 break;
10224
10226 SourceLocation ToTLoc;
10227 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10228 return std::move(Err);
10230 QualType(Spec.getAsType(), 0), ToTLoc);
10231 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10232 break;
10233 }
10234
10236 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10237 break;
10238
10240 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10241 if (!ToSourceRangeOrErr)
10242 return ToSourceRangeOrErr.takeError();
10243
10244 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10245 ToSourceRangeOrErr->getBegin(),
10246 ToSourceRangeOrErr->getEnd());
10247 break;
10248 }
10250 llvm_unreachable("unexpected null nested name specifier");
10251 }
10252 }
10253
10254 return Builder.getWithLocInContext(getToContext());
10255}
10256
10258 switch (From.getKind()) {
10260 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10261 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10262 else
10263 return ToTemplateOrErr.takeError();
10264
10267 UnresolvedSet<2> ToTemplates;
10268 for (auto *I : *FromStorage) {
10269 if (auto ToOrErr = Import(I))
10270 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10271 else
10272 return ToOrErr.takeError();
10273 }
10274 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10275 ToTemplates.end());
10276 }
10277
10280 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10281 if (!DeclNameOrErr)
10282 return DeclNameOrErr.takeError();
10283 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10284 }
10285
10288 auto QualifierOrErr = Import(QTN->getQualifier());
10289 if (!QualifierOrErr)
10290 return QualifierOrErr.takeError();
10291 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10292 if (!TNOrErr)
10293 return TNOrErr.takeError();
10294 return ToContext.getQualifiedTemplateName(
10295 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10296 }
10297
10300 auto QualifierOrErr = Import(DTN->getQualifier());
10301 if (!QualifierOrErr)
10302 return QualifierOrErr.takeError();
10303 return ToContext.getDependentTemplateName(
10304 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10305 }
10306
10310 auto ReplacementOrErr = Import(Subst->getReplacement());
10311 if (!ReplacementOrErr)
10312 return ReplacementOrErr.takeError();
10313
10314 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10315 if (!AssociatedDeclOrErr)
10316 return AssociatedDeclOrErr.takeError();
10317
10318 return ToContext.getSubstTemplateTemplateParm(
10319 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10320 Subst->getPackIndex(), Subst->getFinal());
10321 }
10322
10326 ASTNodeImporter Importer(*this);
10327 auto ArgPackOrErr =
10328 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10329 if (!ArgPackOrErr)
10330 return ArgPackOrErr.takeError();
10331
10332 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10333 if (!AssociatedDeclOrErr)
10334 return AssociatedDeclOrErr.takeError();
10335
10336 return ToContext.getSubstTemplateTemplateParmPack(
10337 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10338 SubstPack->getFinal());
10339 }
10342 auto PatternOrErr = Import(PI->getPattern());
10343 if (!PatternOrErr)
10344 return PatternOrErr.takeError();
10345
10346 auto IndexExprOrErr = Import(PI->getIndexExpr());
10347 if (!IndexExprOrErr)
10348 return IndexExprOrErr.takeError();
10349
10351 for (TemplateName T : PI->getExpansions()) {
10352 auto ExpansionOrErr = Import(T);
10353 if (!ExpansionOrErr)
10354 return ExpansionOrErr.takeError();
10355 Expansions.push_back(*ExpansionOrErr);
10356 }
10357
10358 return ToContext.getPackIndexingTemplateName(
10359 *PatternOrErr, *IndexExprOrErr, PI->isFullySubstituted(), Expansions);
10360 }
10362 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10363 if (!UsingOrError)
10364 return UsingOrError.takeError();
10365 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10366 }
10368 llvm_unreachable("Unexpected DeducedTemplate");
10369 }
10370
10371 llvm_unreachable("Invalid template name kind");
10372}
10373
10375 if (FromLoc.isInvalid())
10376 return SourceLocation{};
10377
10378 SourceManager &FromSM = FromContext.getSourceManager();
10379 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10380
10381 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10382 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10383 if (!ToFileIDOrErr)
10384 return ToFileIDOrErr.takeError();
10385 SourceManager &ToSM = ToContext.getSourceManager();
10386 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10387}
10388
10390 SourceLocation ToBegin, ToEnd;
10391 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10392 return std::move(Err);
10393 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10394 return std::move(Err);
10395
10396 return SourceRange(ToBegin, ToEnd);
10397}
10398
10400 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10401 if (Pos != ImportedFileIDs.end())
10402 return Pos->second;
10403
10404 SourceManager &FromSM = FromContext.getSourceManager();
10405 SourceManager &ToSM = ToContext.getSourceManager();
10406 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10407
10408 // Map the FromID to the "to" source manager.
10409 FileID ToID;
10410 if (FromSLoc.isExpansion()) {
10411 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10412 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10413 if (!ToSpLoc)
10414 return ToSpLoc.takeError();
10415 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10416 if (!ToExLocS)
10417 return ToExLocS.takeError();
10418 unsigned ExLength = FromSM.getFileIDSize(FromID);
10419 SourceLocation MLoc;
10420 if (FromEx.isMacroArgExpansion()) {
10421 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10422 } else {
10423 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10424 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10425 FromEx.isExpansionTokenRange());
10426 else
10427 return ToExLocE.takeError();
10428 }
10429 ToID = ToSM.getFileID(MLoc);
10430 } else {
10431 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10432
10433 if (!IsBuiltin && !Cache->BufferOverridden) {
10434 // Include location of this file.
10435 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10436 if (!ToIncludeLoc)
10437 return ToIncludeLoc.takeError();
10438
10439 // Every FileID that is not the main FileID needs to have a valid include
10440 // location so that the include chain points to the main FileID. When
10441 // importing the main FileID (which has no include location), we need to
10442 // create a fake include location in the main file to keep this property
10443 // intact.
10444 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10445 if (FromID == FromSM.getMainFileID())
10446 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10447
10448 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10449 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10450 // the disk again
10451 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10452 // than mmap the files several times.
10453 auto Entry =
10454 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10455 // FIXME: The filename may be a virtual name that does probably not
10456 // point to a valid file and we get no Entry here. In this case try with
10457 // the memory buffer below.
10458 if (Entry)
10459 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10460 FromSLoc.getFile().getFileCharacteristic());
10461 }
10462 }
10463
10464 if (ToID.isInvalid() || IsBuiltin) {
10465 // FIXME: We want to re-use the existing MemoryBuffer!
10466 std::optional<llvm::MemoryBufferRef> FromBuf =
10467 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10468 FromSM.getFileManager(), SourceLocation{});
10469 if (!FromBuf)
10470 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10471
10472 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10473 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10474 FromBuf->getBufferIdentifier());
10475 ToID = ToSM.createFileID(std::move(ToBuf),
10476 FromSLoc.getFile().getFileCharacteristic());
10477 }
10478 }
10479
10480 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10481
10482 ImportedFileIDs[FromID] = ToID;
10483 return ToID;
10484}
10485
10487 ExpectedExpr ToExprOrErr = Import(From->getInit());
10488 if (!ToExprOrErr)
10489 return ToExprOrErr.takeError();
10490
10491 auto LParenLocOrErr = Import(From->getLParenLoc());
10492 if (!LParenLocOrErr)
10493 return LParenLocOrErr.takeError();
10494
10495 auto RParenLocOrErr = Import(From->getRParenLoc());
10496 if (!RParenLocOrErr)
10497 return RParenLocOrErr.takeError();
10498
10499 if (From->isBaseInitializer()) {
10500 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10501 if (!ToTInfoOrErr)
10502 return ToTInfoOrErr.takeError();
10503
10504 SourceLocation EllipsisLoc;
10505 if (From->isPackExpansion())
10506 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10507 return std::move(Err);
10508
10509 return new (ToContext) CXXCtorInitializer(
10510 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10511 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10512 } else if (From->isMemberInitializer()) {
10513 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10514 if (!ToFieldOrErr)
10515 return ToFieldOrErr.takeError();
10516
10517 auto MemberLocOrErr = Import(From->getMemberLocation());
10518 if (!MemberLocOrErr)
10519 return MemberLocOrErr.takeError();
10520
10521 return new (ToContext) CXXCtorInitializer(
10522 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10523 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10524 } else if (From->isIndirectMemberInitializer()) {
10525 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10526 if (!ToIFieldOrErr)
10527 return ToIFieldOrErr.takeError();
10528
10529 auto MemberLocOrErr = Import(From->getMemberLocation());
10530 if (!MemberLocOrErr)
10531 return MemberLocOrErr.takeError();
10532
10533 return new (ToContext) CXXCtorInitializer(
10534 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10535 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10536 } else if (From->isDelegatingInitializer()) {
10537 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10538 if (!ToTInfoOrErr)
10539 return ToTInfoOrErr.takeError();
10540
10541 return new (ToContext)
10542 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10543 *ToExprOrErr, *RParenLocOrErr);
10544 } else {
10545 // FIXME: assert?
10546 return make_error<ASTImportError>();
10547 }
10548}
10549
10552 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10553 if (Pos != ImportedCXXBaseSpecifiers.end())
10554 return Pos->second;
10555
10556 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10557 if (!ToSourceRange)
10558 return ToSourceRange.takeError();
10560 if (!ToTSI)
10561 return ToTSI.takeError();
10562 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10563 if (!ToEllipsisLoc)
10564 return ToEllipsisLoc.takeError();
10565 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10566 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10567 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10568 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10569 return Imported;
10570}
10571
10573 ASTNodeImporter Importer(*this);
10574 return Importer.ImportAPValue(FromValue);
10575}
10576
10578 ExpectedDecl ToOrErr = Import(From);
10579 if (!ToOrErr)
10580 return ToOrErr.takeError();
10581 Decl *To = *ToOrErr;
10582
10583 auto *FromDC = cast<DeclContext>(From);
10584 ASTNodeImporter Importer(*this);
10585
10586 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10587 if (!ToRecord->getDefinition()) {
10588 return Importer.ImportDefinition(
10589 cast<RecordDecl>(FromDC), ToRecord,
10591 }
10592 }
10593
10594 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10595 if (!ToEnum->getDefinition()) {
10596 return Importer.ImportDefinition(
10598 }
10599 }
10600
10601 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10602 if (!ToIFace->getDefinition()) {
10603 return Importer.ImportDefinition(
10604 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10606 }
10607 }
10608
10609 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10610 if (!ToProto->getDefinition()) {
10611 return Importer.ImportDefinition(
10612 cast<ObjCProtocolDecl>(FromDC), ToProto,
10614 }
10615 }
10616
10617 return Importer.ImportDeclContext(FromDC, true);
10618}
10619
10621 if (!FromName)
10622 return DeclarationName{};
10623
10624 switch (FromName.getNameKind()) {
10626 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10627
10631 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10632 return DeclarationName(*ToSelOrErr);
10633 else
10634 return ToSelOrErr.takeError();
10635
10637 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10638 return ToContext.DeclarationNames.getCXXConstructorName(
10639 ToContext.getCanonicalType(*ToTyOrErr));
10640 else
10641 return ToTyOrErr.takeError();
10642 }
10643
10645 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10646 return ToContext.DeclarationNames.getCXXDestructorName(
10647 ToContext.getCanonicalType(*ToTyOrErr));
10648 else
10649 return ToTyOrErr.takeError();
10650 }
10651
10653 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10654 return ToContext.DeclarationNames.getCXXDeductionGuideName(
10655 cast<TemplateDecl>(*ToTemplateOrErr));
10656 else
10657 return ToTemplateOrErr.takeError();
10658 }
10659
10661 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10662 return ToContext.DeclarationNames.getCXXConversionFunctionName(
10663 ToContext.getCanonicalType(*ToTyOrErr));
10664 else
10665 return ToTyOrErr.takeError();
10666 }
10667
10669 return ToContext.DeclarationNames.getCXXOperatorName(
10670 FromName.getCXXOverloadedOperator());
10671
10673 return ToContext.DeclarationNames.getCXXLiteralOperatorName(
10674 Import(FromName.getCXXLiteralIdentifier()));
10675
10677 // FIXME: STATICS!
10679 }
10680
10681 llvm_unreachable("Invalid DeclarationName Kind!");
10682}
10683
10685 if (!FromId)
10686 return nullptr;
10687
10688 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10689
10690 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10691 ToId->setBuiltinID(FromId->getBuiltinID());
10692
10693 return ToId;
10694}
10695
10698 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10699 return Import(FromII);
10700 return FromIO.getOperator();
10701}
10702
10704 if (FromSel.isNull())
10705 return Selector{};
10706
10708 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10709 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10710 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10711 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10712}
10713
10717 llvm::Error Err = llvm::Error::success();
10718 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10719 for (unsigned Idx = 0; Idx < Size; Idx++) {
10720 APValue Tmp = importChecked(Err, From[Idx]);
10721 To[Idx] = Tmp;
10722 }
10723 };
10724 switch (FromValue.getKind()) {
10725 case APValue::None:
10727 case APValue::Int:
10728 case APValue::Float:
10732 Result = FromValue;
10733 break;
10734 case APValue::Vector: {
10735 Result.MakeVector();
10737 Result.setVectorUninit(FromValue.getVectorLength());
10738 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10739 Elts.data(), FromValue.getVectorLength());
10740 break;
10741 }
10742 case APValue::Matrix:
10743 // Matrix values cannot currently arise in APValue import contexts.
10744 llvm_unreachable("Matrix APValue import not yet supported");
10745 case APValue::Array:
10746 Result.MakeArray(FromValue.getArrayInitializedElts(),
10747 FromValue.getArraySize());
10748 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10749 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10750 FromValue.getArrayInitializedElts());
10751 break;
10752 case APValue::Struct:
10753 Result.MakeStruct(FromValue.getStructNumBases(),
10754 FromValue.getStructNumFields(),
10755 FromValue.getStructNumVirtualBases());
10756 ImportLoop(
10757 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10758 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10759 FromValue.getStructNumBases() + FromValue.getStructNumFields() +
10760 FromValue.getStructNumVirtualBases());
10761 break;
10762 case APValue::Union: {
10763 Result.MakeUnion();
10764 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10765 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10766 if (Err)
10767 return std::move(Err);
10768 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10769 break;
10770 }
10772 Result.MakeAddrLabelDiff();
10773 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10774 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10775 if (Err)
10776 return std::move(Err);
10777 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10778 cast<AddrLabelExpr>(ImpRHS));
10779 break;
10780 }
10782 const Decl *ImpMemPtrDecl =
10783 importChecked(Err, FromValue.getMemberPointerDecl());
10784 if (Err)
10785 return std::move(Err);
10787 Result.setMemberPointerUninit(
10788 cast<const ValueDecl>(ImpMemPtrDecl),
10790 FromValue.getMemberPointerPath().size());
10791 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10792 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10793 Idx++) {
10794 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10795 if (Err)
10796 return std::move(Err);
10797 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10798 }
10799 break;
10800 }
10801 case APValue::LValue:
10803 QualType FromElemTy;
10804 if (FromValue.getLValueBase()) {
10805 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10806 "in C++20 dynamic allocation are transient so they shouldn't "
10807 "appear in the AST");
10808 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10809 if (const auto *E =
10810 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10811 FromElemTy = E->getType();
10812 const Expr *ImpExpr = importChecked(Err, E);
10813 if (Err)
10814 return std::move(Err);
10815 Base = APValue::LValueBase(ImpExpr,
10816 FromValue.getLValueBase().getCallIndex(),
10817 FromValue.getLValueBase().getVersion());
10818 } else {
10819 FromElemTy =
10820 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10821 const Decl *ImpDecl = importChecked(
10822 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10823 if (Err)
10824 return std::move(Err);
10826 FromValue.getLValueBase().getCallIndex(),
10827 FromValue.getLValueBase().getVersion());
10828 }
10829 } else {
10830 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10831 const Type *ImpTypeInfo = importChecked(
10832 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10833 QualType ImpType =
10834 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10835 if (Err)
10836 return std::move(Err);
10838 ImpType);
10839 }
10840 }
10841 CharUnits Offset = FromValue.getLValueOffset();
10842 unsigned PathLength = FromValue.getLValuePath().size();
10843 Result.MakeLValue();
10844 if (FromValue.hasLValuePath()) {
10845 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10846 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10847 FromValue.isNullPointer());
10849 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10850 if (FromElemTy->isRecordType()) {
10851 const Decl *FromDecl =
10852 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10853 const Decl *ImpDecl = importChecked(Err, FromDecl);
10854 if (Err)
10855 return std::move(Err);
10856 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10857 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10858 else
10859 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10861 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10862 } else {
10863 FromElemTy =
10864 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10865 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10866 FromPath[LoopIdx].getAsArrayIndex());
10867 }
10868 }
10869 } else
10870 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10871 FromValue.isNullPointer());
10872 }
10873 if (Err)
10874 return std::move(Err);
10875 return Result;
10876}
10877
10879 DeclContext *DC,
10880 unsigned IDNS,
10881 NamedDecl **Decls,
10882 unsigned NumDecls) {
10883 if (ODRHandling == ODRHandlingType::Conservative)
10884 // Report error at any name conflict.
10885 return make_error<ASTImportError>(ASTImportError::NameConflict);
10886 else
10887 // Allow to create the new Decl with the same name.
10888 return Name;
10889}
10890
10892 if (LastDiagFromFrom)
10893 ToContext.getDiagnostics().notePriorDiagnosticFrom(
10894 FromContext.getDiagnostics());
10895 LastDiagFromFrom = false;
10896 return ToContext.getDiagnostics().Report(Loc, DiagID);
10897}
10898
10900 if (!LastDiagFromFrom)
10901 FromContext.getDiagnostics().notePriorDiagnosticFrom(
10902 ToContext.getDiagnostics());
10903 LastDiagFromFrom = true;
10904 return FromContext.getDiagnostics().Report(Loc, DiagID);
10905}
10906
10908 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10909 if (!ID->getDefinition())
10910 ID->startDefinition();
10911 }
10912 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10913 if (!PD->getDefinition())
10914 PD->startDefinition();
10915 }
10916 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10917 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10918 TD->startDefinition();
10919 TD->setCompleteDefinition(true);
10920 }
10921 }
10922 else {
10923 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10924 }
10925}
10926
10928 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10929 assert((Inserted || Pos->second == To) &&
10930 "Try to import an already imported Decl");
10931 if (!Inserted)
10932 return Pos->second;
10933 // This mapping should be maintained only in this function. Therefore do not
10934 // check for additional consistency.
10935 ImportedFromDecls[To] = From;
10936 // In the case of TypedefNameDecl we create the Decl first and only then we
10937 // import and set its DeclContext. So, the DC is still not set when we reach
10938 // here from GetImportedOrCreateDecl.
10939 if (To->getDeclContext())
10940 AddToLookupTable(To);
10941 return To;
10942}
10943
10944std::optional<ASTImportError>
10946 auto Pos = ImportDeclErrors.find(FromD);
10947 if (Pos != ImportDeclErrors.end())
10948 return Pos->second;
10949 else
10950 return std::nullopt;
10951}
10952
10954 auto InsertRes = ImportDeclErrors.insert({From, Error});
10955 (void)InsertRes;
10956 // Either we set the error for the first time, or we already had set one and
10957 // now we want to set the same error.
10958 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10959}
10960
10962 bool Complain) {
10963 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10964 ImportedTypes.find(From.getTypePtr());
10965 if (Pos != ImportedTypes.end()) {
10966 if (ExpectedType ToFromOrErr = Import(From)) {
10967 if (ToContext.hasSameType(*ToFromOrErr, To))
10968 return true;
10969 } else {
10970 llvm::consumeError(ToFromOrErr.takeError());
10971 }
10972 }
10973
10975 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10976 getStructuralEquivalenceKind(*this), false, Complain);
10977 return Ctx.IsEquivalent(From, To);
10978}
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:239
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
const LangOptions & getLangOpts() const
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
std::string toString() const
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition ASTImporter.h:62
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
static UnsignedOrNone getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
friend class ASTNodeImporter
Definition ASTImporter.h:63
llvm::Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition ASTImporter.h:65
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedStmt VisitCXXExpansionSelectExpr(CXXExpansionSelectExpr *E)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedStmt VisitCXXExpansionStmtPattern(CXXExpansionStmtPattern *S)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
StringRef ImportASTStringRef(StringRef FromStr)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedDecl VisitRequiresExprBodyDecl(RequiresExprBodyDecl *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitRequiresExpr(RequiresExpr *E)
ExpectedDecl VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitPseudoObjectExpr(PseudoObjectExpr *E)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitConceptDecl(ConceptDecl *D)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
ExpectedDecl VisitCXXExpansionStmtDecl(CXXExpansionStmtDecl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
SmallVector< TemplateArgument, 8 > TemplateArgsTy
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedStmt VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedDecl VisitFileScopeAsmDecl(FileScopeAsmDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
Expected< concepts::Requirement * > ImportNestedRequirement(concepts::NestedRequirement *From)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedStmt VisitCXXExpansionStmtInstantiation(CXXExpansionStmtInstantiation *S)
ExpectedDecl VisitFriendTemplateDecl(FriendTemplateDecl *D)
ExpectedStmt VisitCXXParenListInitExpr(CXXParenListInitExpr *E)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
ASTNodeImporter(ASTImporter &Importer)
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitConceptSpecializationExpr(ConceptSpecializationExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitDependentTemplateIdExpr(DependentTemplateIdExpr *E)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
Expected< concepts::Requirement * > ImportExprRequirement(concepts::ExprRequirement *From)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
Error ImportConstraintSatisfaction(const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
Expected< concepts::Requirement * > ImportTypeRequirement(concepts::TypeRequirement *From)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedStmt VisitBreakStmt(BreakStmt *S)
DesignatedInitExpr::Designator Designator
ExpectedDecl VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D)
SourceLocation getColonLoc() const
Definition Expr.h:4425
SourceLocation getQuestionLoc() const
Definition Expr.h:4424
Represents an access specifier followed by colon ':'.
Definition DeclCXX.h:86
SourceLocation getColonLoc() const
The location of the colon following the access specifier.
Definition DeclCXX.h:108
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition Expr.h:4594
SourceLocation getAmpAmpLoc() const
Definition Expr.h:4609
SourceLocation getLabelLoc() const
Definition Expr.h:4611
LabelDecl * getLabel() const
Definition Expr.h:4617
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6071
Represents a loop initializing the elements of an array.
Definition Expr.h:6018
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:6033
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:6038
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2765
SourceLocation getRBracketLoc() const
Definition Expr.h:2813
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition Expr.h:2794
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h: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:3800
bool isVolatile() const
Definition Stmt.h:3325
outputs_range outputs()
Definition Stmt.h:3432
SourceLocation getAsmLoc() const
Definition Stmt.h:3319
inputs_range inputs()
Definition Stmt.h:3403
unsigned getNumClobbers() const
Definition Stmt.h:3380
unsigned getNumOutputs() const
Definition Stmt.h:3348
unsigned getNumInputs() const
Definition Stmt.h:3370
bool isSimple() const
Definition Stmt.h:3322
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6978
Expr ** getSubExprs()
Definition Expr.h:7053
SourceLocation getRParenLoc() const
Definition Expr.h:7107
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition Expr.cpp:5305
AtomicOp getOp() const
Definition Expr.h:7041
SourceLocation getBuiltinLoc() const
Definition Expr.h:7106
Attr - This represents one attribute.
Definition Attr.h:46
attr::Kind getKind() const
Definition Attr.h:92
void setPackExpansion(bool PE)
Definition Attr.h:108
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition Attr.h:106
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition Stmt.h:2215
Stmt * getSubStmt()
Definition Stmt.h:2251
SourceLocation getAttrLoc() const
Definition Stmt.h:2246
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2247
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition Stmt.cpp:441
Represents a C++ declaration that introduces decls from somewhere else.
Definition DeclCXX.h:3525
void addShadowDecl(UsingShadowDecl *S)
Definition DeclCXX.cpp:3516
shadow_range shadows() const
Definition DeclCXX.h:3591
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4497
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Definition Expr.h:4551
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition Expr.h:4535
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition Expr.h:4539
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition Expr.h:4544
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition Expr.h:4532
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4082
Expr * getLHS() const
Definition Expr.h:4132
SourceLocation getOperatorLoc() const
Definition Expr.h:4124
Expr * getRHS() const
Definition Expr.h:4134
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5131
Opcode getOpcode() const
Definition Expr.h:4127
FPOptionsOverride getFPFeatures() const
Definition Expr.h:4302
A binding in a decomposition declaration.
Definition DeclCXX.h:4214
void setDecomposedDecl(DecompositionDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition DeclCXX.h:4258
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition DeclCXX.h:4240
DecompositionDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition DeclCXX.h:4247
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:4252
BreakStmt - This represents a break.
Definition Stmt.h:3147
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5529
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:2135
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:2641
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2976
Represents a C++ base or member initializer.
Definition DeclCXX.h:2406
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition DeclCXX.h:2546
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition DeclCXX.h:2506
Expr * getInit() const
Get the initializer.
Definition DeclCXX.h:2608
SourceLocation getRParenLoc() const
Definition DeclCXX.h:2605
SourceLocation getEllipsisLoc() const
Definition DeclCXX.h:2516
SourceLocation getLParenLoc() const
Definition DeclCXX.h:2604
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition DeclCXX.h:2511
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition DeclCXX.h:2540
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition DeclCXX.h:2484
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition DeclCXX.h:2478
bool isIndirectMemberInitializer() const
Definition DeclCXX.h:2490
SourceLocation getMemberLocation() const
Definition DeclCXX.h:2566
IndirectFieldDecl * getIndirectMember() const
Definition DeclCXX.h:2560
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition DeclCXX.h:2532
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:2000
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition DeclCXX.h:2083
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:3923
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4022
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4025
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:4077
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition ExprCXX.h:4069
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4056
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition ExprCXX.h:4096
SourceLocation getMemberLoc() const
Definition ExprCXX.h:4065
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:4085
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition ExprCXX.h:4061
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:4049
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4013
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition ExprCXX.h:4036
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition ExprCXX.h:4005
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:4124
Represents a C++ destructor within a class.
Definition DeclCXX.h:2906
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:5611
InitListExpr * getRangeExpr()
Definition ExprCXX.h:5621
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:5085
UnresolvedLookupExpr * getCallee() const
Definition ExprCXX.h:5107
Expr * getRHS() const
Definition ExprCXX.h:5111
SourceLocation getLParenLoc() const
Definition ExprCXX.h:5127
SourceLocation getEllipsisLoc() const
Definition ExprCXX.h:5129
UnsignedOrNone getNumExpansions() const
Definition ExprCXX.h:5132
Expr * getLHS() const
Definition ExprCXX.h:5110
SourceLocation getRParenLoc() const
Definition ExprCXX.h:5128
BinaryOperatorKind getOperator() const
Definition ExprCXX.h:5130
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:2149
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:2262
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:4362
bool getValue() const
Definition ExprCXX.h:4385
SourceLocation getEndLoc() const
Definition ExprCXX.h:4382
Expr * getOperand() const
Definition ExprCXX.h:4379
SourceLocation getBeginLoc() const
Definition ExprCXX.h:4381
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:5194
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:5250
SourceLocation getInitLoc() const LLVM_READONLY
Definition ExprCXX.h:5252
MutableArrayRef< Expr * > getInitExprs()
Definition ExprCXX.h:5234
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5248
MutableArrayRef< Expr * > getUserSpecifiedInitExprs()
Definition ExprCXX.h:5240
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:3797
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3841
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3852
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:3835
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3846
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3855
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2987
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition Expr.cpp:1545
ADLCallKind getADLCallKind() const
Definition Expr.h:3138
Expr * getCallee()
Definition Expr.h:3134
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3286
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3178
arg_range arguments()
Definition Expr.h:3239
SourceLocation getRParenLoc() const
Definition Expr.h:3318
CaseStmt - Represent a case statement.
Definition Stmt.h:1932
Stmt * getSubStmt()
Definition Stmt.h:2045
Expr * getLHS()
Definition Stmt.h:2015
SourceLocation getEllipsisLoc() const
Get the location of the ... in a case statement of the form LHS ... RHS.
Definition Stmt.h:2001
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition Stmt.cpp:1306
SourceLocation getCaseLoc() const
Definition Stmt.h:1997
Expr * getRHS()
Definition Stmt.h:2027
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition Expr.h:3720
path_iterator path_begin()
Definition Expr.h:3790
CastKind getCastKind() const
Definition Expr.h:3764
path_iterator path_end()
Definition Expr.h:3791
FPOptionsOverride getFPFeatures() const
Definition Expr.h:3840
Expr * getSubExpr()
Definition Expr.h:3770
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:4892
SourceLocation getBuiltinLoc() const
Definition Expr.h:4939
Expr * getLHS() const
Definition Expr.h:4934
bool isConditionDependent() const
Definition Expr.h:4922
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition Expr.h:4915
Expr * getRHS() const
Definition Expr.h:4936
SourceLocation getRParenLoc() const
Definition Expr.h:4942
Expr * getCond() const
Definition Expr.h:4932
Declaration of a class template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, llvm::FoldingSetInsertToken &InsertToken)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, llvm::FoldingSetInsertToken &InsertToken)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, llvm::FoldingSetInsertToken InsertToken)
Insert the specified specialization knowing that it is not already in.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, llvm::FoldingSetInsertToken InsertToken)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getExternKeywordLoc() const
Gets the location of the extern keyword, if present.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateInstantiationArgs() const
Retrieve the set of template arguments that should be used to instantiate members of the class templa...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getInstantiatedFrom() const
If this class template specialization is an instantiation of a template (rather than an explicit spec...
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4344
QualType getComputationLHSType() const
Definition Expr.h:4378
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition Expr.cpp:5153
QualType getComputationResultType() const
Definition Expr.h:4381
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3649
SourceLocation getLParenLoc() const
Definition Expr.h:3684
bool isFileScope() const
Definition Expr.h:3681
const Expr * getInitializer() const
Definition Expr.h:3677
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:3687
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1752
unsigned size() const
Definition Stmt.h:1797
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1802
body_range body()
Definition Stmt.h:1815
SourceLocation getLBracLoc() const
Definition Stmt.h:1869
bool hasStoredFPFeatures() const
Definition Stmt.h:1799
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition Stmt.cpp:399
SourceLocation getRBracLoc() const
Definition Stmt.h:1870
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
A reference to a concept and its template args, as it appears in the code.
Definition ASTConcept.h:130
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition ASTConcept.h:170
NamedDecl * getFoundDecl() const
Definition ASTConcept.h:197
const DeclarationNameInfo & getConceptNameInfo() const
Definition ASTConcept.h:174
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateName NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition ASTConcept.h:203
TemplateName getNamedConcept() const
Definition ASTConcept.h:201
SourceLocation getTemplateKWLoc() const
Definition ASTConcept.h:180
Represents the specialization of a concept - evaluates to a prvalue of type bool.
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
ConceptReference * getConceptReference() const
const ImplicitConceptSpecializationDecl * getSpecializationDecl() const
const ASTConstraintSatisfaction & getSatisfaction() const
Get elaborated satisfaction info about the template arguments' satisfaction of the named concept.
ConditionalOperator - The ?
Definition Expr.h:4435
Expr * getLHS() const
Definition Expr.h:4469
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4458
Expr * getRHS() const
Definition Expr.h:4470
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1102
APValue getAPValueResult() const
Definition Expr.cpp:419
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition Expr.cpp:356
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:47
llvm::SmallVector< UnsatisfiedConstraintRecord, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition ASTConcept.h:67
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition DeclCXX.h:3706
ContinueStmt - This represents a continue.
Definition Stmt.h:3131
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4763
FPOptionsOverride getStoredFPFeaturesOrDefault() const
Get the store FPOptionsOverride or default if not stored.
Definition Expr.h:4831
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition Expr.h:4867
static ConvertVectorExpr * Create(const ASTContext &C, Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc, FPOptionsOverride FPFeatures)
Definition Expr.cpp:5718
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition Expr.h:4864
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition Expr.h:4856
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition Expr.h:4853
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
NamedDecl * getDecl() const
AccessSpecifier getAccess() const
The results of name lookup within a DeclContext.
Definition DeclBase.h:1399
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
Definition DeclBase.h: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:823
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:832
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:856
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition Decl.h:815
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:2018
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:846
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:810
A decomposition declaration.
Definition DeclCXX.h:4278
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:3563
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:3637
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3611
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3629
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition ExprCXX.h:3671
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3647
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3621
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3602
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3599
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:3524
SourceLocation getRAngleLoc() const
Definition ExprCXX.h:3520
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:3519
IdentifierOrOverloadedOperator getName() const
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
bool hasTemplateKeyword() const
Was this template name was preceeded by the template keyword?
Represents a single C99 designator.
Definition Expr.h:5644
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition Expr.h:5771
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Expr.h:5725
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition Expr.h:5761
SourceLocation getFieldLoc() const
Definition Expr.h:5752
SourceLocation getRBracketLoc() const
Definition Expr.h:5800
const IdentifierInfo * getFieldName() const
Definition Expr.cpp:4822
SourceLocation getEllipsisLoc() const
Definition Expr.h:5794
SourceLocation getDotLoc() const
Definition Expr.h:5747
SourceLocation getLBracketLoc() const
Definition Expr.h:5788
Represents a C99 designated initializer expression.
Definition Expr.h:5601
Expr * getSubExpr(unsigned Idx) const
Definition Expr.h:5883
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition Expr.h:5865
MutableArrayRef< Designator > designators()
Definition Expr.h:5834
Expr * getInit() const
Retrieve the initializer value.
Definition Expr.h:5869
unsigned size() const
Returns the number of designators in this initializer.
Definition Expr.h:5831
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition Expr.h:5856
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition Expr.h:5881
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition Expr.cpp:4863
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:5314
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3558
llvm::APSInt getInitVal() const
Definition Decl.h:3578
const Expr * getInitExpr() const
Definition Decl.h:3576
Represents an enum.
Definition Decl.h:4146
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition Decl.h:4418
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4364
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition Decl.h:4356
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4367
void setIntegerType(QualType T)
Set the underlying integer type.
Definition Decl.h:4328
EnumDecl * getMostRecentDecl()
Definition Decl.h:4251
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4373
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition Decl.cpp:5161
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4319
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition Decl.cpp:5221
EnumDecl * getDefinition() const
Definition Decl.h:4258
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition Decl.h:4345
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition Decl.h:4311
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3972
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3994
Store information needed for an explicit specifier.
Definition DeclCXX.h:1948
ExplicitSpecKind getKind() const
Definition DeclCXX.h:1956
const Expr * getExpr() const
Definition DeclCXX.h:1957
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3714
bool cleanupsHaveSideEffects() const
Definition ExprCXX.h:3749
ArrayRef< CleanupObject > getObjects() const
Definition ExprCXX.h:3738
unsigned getNumObjects() const
Definition ExprCXX.h:3742
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition ExprCXX.h:3720
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:3295
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3395
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4792
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition Decl.h:3475
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3469
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition Decl.cpp:4802
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3411
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition Decl.h:3519
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition Decl.cpp:4902
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:57
SourceLocation getAsmLoc() const
Definition Decl.h:4748
const Expr * getAsmStringExpr() const
Definition Decl.h:4755
SourceLocation getRParenLoc() const
Definition Decl.h:4749
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1601
llvm::APInt getValue() const
Returns an internal integer representation of the literal.
Definition Expr.h:1595
SourceLocation getLocation() const
Definition Expr.h:1727
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition Expr.cpp: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:2059
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3268
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2603
DefaultedOrDeletedFunctionInfo * getDefaultedOrDeletedInfo() const
Definition Decl.cpp:3183
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition Decl.cpp:4239
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4234
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:2832
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:3040
SourceLocation getDefaultLoc() const
Definition Decl.h:2525
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2905
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2516
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2504
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2575
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4213
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition Decl.cpp:4364
void setDefaultLoc(SourceLocation NewLoc)
Definition Decl.h:2529
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2440
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition Decl.cpp:4430
@ TK_FunctionTemplateSpecialization
Definition Decl.h:2075
@ TK_DependentFunctionTemplateSpecialization
Definition Decl.h:2078
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:3019
void setTrivial(bool IT)
Definition Decl.h:2505
bool FriendConstraintRefersToEnclosingTemplate() const
Definition Decl.h:2838
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition Decl.cpp:4185
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition Decl.cpp:4252
bool isDeletedAsWritten() const
Definition Decl.h:2671
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition Decl.cpp:4419
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2480
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition Decl.h:2476
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition Decl.cpp: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:2332
bool isDefaulted() const
Whether this function is defaulted.
Definition Decl.h:2512
FunctionDecl * getInstantiatedFromDecl() const
Definition Decl.cpp:4258
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4458
void setDefaulted(bool D=true)
Definition Decl.h:2513
void setBody(Stmt *B)
Definition Decl.cpp:3280
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2471
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition Decl.cpp:3158
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition Decl.h:2521
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition Decl.cpp:4206
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2325
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:3030
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5385
QualType desugar() const
Definition TypeBase.h:5966
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5674
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:5839
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5825
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:4937
QualType getReturnType() const
Definition TypeBase.h:4921
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3458
unsigned getNumLabels() const
Definition Stmt.h:3608
labels_range labels()
Definition Stmt.h:3631
SourceLocation getRParenLoc() const
Definition Stmt.h:3480
IdentifierInfo * getInputIdentifier(unsigned i) const
Definition Stmt.h:3573
const Expr * getOutputConstraintExpr(unsigned i) const
Definition Stmt.h:3560
const Expr * getInputConstraintExpr(unsigned i) const
Definition Stmt.h:3586
IdentifierInfo * getOutputIdentifier(unsigned i) const
Definition Stmt.h:3549
const Expr * getAsmStringExpr() const
Definition Stmt.h:3485
Expr * getClobberExpr(unsigned i)
Definition Stmt.h:3665
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4967
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4984
Represents a C11 generic selection.
Definition Expr.h:6232
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition Expr.h:6509
ArrayRef< Expr * > getAssocExprs() const
Definition Expr.h:6529
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition Expr.h:6490
SourceLocation getGenericLoc() const
Definition Expr.h:6587
SourceLocation getRParenLoc() const
Definition Expr.h:6591
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition Expr.h:6479
SourceLocation getDefaultLoc() const
Definition Expr.h:6590
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
Definition Expr.cpp:4752
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition Expr.h:6486
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition Expr.h:6497
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition Expr.h:6534
GotoStmt - This represents a direct goto.
Definition Stmt.h:2981
SourceLocation getLabelLoc() const
Definition Stmt.h:2999
SourceLocation getGotoLoc() const
Definition Stmt.h:2997
LabelDecl * getLabel() const
Definition Stmt.h:2994
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setBuiltinID(unsigned ID)
StringRef getName() const
Return the actual identifier string.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2271
Stmt * getThen()
Definition Stmt.h:2360
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition Stmt.cpp:1044
SourceLocation getIfLoc() const
Definition Stmt.h:2437
IfStatementKind getStatementKind() const
Definition Stmt.h:2472
SourceLocation getElseLoc() const
Definition Stmt.h:2440
Stmt * getInit()
Definition Stmt.h:2421
SourceLocation getLParenLoc() const
Definition Stmt.h:2489
Expr * getCond()
Definition Stmt.h:2348
Stmt * getElse()
Definition Stmt.h:2369
SourceLocation getRParenLoc() const
Definition Stmt.h:2491
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1068
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1751
const Expr * getSubExpr() const
Definition Expr.h:1763
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3897
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition Expr.cpp:2103
ArrayRef< TemplateArgument > getTemplateArguments() const
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition Decl.h:1810
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6107
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5188
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3602
unsigned getChainingSize() const
Definition Decl.h:3627
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3623
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3020
SourceLocation getGotoLoc() const
Definition Stmt.h:3036
SourceLocation getStarLoc() const
Definition Stmt.h:3038
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2612
CXXConstructorDecl * getConstructor() const
Definition DeclCXX.h:2625
ConstructorUsingShadowDecl * getShadowDecl() const
Definition DeclCXX.h:2624
Describes an C or C++ initializer list.
Definition Expr.h:5352
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition Expr.h:5465
void setSyntacticForm(InitListExpr *Init)
Definition Expr.h:5526
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition Expr.h:5479
unsigned getNumInits() const
Definition Expr.h:5385
SourceLocation getLBraceLoc() const
Definition Expr.h:5510
void setArrayFiller(Expr *filler)
Definition Expr.cpp:2471
InitListExpr * getSyntacticForm() const
Definition Expr.h:5522
bool hadArrayRangeDesignator() const
Definition Expr.h:5533
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition Expr.h:5455
bool isExplicit() const
Definition Expr.h:5495
SourceLocation getRBraceLoc() const
Definition Expr.h:5512
void setInitializedFieldInUnion(FieldDecl *FD)
Definition Expr.h:5485
ArrayRef< Expr * > inits() const
Definition Expr.h:5405
void sawArrayRangeDesignator(bool ARD=true)
Definition Expr.h:5536
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:981
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition Expr.h:1556
Represents the declaration of a label.
Definition Decl.h:525
bool isGnuLocal() const
Definition Decl.h:552
LabelStmt * getStmt() const
Definition Decl.h:549
void setStmt(LabelStmt *T)
Definition Decl.h:550
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2158
LabelDecl * getDecl() const
Definition Stmt.h:2176
Stmt * getSubStmt()
Definition Stmt.h:2180
SourceLocation getIdentLoc() const
Definition Stmt.h:2173
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool capturesVariable() const
Determine whether this capture handles a variable.
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition ExprCXX.cpp: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:3337
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition DeclCXX.h:3383
Represents a linkage specification.
Definition DeclCXX.h:3044
void setRBraceLoc(SourceLocation L)
Definition DeclCXX.h:3086
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3067
SourceLocation getExternLoc() const
Definition DeclCXX.h:3083
SourceLocation getRBraceLoc() const
Definition DeclCXX.h:3084
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3078
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:4973
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4990
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition ExprCXX.h:5042
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition ExprCXX.h:5013
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3408
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition Expr.h:3580
SourceLocation getOperatorLoc() const
Definition Expr.h:3590
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition Expr.h:3525
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition Expr.h:3510
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition Expr.h:3491
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition Expr.h:3552
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition Expr.h:3632
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition Expr.cpp:1780
Expr * getBase() const
Definition Expr.h:3485
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition Expr.h:3541
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition Expr.h:3533
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition Expr.h:3585
bool isArrow() const
Definition Expr.h:3592
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition Expr.h:3495
Provides information a specialization of a member of a class template, which may be a member function...
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
This represents a decl that may have a name.
Definition Decl.h:275
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition Decl.cpp:1183
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:296
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:341
Represents a C++ namespace alias.
Definition DeclCXX.h:3230
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3291
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition DeclCXX.h:3313
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3316
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition DeclCXX.h:3319
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition DeclCXX.h:3300
Represent a C++ namespace.
Definition Decl.h:593
SourceLocation getRBraceLoc() const
Definition Decl.h:693
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:692
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:649
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition Decl.h:676
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition Decl.h:658
void setRBraceLoc(SourceLocation L)
Definition Decl.h:695
Class that aids in the construction of nested-name-specifiers along with source-location information ...
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1715
bool hasLeadingEmptyMacro() const
Definition Stmt.h:1729
SourceLocation getSemiLoc() const
Definition Stmt.h:1726
Represents Objective-C's @catch statement.
Definition StmtObjC.h:77
const VarDecl * getCatchParamDecl() const
Definition StmtObjC.h:97
const Stmt * getCatchBody() const
Definition StmtObjC.h:93
SourceLocation getAtCatchLoc() const
Definition StmtObjC.h:105
SourceLocation getRParenLoc() const
Definition StmtObjC.h:107
Represents Objective-C's @finally statement.
Definition StmtObjC.h:127
const Stmt * getFinallyBody() const
Definition StmtObjC.h:139
SourceLocation getAtFinallyLoc() const
Definition StmtObjC.h:148
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
const Expr * getSynchExpr() const
Definition StmtObjC.h:331
const CompoundStmt * getSynchBody() const
Definition StmtObjC.h:323
SourceLocation getAtSynchronizedLoc() const
Definition StmtObjC.h:320
Represents Objective-C's @throw statement.
Definition StmtObjC.h:358
const Expr * getThrowExpr() const
Definition StmtObjC.h:370
SourceLocation getThrowLoc() const LLVM_READONLY
Definition StmtObjC.h:374
Represents Objective-C's @try ... @catch ... @finally statement.
Definition StmtObjC.h:167
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition StmtObjC.h:241
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition StmtObjC.cpp:45
unsigned getNumCatchStmts() const
Retrieve the number of @catch statements in this try-catch-finally block.
Definition StmtObjC.h:220
const ObjCAtCatchStmt * getCatchStmt(unsigned I) const
Retrieve a @catch statement.
Definition StmtObjC.h:223
const Stmt * getTryBody() const
Retrieve the @try body.
Definition StmtObjC.h:214
SourceLocation getAtTryLoc() const
Retrieve the location of the @ in the @try.
Definition StmtObjC.h:210
Represents Objective-C's @autoreleasepool Statement.
Definition StmtObjC.h:394
SourceLocation getAtLoc() const
Definition StmtObjC.h:414
const Stmt * getSubStmt() const
Definition StmtObjC.h:405
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1675
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2335
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:2397
ObjCCategoryImplDecl * getImplementation() const
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2378
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2383
protocol_iterator protocol_end() const
Definition DeclObjC.h:2417
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2420
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2470
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2472
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2427
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2413
void setImplementation(ObjCCategoryImplDecl *ImplD)
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2406
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2466
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2551
SourceLocation getCategoryNameLoc() const
Definition DeclObjC.h:2578
ObjCCategoryDecl * getCategoryDecl() const
SourceLocation getAtStartLoc() const
Definition DeclObjC.h:1102
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
SourceLocation getForLoc() const
Definition StmtObjC.h:52
SourceLocation getRParenLoc() const
Definition StmtObjC.h:54
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2492
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2603
SourceLocation getIvarRBraceLoc() const
Definition DeclObjC.h:2750
SourceLocation getSuperClassLoc() const
Definition DeclObjC.h:2743
const ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.h:2741
SourceLocation getIvarLBraceLoc() const
Definition DeclObjC.h:2748
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:1491
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition DeclObjC.h:1899
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition DeclObjC.h:1309
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:1398
void setImplementation(ObjCImplementationDecl *ImplD)
known_categories_range known_categories() const
Definition DeclObjC.h:1693
void setSuperClass(TypeSourceInfo *superClass)
Definition DeclObjC.h:1594
protocol_iterator protocol_end() const
Definition DeclObjC.h:1380
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition DeclObjC.cpp:369
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition DeclObjC.h:1529
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition DeclObjC.cpp:340
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:1362
ObjCImplementationDecl * getImplementation() const
protocol_iterator protocol_begin() const
Definition DeclObjC.h:1369
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:1391
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition DeclObjC.cpp:613
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition DeclObjC.h:1921
ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.cpp:349
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition DeclObjC.h:1548
TypeSourceInfo * getSuperClassTInfo() const
Definition DeclObjC.h:1579
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1958
AccessControl getAccessControl() const
Definition DeclObjC.h:2006
bool getSynthesize() const
Definition DeclObjC.h:2013
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
ImplicitParamDecl * getSelfDecl() const
Definition DeclObjC.h:421
ArrayRef< ParmVarDecl * > parameters() const
Definition DeclObjC.h:376
unsigned param_size() const
Definition DeclObjC.h:350
bool isPropertyAccessor() const
Definition DeclObjC.h:439
param_const_iterator param_end() const
Definition DeclObjC.h:361
param_const_iterator param_begin() const
Definition DeclObjC.h:357
bool isVariadic() const
Definition DeclObjC.h:434
SourceLocation getEndLoc() const LLVM_READONLY
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition DeclObjC.h:346
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs={})
Sets the method's parameters and selector source locations.
Definition DeclObjC.cpp:962
bool isSynthesizedAccessorStub() const
Definition DeclObjC.h:447
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type.
Definition DeclObjC.h:259
bool isInstanceMethod() const
Definition DeclObjC.h:429
bool isDefined() const
Definition DeclObjC.h:455
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
QualType getReturnType() const
Definition DeclObjC.h:332
ParmVarDecl *const * param_iterator
Definition DeclObjC.h:353
ObjCImplementationControl getImplementationControl() const
Definition DeclObjC.h:503
ObjCInterfaceDecl * getClassInterface()
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition DeclObjC.cpp:956
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:734
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:902
SourceLocation getGetterNameLoc() const
Definition DeclObjC.h:892
ObjCMethodDecl * getGetterMethodDecl() const
Definition DeclObjC.h:907
bool isInstanceProperty() const
Definition DeclObjC.h:860
ObjCMethodDecl * getSetterMethodDecl() const
Definition DeclObjC.h:910
SourceLocation getSetterNameLoc() const
Definition DeclObjC.h:900
SourceLocation getAtLoc() const
Definition DeclObjC.h:802
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:825
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:930
Selector getSetterName() const
Definition DeclObjC.h:899
TypeSourceInfo * getTypeSourceInfo() const
Definition DeclObjC.h:808
QualType getType() const
Definition DeclObjC.h:810
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition DeclObjC.h:837
Selector getGetterName() const
Definition DeclObjC.h:891
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition DeclObjC.h:926
SourceLocation getLParenLoc() const
Definition DeclObjC.h:805
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:911
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition DeclObjC.h:833
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition DeclObjC.h:821
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition DeclObjC.h:894
PropertyControl getPropertyImplementation() const
Definition DeclObjC.h:918
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition DeclObjC.h:908
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2811
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:2885
SourceLocation getPropertyIvarDeclLoc() const
Definition DeclObjC.h:2888
Kind getPropertyImplementation() const
Definition DeclObjC.h:2881
ObjCPropertyDecl * getPropertyDecl() const
Definition DeclObjC.h:2876
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclObjC.h:2873
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2090
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition DeclObjC.h:2267
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition DeclObjC.h:2215
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition DeclObjC.h:2256
void startDefinition()
Starts the definition of this Objective-C protocol.
ObjCProtocolList::iterator protocol_iterator
Definition DeclObjC.h:2164
protocol_iterator protocol_begin() const
Definition DeclObjC.h:2171
ObjCProtocolList::loc_iterator protocol_loc_iterator
Definition DeclObjC.h:2185
protocol_iterator protocol_end() const
Definition DeclObjC.h:2178
protocol_loc_iterator protocol_loc_begin() const
Definition DeclObjC.h:2192
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:581
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition DeclObjC.h:639
const Type * getTypeForDecl() const
Definition Decl.h:3673
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition DeclObjC.h:647
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition DeclObjC.h:626
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition DeclObjC.h:636
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:665
SourceLocation getRAngleLoc() const
Definition DeclObjC.h:714
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
SourceLocation getLAngleLoc() const
Definition DeclObjC.h:713
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2571
Expr * getIndexExpr(unsigned Idx)
Definition Expr.h:2630
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2604
const OffsetOfNode & getComponent(unsigned Idx) const
Definition Expr.h:2618
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition Expr.cpp:1683
TypeSourceInfo * getTypeSourceInfo() const
Definition Expr.h:2611
unsigned getNumExpressions() const
Definition Expr.h:2642
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition Expr.h:2608
unsigned getNumComponents() const
Definition Expr.h:2626
Helper class for OffsetOfExpr.
Definition Expr.h:2465
const IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition Expr.cpp:1718
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition Expr.h:2523
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition Expr.h:2529
@ Array
An index into an array.
Definition Expr.h:2470
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2474
@ Field
A field.
Definition Expr.h:2472
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2477
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:2551
Kind getKind() const
Determine what kind of offsetof node this is.
Definition Expr.h:2519
SourceLocation getEndLoc() const LLVM_READONLY
Definition Expr.h:2552
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition Expr.h:2539
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1198
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1248
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition Expr.h:1220
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h: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:4416
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition ExprCXX.h:4445
UnsignedOrNone getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition ExprCXX.h:4456
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition ExprCXX.h:4452
A structure for storing a pack-index-template-name ([temp.names]).
ArrayRef< TemplateName > getExpansions() const
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2226
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2251
const Expr * getSubExpr() const
Definition Expr.h:2243
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2255
ArrayRef< Expr * > exprs() const
Definition Expr.h:6177
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition Expr.cpp:5003
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition Expr.h:6160
SourceLocation getLParenLoc() const
Definition Expr.h:6179
SourceLocation getRParenLoc() const
Definition Expr.h:6180
Represents a parameter to a function.
Definition Decl.h:1820
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition Decl.h:1901
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1880
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition Decl.h:1888
void setDefaultArg(Expr *defarg)
Definition Decl.cpp:3010
SourceLocation getExplicitObjectParamThisLoc() const
Definition Decl.h:1916
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition Decl.h:1961
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition Decl.h:1949
void setUninstantiatedDefaultArg(Expr *arg)
Definition Decl.cpp:3035
bool isObjCMethodParameter() const
Definition Decl.h:1863
ObjCDeclQualifier getObjCDeclQualifier() const
Definition Decl.h:1884
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1853
bool hasUninstantiatedDefaultArg() const
Definition Decl.h:1953
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition Decl.h:1848
bool hasInheritedDefaultArg() const
Definition Decl.h:1965
void setKNRPromoted(bool promoted)
Definition Decl.h:1904
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition Decl.h:1912
Expr * getDefaultArg()
Definition Decl.cpp: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:1870
void setHasInheritedDefaultArg(bool I=true)
Definition Decl.h:1969
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2049
SourceLocation getBeginLoc() const
Definition Expr.h:2114
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition Expr.cpp:639
bool isTransparent() const
Definition Expr.h:2088
PredefinedIdentKind getIdentKind() const
Definition Expr.h:2084
StringLiteral * getFunctionName()
Definition Expr.h:2093
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2698
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6854
unsigned getResultExprIndex() const
Return the index of the result-bearing expression into the semantics expressions, or PseudoObjectExpr...
Definition Expr.h:6896
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition Expr.cpp:5225
ArrayRef< Expr * > semantics()
Definition Expr.h:6926
unsigned getNumSemanticExprs() const
Definition Expr.h:6911
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition Expr.h:6891
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8418
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8450
Represents a template name as written in source code.
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Represents a struct/union/class.
Definition Decl.h:4460
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition Decl.cpp:5313
void setAnonymousStructOrUnion(bool Anon)
Definition Decl.h:4516
field_range fields() const
Definition Decl.h:4663
RecordDecl * getMostRecentDecl()
Definition Decl.h:4486
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition Decl.cpp:5358
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition Decl.h:4644
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition Decl.h:4512
Provides common interface for the Decls that can be redeclared.
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition Decl.h:5465
Represents the body of a requires-expression.
Definition DeclCXX.h:2118
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
SourceLocation getLParenLoc() const
SourceLocation getRParenLoc() const
SourceLocation getRBraceLoc() const
SourceLocation getRequiresKWLoc() const
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
RequiresExprBodyDecl * getBody() const
ArrayRef< concepts::Requirement * > getRequirements() const
ArrayRef< ParmVarDecl * > getLocalParameters() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3172
SourceLocation getReturnLoc() const
Definition Stmt.h:3221
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization.
Definition Stmt.h:3208
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition Stmt.cpp:1290
Expr * getRetValue()
Definition Stmt.h:3199
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4687
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition Expr.h:4723
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition Expr.h:4720
SourceLocation getRParenLoc() const
Definition Expr.h:4707
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4710
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4494
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4556
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4579
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:4584
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4553
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4559
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4562
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition ExprCXX.h:4568
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5070
SourceLocation getBeginLoc() const
Definition Expr.h:5115
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition Expr.h:5111
SourceLocation getEndLoc() const
Definition Expr.h:5116
SourceLocIdentKind getIdentKind() const
Definition Expr.h:5090
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4165
bool isFailed() const
Definition DeclCXX.h:4194
SourceLocation getRParenLoc() const
Definition DeclCXX.h:4196
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4639
CompoundStmt * getSubStmt()
Definition Expr.h:4656
unsigned getTemplateDepth() const
Definition Expr.h:4668
SourceLocation getRParenLoc() const
Definition Expr.h:4665
SourceLocation getLParenLoc() const
Definition Expr.h:4663
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:85
StmtClass getStmtClass() const
Definition Stmt.h:1505
const char * getStmtClassName() const
Definition Stmt.cpp:86
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1819
bool isPascal() const
Definition Expr.h:1958
tokloc_iterator tokloc_begin() const
Definition Expr.h:2009
tokloc_iterator tokloc_end() const
Definition Expr.h:2013
StringLiteralKind getKind() const
Definition Expr.h:1948
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
Definition Expr.cpp:1194
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition Expr.h:1895
unsigned getNumConcatenated() const
Get the number of string literal tokens that were concatenated in translation phase #6 to form this s...
Definition Expr.h:1985
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4717
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4762
UnsignedOrNone getPackIndex() const
Definition ExprCXX.h:4770
QualType getParameterType() const
Determine the substituted type of the template parameter.
Definition ExprCXX.h:4781
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4768
SourceLocation getNameLoc() const
Definition ExprCXX.h:4752
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4807
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:4855
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition ExprCXX.h:4841
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition ExprCXX.h:4845
A structure for storing an already-substituted template template parameter pack.
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
A structure for storing the information associated with a substituted template template parameter.
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
void setNextSwitchCase(SwitchCase *SC)
Definition Stmt.h:1907
SourceLocation getColonLoc() const
Definition Stmt.h:1911
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1905
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2521
SourceLocation getSwitchLoc() const
Definition Stmt.h:2656
SourceLocation getLParenLoc() const
Definition Stmt.h:2658
SourceLocation getRParenLoc() const
Definition Stmt.h:2660
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition Stmt.cpp:1167
Expr * getCond()
Definition Stmt.h:2584
Stmt * getBody()
Definition Stmt.h:2596
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition Stmt.cpp:1186
Stmt * getInit()
Definition Stmt.h:2601
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2652
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3852
SourceRange getBraceRange() const
Definition Decl.h:3929
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition Decl.h:3973
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition Decl.cpp:4996
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition Decl.h:3948
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3953
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition Decl.h:4106
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition Decl.h:4089
void startDefinition()
Starts the definition of this tag declaration.
Definition Decl.cpp:4973
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition Decl.cpp:4968
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition Decl.cpp:5010
TagKind getTagKind() const
Definition Decl.h:4052
void setBraceRange(SourceRange R)
Definition Decl.h:3930
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition Decl.h:3956
A convenient class for passing around template argument information.
SourceLocation getRAngleLoc() const
void addArgument(const TemplateArgumentLoc &Loc)
ArrayRef< TemplateArgumentLoc > arguments() const
SourceLocation getLAngleLoc() const
A template argument list.
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Location wrapper for a TemplateArgument.
TemplateArgumentLocInfo getLocInfo() const
const TemplateArgument & getArgument() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
UnsignedOrNone getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
unsigned pack_size() const
The number of template arguments in the given template argument pack.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isCanonicalExpr() const
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
bool isNull() const
Determine whether this template name is NULL.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
@ OverloadedTemplate
A set of overloaded template declarations.
@ PackIndexingTemplate
A pack-index-template-name.
@ Template
A single template declaration.
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
PackIndexingTemplateStorage * getAsPackIndexingTemplate() const
Retrieve the pack-index-template-name storage, if any.
A template parameter object.
const APValue & getValue() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
SourceLocation getRAngleLoc() const
SourceLocation getLAngleLoc() const
SourceLocation getTemplateLoc() const
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
TemplateNameKind templateParameterKind() const
unsigned getPosition() const
Get the position of the template parameter within its parameter list.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
unsigned getDepth() const
Get the nesting depth of the template parameter.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
unsigned getIndex() const
Retrieve the index of the template parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
The top declaration context.
Definition Decl.h:106
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3823
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition Decl.h:3841
Declaration of an alias template.
TypeAliasDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition ASTConcept.h:227
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:3682
Symbolic representation of typeid(T) for some type T.
Definition APValue.h: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:8389
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:8400
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:8754
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:9207
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:9254
bool isRecordType() const
Definition TypeBase.h:8782
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3802
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3697
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3747
QualType getUnderlyingType() const
Definition Decl.h:3752
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2669
SourceLocation getRParenLoc() const
Definition Expr.h:2745
SourceLocation getOperatorLoc() const
Definition Expr.h:2742
TypeSourceInfo * getArgumentTypeInfo() const
Definition Expr.h:2715
UnaryExprOrTypeTrait getKind() const
Definition Expr.h:2701
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2288
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2333
Expr * getSubExpr() const
Definition Expr.h:2329
Opcode getOpcode() const
Definition Expr.h:2324
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition Expr.h:2425
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition Expr.h:2428
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition Expr.cpp:5167
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition Expr.h:2342
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h: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:4179
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition ExprCXX.h:4271
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition ExprCXX.h:4274
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition ExprCXX.h:4265
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition ExprCXX.h:4252
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:4066
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition DeclCXX.h:4096
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4100
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4093
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4117
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3969
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition DeclCXX.h:4000
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:4010
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:4017
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition DeclCXX.h:4027
Represents a C++ using-declaration.
Definition DeclCXX.h:3620
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3669
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition DeclCXX.h:3654
DeclarationNameInfo getNameInfo() const
Definition DeclCXX.h:3661
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition DeclCXX.h:3647
Represents C++ using-directive.
Definition DeclCXX.h:3125
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition DeclCXX.h:3196
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:3192
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition DeclCXX.h:3200
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition DeclCXX.h:3203
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition DeclCXX.h:3170
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3821
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition DeclCXX.h:3845
TypeSourceInfo * getEnumType() const
Definition DeclCXX.h:3857
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition DeclCXX.h:3841
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition DeclCXX.h:3902
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition DeclCXX.h:3931
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition DeclCXX.h:3935
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3428
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3492
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition DeclCXX.cpp:3487
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:5001
TypeSourceInfo * getWrittenTypeInfo() const
Definition Expr.h:5034
SourceLocation getBuiltinLoc() const
Definition Expr.h:5037
SourceLocation getRParenLoc() const
Definition Expr.h:5040
VarArgKind getVarargABI() const
Definition Expr.h:5025
const Expr * getSubExpr() const
Definition Expr.h:5021
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:713
void setType(QualType newType)
Definition Decl.h:725
QualType getType() const
Definition Decl.h:724
Represents a variable declaration or definition.
Definition Decl.h:933
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition Decl.cpp:2782
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1594
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition Decl.cpp: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:1579
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:1583
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:1366
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition Decl.h:1180
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1576
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1184
const Expr * getInit() const
Definition Decl.h:1392
void setConstexpr(bool IC)
Definition Decl.h:1597
void setInit(Expr *I)
Definition Decl.cpp:2459
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition Decl.cpp:2787
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1175
void setImplicitlyInline()
Definition Decl.h:1588
VarDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition Decl.h:1382
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition Decl.cpp: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:89
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition Decl.h:886
unsigned HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition Decl.h:900
unsigned HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition Decl.h:908
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5454
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5458
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5444
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5447
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5450
Extra information about a function prototype.
Definition TypeBase.h:5470
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