clang 19.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
19#include "clang/AST/Attr.h"
20#include "clang/AST/Decl.h"
22#include "clang/AST/DeclBase.h"
23#include "clang/AST/DeclCXX.h"
25#include "clang/AST/DeclGroup.h"
26#include "clang/AST/DeclObjC.h"
30#include "clang/AST/Expr.h"
31#include "clang/AST/ExprCXX.h"
32#include "clang/AST/ExprObjC.h"
37#include "clang/AST/Stmt.h"
38#include "clang/AST/StmtCXX.h"
39#include "clang/AST/StmtObjC.h"
43#include "clang/AST/Type.h"
44#include "clang/AST/TypeLoc.h"
51#include "clang/Basic/LLVM.h"
56#include "llvm/ADT/APSInt.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/Casting.h"
63#include "llvm/Support/ErrorHandling.h"
64#include "llvm/Support/MemoryBuffer.h"
65#include <algorithm>
66#include <cassert>
67#include <cstddef>
68#include <memory>
69#include <optional>
70#include <type_traits>
71#include <utility>
72
73namespace clang {
74
75 using llvm::make_error;
76 using llvm::Error;
77 using llvm::Expected;
85
86 std::string ASTImportError::toString() const {
87 // FIXME: Improve error texts.
88 switch (Error) {
89 case NameConflict:
90 return "NameConflict";
92 return "UnsupportedConstruct";
93 case Unknown:
94 return "Unknown error";
95 }
96 llvm_unreachable("Invalid error code.");
97 return "Invalid error code.";
98 }
99
100 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
101
102 std::error_code ASTImportError::convertToErrorCode() const {
103 llvm_unreachable("Function not implemented.");
104 }
105
107
108 template <class T>
112 for (auto *R : D->getFirstDecl()->redecls()) {
113 if (R != D->getFirstDecl())
114 Redecls.push_back(R);
115 }
116 Redecls.push_back(D->getFirstDecl());
117 std::reverse(Redecls.begin(), Redecls.end());
118 return Redecls;
119 }
120
122 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
124 if (auto *VD = dyn_cast<VarDecl>(D))
125 return getCanonicalForwardRedeclChain<VarDecl>(VD);
126 if (auto *TD = dyn_cast<TagDecl>(D))
127 return getCanonicalForwardRedeclChain<TagDecl>(TD);
128 llvm_unreachable("Bad declaration kind");
129 }
130
131 void updateFlags(const Decl *From, Decl *To) {
132 // Check if some flags or attrs are new in 'From' and copy into 'To'.
133 // FIXME: Other flags or attrs?
134 if (From->isUsed(false) && !To->isUsed(false))
135 To->setIsUsed();
136 }
137
138 /// How to handle import errors that occur when import of a child declaration
139 /// of a DeclContext fails.
141 /// This context is imported (in the 'from' domain).
142 /// It is nullptr if a non-DeclContext is imported.
143 const DeclContext *const FromDC;
144 /// Ignore import errors of the children.
145 /// If true, the context can be imported successfully if a child
146 /// of it failed to import. Otherwise the import errors of the child nodes
147 /// are accumulated (joined) into the import error object of the parent.
148 /// (Import of a parent can fail in other ways.)
149 bool const IgnoreChildErrors;
150
151 public:
153 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
155 : FromDC(dyn_cast<DeclContext>(FromD)),
156 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
157
158 /// Process the import result of a child (of the current declaration).
159 /// \param ResultErr The import error that can be used as result of
160 /// importing the parent. This may be changed by the function.
161 /// \param ChildErr Result of importing a child. Can be success or error.
162 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
163 if (ChildErr && !IgnoreChildErrors)
164 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
165 else
166 consumeError(std::move(ChildErr));
167 }
168
169 /// Determine if import failure of a child does not cause import failure of
170 /// its parent.
171 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
172 if (!IgnoreChildErrors || !FromDC)
173 return false;
174 return FromDC->containsDecl(FromChildD);
175 }
176 };
177
178 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
179 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
180 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
181 ASTImporter &Importer;
182
183 // Use this instead of Importer.importInto .
184 template <typename ImportT>
185 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
186 return Importer.importInto(To, From);
187 }
188
189 // Use this to import pointers of specific type.
190 template <typename ImportT>
191 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
192 auto ToOrErr = Importer.Import(From);
193 if (ToOrErr)
194 To = cast_or_null<ImportT>(*ToOrErr);
195 return ToOrErr.takeError();
196 }
197
198 // Call the import function of ASTImporter for a baseclass of type `T` and
199 // cast the return value to `T`.
200 template <typename T>
201 auto import(T *From)
202 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
204 auto ToOrErr = Importer.Import(From);
205 if (!ToOrErr)
206 return ToOrErr.takeError();
207 return cast_or_null<T>(*ToOrErr);
208 }
209
210 template <typename T>
211 auto import(const T *From) {
212 return import(const_cast<T *>(From));
213 }
214
215 // Call the import function of ASTImporter for type `T`.
216 template <typename T>
217 Expected<T> import(const T &From) {
218 return Importer.Import(From);
219 }
220
221 // Import an std::optional<T> by importing the contained T, if any.
222 template <typename T>
223 Expected<std::optional<T>> import(std::optional<T> From) {
224 if (!From)
225 return std::nullopt;
226 return import(*From);
227 }
228
229 ExplicitSpecifier importExplicitSpecifier(Error &Err,
230 ExplicitSpecifier ESpec);
231
232 // Wrapper for an overload set.
233 template <typename ToDeclT> struct CallOverloadedCreateFun {
234 template <typename... Args> decltype(auto) operator()(Args &&... args) {
235 return ToDeclT::Create(std::forward<Args>(args)...);
236 }
237 };
238
239 // Always use these functions to create a Decl during import. There are
240 // certain tasks which must be done after the Decl was created, e.g. we
241 // must immediately register that as an imported Decl. The parameter `ToD`
242 // will be set to the newly created Decl or if had been imported before
243 // then to the already imported Decl. Returns a bool value set to true if
244 // the `FromD` had been imported before.
245 template <typename ToDeclT, typename FromDeclT, typename... Args>
246 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
247 Args &&...args) {
248 // There may be several overloads of ToDeclT::Create. We must make sure
249 // to call the one which would be chosen by the arguments, thus we use a
250 // wrapper for the overload set.
251 CallOverloadedCreateFun<ToDeclT> OC;
252 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
253 std::forward<Args>(args)...);
254 }
255 // Use this overload if a special Type is needed to be created. E.g if we
256 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
257 // then:
258 // TypedefNameDecl *ToTypedef;
259 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
260 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
261 typename... Args>
262 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
263 Args &&...args) {
264 CallOverloadedCreateFun<NewDeclT> OC;
265 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
266 std::forward<Args>(args)...);
267 }
268 // Use this version if a special create function must be
269 // used, e.g. CXXRecordDecl::CreateLambda .
270 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
271 typename... Args>
272 [[nodiscard]] bool
273 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
274 FromDeclT *FromD, Args &&...args) {
275 if (Importer.getImportDeclErrorIfAny(FromD)) {
276 ToD = nullptr;
277 return true; // Already imported but with error.
278 }
279 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
280 if (ToD)
281 return true; // Already imported.
282 ToD = CreateFun(std::forward<Args>(args)...);
283 // Keep track of imported Decls.
284 Importer.RegisterImportedDecl(FromD, ToD);
285 Importer.SharedState->markAsNewDecl(ToD);
286 InitializeImportedDecl(FromD, ToD);
287 return false; // A new Decl is created.
288 }
289
290 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
291 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
292 if (FromD->isUsed())
293 ToD->setIsUsed();
294 if (FromD->isImplicit())
295 ToD->setImplicit();
296 }
297
298 // Check if we have found an existing definition. Returns with that
299 // definition if yes, otherwise returns null.
300 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
301 const FunctionDecl *Definition = nullptr;
303 FoundFunction->hasBody(Definition))
304 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
305 return nullptr;
306 }
307
308 void addDeclToContexts(Decl *FromD, Decl *ToD) {
309 if (Importer.isMinimalImport()) {
310 // In minimal import case the decl must be added even if it is not
311 // contained in original context, for LLDB compatibility.
312 // FIXME: Check if a better solution is possible.
313 if (!FromD->getDescribedTemplate() &&
314 FromD->getFriendObjectKind() == Decl::FOK_None)
316 return;
317 }
318
319 DeclContext *FromDC = FromD->getDeclContext();
320 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
321 DeclContext *ToDC = ToD->getDeclContext();
322 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
323
324 bool Visible = false;
325 if (FromDC->containsDeclAndLoad(FromD)) {
326 ToDC->addDeclInternal(ToD);
327 Visible = true;
328 }
329 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
330 ToLexicalDC->addDeclInternal(ToD);
331 Visible = true;
332 }
333
334 // If the Decl was added to any context, it was made already visible.
335 // Otherwise it is still possible that it should be visible.
336 if (!Visible) {
337 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
338 auto *ToNamed = cast<NamedDecl>(ToD);
339 DeclContextLookupResult FromLookup =
340 FromDC->lookup(FromNamed->getDeclName());
341 if (llvm::is_contained(FromLookup, FromNamed))
342 ToDC->makeDeclVisibleInContext(ToNamed);
343 }
344 }
345 }
346
347 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
348 DeclContext *OldDC) {
349 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
350 if (!LT)
351 return;
352
353 for (NamedDecl *TP : Params)
354 LT->update(TP, OldDC);
355 }
356
357 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
358 updateLookupTableForTemplateParameters(
359 Params, Importer.getToContext().getTranslationUnitDecl());
360 }
361
362 public:
363 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
364
368
369 // Importing types
371#define TYPE(Class, Base) \
372 ExpectedType Visit##Class##Type(const Class##Type *T);
373#include "clang/AST/TypeNodes.inc"
374
375 // Importing declarations
376 Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD,
377 SourceLocation &Loc);
378 Error ImportDeclParts(
379 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
380 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc);
381 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
384 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
385 Error ImportDeclContext(
386 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
387 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
388
389 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
391 Expected<APValue> ImportAPValue(const APValue &FromValue);
392
394
395 /// What we should import from the definition.
397 /// Import the default subset of the definition, which might be
398 /// nothing (if minimal import is set) or might be everything (if minimal
399 /// import is not set).
401 /// Import everything.
403 /// Import only the bare bones needed to establish a valid
404 /// DeclContext.
406 };
407
409 return IDK == IDK_Everything ||
410 (IDK == IDK_Default && !Importer.isMinimalImport());
411 }
412
413 Error ImportInitializer(VarDecl *From, VarDecl *To);
414 Error ImportDefinition(
415 RecordDecl *From, RecordDecl *To,
417 Error ImportDefinition(
418 EnumDecl *From, EnumDecl *To,
420 Error ImportDefinition(
423 Error ImportDefinition(
430
431 template <typename InContainerTy>
433 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
434
435 template<typename InContainerTy>
437 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
438 const InContainerTy &Container, TemplateArgumentListInfo &Result);
439
442 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
445 FunctionDecl *FromFD);
447 DeclaratorDecl *ToD);
448
450
452
453 Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
454 ParmVarDecl *ToParam);
455
458
459 template <typename T>
460 bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
461
462 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
463 bool IgnoreTemplateParmDepth = false);
510
513
528
529 // Importing statements
549 // FIXME: MSAsmStmt
550 // FIXME: SEHExceptStmt
551 // FIXME: SEHFinallyStmt
552 // FIXME: SEHTryStmt
553 // FIXME: SEHLeaveStmt
554 // FIXME: CapturedStmt
558 // FIXME: MSDependentExistsStmt
566
567 // Importing expressions
644
645 // Helper for chaining together multiple imports. If an error is detected,
646 // subsequent imports will return default constructed nodes, so that failure
647 // can be detected with a single conditional branch after a sequence of
648 // imports.
649 template <typename T> T importChecked(Error &Err, const T &From) {
650 // Don't attempt to import nodes if we hit an error earlier.
651 if (Err)
652 return T{};
653 Expected<T> MaybeVal = import(From);
654 if (!MaybeVal) {
655 Err = MaybeVal.takeError();
656 return T{};
657 }
658 return *MaybeVal;
659 }
660
661 template<typename IIter, typename OIter>
662 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
663 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
664 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
665 Expected<ItemT> ToOrErr = import(*Ibegin);
666 if (!ToOrErr)
667 return ToOrErr.takeError();
668 *Obegin = *ToOrErr;
669 }
670 return Error::success();
671 }
672
673 // Import every item from a container structure into an output container.
674 // If error occurs, stops at first error and returns the error.
675 // The output container should have space for all needed elements (it is not
676 // expanded, new items are put into from the beginning).
677 template<typename InContainerTy, typename OutContainerTy>
679 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
680 return ImportArrayChecked(
681 InContainer.begin(), InContainer.end(), OutContainer.begin());
682 }
683
684 template<typename InContainerTy, typename OIter>
685 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
686 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
687 }
688
690 CXXMethodDecl *FromMethod);
691
693 FunctionDecl *FromFD);
694
695 // Returns true if the given function has a placeholder return type and
696 // that type is declared inside the body of the function.
697 // E.g. auto f() { struct X{}; return X(); }
699 };
700
701template <typename InContainerTy>
703 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
704 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
705 auto ToLAngleLocOrErr = import(FromLAngleLoc);
706 if (!ToLAngleLocOrErr)
707 return ToLAngleLocOrErr.takeError();
708 auto ToRAngleLocOrErr = import(FromRAngleLoc);
709 if (!ToRAngleLocOrErr)
710 return ToRAngleLocOrErr.takeError();
711
712 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
713 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
714 return Err;
715 Result = ToTAInfo;
716 return Error::success();
717}
718
719template <>
720Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
723 From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
724}
725
726template <>
729 const ASTTemplateArgumentListInfo &From,
731 return ImportTemplateArgumentListInfo(
732 From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
733}
734
737 FunctionDecl *FromFD) {
738 assert(FromFD->getTemplatedKind() ==
740
742
743 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
744 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
745 return std::move(Err);
746
747 // Import template arguments.
748 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
749 std::get<1>(Result)))
750 return std::move(Err);
751
752 return Result;
753}
754
755template <>
757ASTNodeImporter::import(TemplateParameterList *From) {
759 if (Error Err = ImportContainerChecked(*From, To))
760 return std::move(Err);
761
762 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
763 if (!ToRequiresClause)
764 return ToRequiresClause.takeError();
765
766 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
767 if (!ToTemplateLocOrErr)
768 return ToTemplateLocOrErr.takeError();
769 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
770 if (!ToLAngleLocOrErr)
771 return ToLAngleLocOrErr.takeError();
772 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
773 if (!ToRAngleLocOrErr)
774 return ToRAngleLocOrErr.takeError();
775
777 Importer.getToContext(),
778 *ToTemplateLocOrErr,
779 *ToLAngleLocOrErr,
780 To,
781 *ToRAngleLocOrErr,
782 *ToRequiresClause);
783}
784
785template <>
787ASTNodeImporter::import(const TemplateArgument &From) {
788 switch (From.getKind()) {
790 return TemplateArgument();
791
793 ExpectedType ToTypeOrErr = import(From.getAsType());
794 if (!ToTypeOrErr)
795 return ToTypeOrErr.takeError();
796 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
797 From.getIsDefaulted());
798 }
799
801 ExpectedType ToTypeOrErr = import(From.getIntegralType());
802 if (!ToTypeOrErr)
803 return ToTypeOrErr.takeError();
804 return TemplateArgument(From, *ToTypeOrErr);
805 }
806
808 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
809 if (!ToOrErr)
810 return ToOrErr.takeError();
811 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
812 if (!ToTypeOrErr)
813 return ToTypeOrErr.takeError();
814 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
815 *ToTypeOrErr, From.getIsDefaulted());
816 }
817
819 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
820 if (!ToTypeOrErr)
821 return ToTypeOrErr.takeError();
822 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
823 From.getIsDefaulted());
824 }
825
827 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
828 if (!ToTypeOrErr)
829 return ToTypeOrErr.takeError();
830 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
831 if (!ToValueOrErr)
832 return ToValueOrErr.takeError();
833 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
834 *ToValueOrErr);
835 }
836
838 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
839 if (!ToTemplateOrErr)
840 return ToTemplateOrErr.takeError();
841
842 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
843 }
844
846 Expected<TemplateName> ToTemplateOrErr =
847 import(From.getAsTemplateOrTemplatePattern());
848 if (!ToTemplateOrErr)
849 return ToTemplateOrErr.takeError();
850
851 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
852 From.getIsDefaulted());
853 }
854
856 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
857 return TemplateArgument(*ToExpr, From.getIsDefaulted());
858 else
859 return ToExpr.takeError();
860
863 ToPack.reserve(From.pack_size());
864 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
865 return std::move(Err);
866
867 return TemplateArgument(
868 llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
869 }
870 }
871
872 llvm_unreachable("Invalid template argument kind");
873}
874
875template <>
877ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
878 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
879 if (!ArgOrErr)
880 return ArgOrErr.takeError();
881 TemplateArgument Arg = *ArgOrErr;
882
883 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
884
887 ExpectedExpr E = import(FromInfo.getAsExpr());
888 if (!E)
889 return E.takeError();
890 ToInfo = TemplateArgumentLocInfo(*E);
891 } else if (Arg.getKind() == TemplateArgument::Type) {
892 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
893 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
894 else
895 return TSIOrErr.takeError();
896 } else {
897 auto ToTemplateQualifierLocOrErr =
898 import(FromInfo.getTemplateQualifierLoc());
899 if (!ToTemplateQualifierLocOrErr)
900 return ToTemplateQualifierLocOrErr.takeError();
901 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
902 if (!ToTemplateNameLocOrErr)
903 return ToTemplateNameLocOrErr.takeError();
904 auto ToTemplateEllipsisLocOrErr =
905 import(FromInfo.getTemplateEllipsisLoc());
906 if (!ToTemplateEllipsisLocOrErr)
907 return ToTemplateEllipsisLocOrErr.takeError();
909 Importer.getToContext(), *ToTemplateQualifierLocOrErr,
910 *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
911 }
912
913 return TemplateArgumentLoc(Arg, ToInfo);
914}
915
916template <>
917Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
918 if (DG.isNull())
919 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
920 size_t NumDecls = DG.end() - DG.begin();
922 ToDecls.reserve(NumDecls);
923 for (Decl *FromD : DG) {
924 if (auto ToDOrErr = import(FromD))
925 ToDecls.push_back(*ToDOrErr);
926 else
927 return ToDOrErr.takeError();
928 }
929 return DeclGroupRef::Create(Importer.getToContext(),
930 ToDecls.begin(),
931 NumDecls);
932}
933
934template <>
936ASTNodeImporter::import(const Designator &D) {
937 if (D.isFieldDesignator()) {
938 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
939
940 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
941 if (!ToDotLocOrErr)
942 return ToDotLocOrErr.takeError();
943
944 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
945 if (!ToFieldLocOrErr)
946 return ToFieldLocOrErr.takeError();
947
949 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
950 }
951
952 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
953 if (!ToLBracketLocOrErr)
954 return ToLBracketLocOrErr.takeError();
955
956 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
957 if (!ToRBracketLocOrErr)
958 return ToRBracketLocOrErr.takeError();
959
960 if (D.isArrayDesignator())
962 *ToLBracketLocOrErr,
963 *ToRBracketLocOrErr);
964
965 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
966 if (!ToEllipsisLocOrErr)
967 return ToEllipsisLocOrErr.takeError();
968
969 assert(D.isArrayRangeDesignator());
971 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
972 *ToRBracketLocOrErr);
973}
974
975template <>
976Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
977 Error Err = Error::success();
978 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
979 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
980 auto ToConceptNameLoc =
982 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
983 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
984 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
985 if (Err)
986 return std::move(Err);
988 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
989 if (ASTTemplateArgs)
990 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
991 return std::move(Err);
992 auto *ConceptRef = ConceptReference::Create(
993 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
994 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
995 ToNamedConcept,
996 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
997 Importer.getToContext(), ToTAInfo)
998 : nullptr);
999 return ConceptRef;
1000}
1001
1002template <>
1003Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1004 ValueDecl *Var = nullptr;
1005 if (From.capturesVariable()) {
1006 if (auto VarOrErr = import(From.getCapturedVar()))
1007 Var = *VarOrErr;
1008 else
1009 return VarOrErr.takeError();
1010 }
1011
1012 auto LocationOrErr = import(From.getLocation());
1013 if (!LocationOrErr)
1014 return LocationOrErr.takeError();
1015
1016 SourceLocation EllipsisLoc;
1017 if (From.isPackExpansion())
1018 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1019 return std::move(Err);
1020
1021 return LambdaCapture(
1022 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1023 EllipsisLoc);
1024}
1025
1026template <typename T>
1028 if (Found->getLinkageInternal() != From->getLinkageInternal())
1029 return false;
1030
1031 if (From->hasExternalFormalLinkage())
1032 return Found->hasExternalFormalLinkage();
1033 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1034 return false;
1035 if (From->isInAnonymousNamespace())
1036 return Found->isInAnonymousNamespace();
1037 else
1038 return !Found->isInAnonymousNamespace() &&
1039 !Found->hasExternalFormalLinkage();
1040}
1041
1042template <>
1044 TypedefNameDecl *From) {
1045 if (Found->getLinkageInternal() != From->getLinkageInternal())
1046 return false;
1047
1048 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1049 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1050 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1051}
1052
1053} // namespace clang
1054
1055//----------------------------------------------------------------------------
1056// Import Types
1057//----------------------------------------------------------------------------
1058
1059using namespace clang;
1060
1062 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1063 << T->getTypeClassName();
1064 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1065}
1066
1067ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1068 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1069 if (!UnderlyingTypeOrErr)
1070 return UnderlyingTypeOrErr.takeError();
1071
1072 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1073}
1074
1075ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1076 switch (T->getKind()) {
1077#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1078 case BuiltinType::Id: \
1079 return Importer.getToContext().SingletonId;
1080#include "clang/Basic/OpenCLImageTypes.def"
1081#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1082 case BuiltinType::Id: \
1083 return Importer.getToContext().Id##Ty;
1084#include "clang/Basic/OpenCLExtensionTypes.def"
1085#define SVE_TYPE(Name, Id, SingletonId) \
1086 case BuiltinType::Id: \
1087 return Importer.getToContext().SingletonId;
1088#include "clang/Basic/AArch64SVEACLETypes.def"
1089#define PPC_VECTOR_TYPE(Name, Id, Size) \
1090 case BuiltinType::Id: \
1091 return Importer.getToContext().Id##Ty;
1092#include "clang/Basic/PPCTypes.def"
1093#define RVV_TYPE(Name, Id, SingletonId) \
1094 case BuiltinType::Id: \
1095 return Importer.getToContext().SingletonId;
1096#include "clang/Basic/RISCVVTypes.def"
1097#define WASM_TYPE(Name, Id, SingletonId) \
1098 case BuiltinType::Id: \
1099 return Importer.getToContext().SingletonId;
1100#include "clang/Basic/WebAssemblyReferenceTypes.def"
1101#define SHARED_SINGLETON_TYPE(Expansion)
1102#define BUILTIN_TYPE(Id, SingletonId) \
1103 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1104#include "clang/AST/BuiltinTypes.def"
1105
1106 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1107 // context supports C++.
1108
1109 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1110 // context supports ObjC.
1111
1112 case BuiltinType::Char_U:
1113 // The context we're importing from has an unsigned 'char'. If we're
1114 // importing into a context with a signed 'char', translate to
1115 // 'unsigned char' instead.
1116 if (Importer.getToContext().getLangOpts().CharIsSigned)
1117 return Importer.getToContext().UnsignedCharTy;
1118
1119 return Importer.getToContext().CharTy;
1120
1121 case BuiltinType::Char_S:
1122 // The context we're importing from has an unsigned 'char'. If we're
1123 // importing into a context with a signed 'char', translate to
1124 // 'unsigned char' instead.
1125 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1126 return Importer.getToContext().SignedCharTy;
1127
1128 return Importer.getToContext().CharTy;
1129
1130 case BuiltinType::WChar_S:
1131 case BuiltinType::WChar_U:
1132 // FIXME: If not in C++, shall we translate to the C equivalent of
1133 // wchar_t?
1134 return Importer.getToContext().WCharTy;
1135 }
1136
1137 llvm_unreachable("Invalid BuiltinType Kind!");
1138}
1139
1140ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1141 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1142 if (!ToOriginalTypeOrErr)
1143 return ToOriginalTypeOrErr.takeError();
1144
1145 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1146}
1147
1148ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1149 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1150 if (!ToElementTypeOrErr)
1151 return ToElementTypeOrErr.takeError();
1152
1153 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1154}
1155
1156ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1157 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1158 if (!ToPointeeTypeOrErr)
1159 return ToPointeeTypeOrErr.takeError();
1160
1161 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1162}
1163
1164ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1165 // FIXME: Check for blocks support in "to" context.
1166 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1167 if (!ToPointeeTypeOrErr)
1168 return ToPointeeTypeOrErr.takeError();
1169
1170 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1171}
1172
1174ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1175 // FIXME: Check for C++ support in "to" context.
1176 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1177 if (!ToPointeeTypeOrErr)
1178 return ToPointeeTypeOrErr.takeError();
1179
1180 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1181}
1182
1184ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1185 // FIXME: Check for C++0x support in "to" context.
1186 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1187 if (!ToPointeeTypeOrErr)
1188 return ToPointeeTypeOrErr.takeError();
1189
1190 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1191}
1192
1194ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1195 // FIXME: Check for C++ support in "to" context.
1196 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1197 if (!ToPointeeTypeOrErr)
1198 return ToPointeeTypeOrErr.takeError();
1199
1200 ExpectedTypePtr ClassTypeOrErr = import(T->getClass());
1201 if (!ClassTypeOrErr)
1202 return ClassTypeOrErr.takeError();
1203
1204 return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr,
1205 *ClassTypeOrErr);
1206}
1207
1209ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1210 Error Err = Error::success();
1211 auto ToElementType = importChecked(Err, T->getElementType());
1212 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1213 if (Err)
1214 return std::move(Err);
1215
1216 return Importer.getToContext().getConstantArrayType(
1217 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1218 T->getIndexTypeCVRQualifiers());
1219}
1220
1222ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1223 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1224 if (!ToArrayTypeOrErr)
1225 return ToArrayTypeOrErr.takeError();
1226
1227 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1228}
1229
1231ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1232 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1233 if (!ToElementTypeOrErr)
1234 return ToElementTypeOrErr.takeError();
1235
1236 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1237 T->getSizeModifier(),
1238 T->getIndexTypeCVRQualifiers());
1239}
1240
1242ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1243 Error Err = Error::success();
1244 QualType ToElementType = importChecked(Err, T->getElementType());
1245 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1246 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1247 if (Err)
1248 return std::move(Err);
1249 return Importer.getToContext().getVariableArrayType(
1250 ToElementType, ToSizeExpr, T->getSizeModifier(),
1251 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1252}
1253
1254ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1255 const DependentSizedArrayType *T) {
1256 Error Err = Error::success();
1257 QualType ToElementType = importChecked(Err, T->getElementType());
1258 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1259 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1260 if (Err)
1261 return std::move(Err);
1262 // SizeExpr may be null if size is not specified directly.
1263 // For example, 'int a[]'.
1264
1265 return Importer.getToContext().getDependentSizedArrayType(
1266 ToElementType, ToSizeExpr, T->getSizeModifier(),
1267 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1268}
1269
1270ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1272 Error Err = Error::success();
1273 QualType ToElementType = importChecked(Err, T->getElementType());
1274 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1275 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1276 if (Err)
1277 return std::move(Err);
1279 ToElementType, ToSizeExpr, ToAttrLoc);
1280}
1281
1282ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1283 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1284 if (!ToElementTypeOrErr)
1285 return ToElementTypeOrErr.takeError();
1286
1287 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1288 T->getNumElements(),
1289 T->getVectorKind());
1290}
1291
1292ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1293 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1294 if (!ToElementTypeOrErr)
1295 return ToElementTypeOrErr.takeError();
1296
1297 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1298 T->getNumElements());
1299}
1300
1302ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1303 // FIXME: What happens if we're importing a function without a prototype
1304 // into C++? Should we make it variadic?
1305 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1306 if (!ToReturnTypeOrErr)
1307 return ToReturnTypeOrErr.takeError();
1308
1309 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1310 T->getExtInfo());
1311}
1312
1314ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1315 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1316 if (!ToReturnTypeOrErr)
1317 return ToReturnTypeOrErr.takeError();
1318
1319 // Import argument types
1320 SmallVector<QualType, 4> ArgTypes;
1321 for (const auto &A : T->param_types()) {
1322 ExpectedType TyOrErr = import(A);
1323 if (!TyOrErr)
1324 return TyOrErr.takeError();
1325 ArgTypes.push_back(*TyOrErr);
1326 }
1327
1328 // Import exception types
1329 SmallVector<QualType, 4> ExceptionTypes;
1330 for (const auto &E : T->exceptions()) {
1331 ExpectedType TyOrErr = import(E);
1332 if (!TyOrErr)
1333 return TyOrErr.takeError();
1334 ExceptionTypes.push_back(*TyOrErr);
1335 }
1336
1338 Error Err = Error::success();
1340 ToEPI.ExtInfo = FromEPI.ExtInfo;
1341 ToEPI.Variadic = FromEPI.Variadic;
1342 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1343 ToEPI.TypeQuals = FromEPI.TypeQuals;
1344 ToEPI.RefQualifier = FromEPI.RefQualifier;
1345 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1352 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1353
1354 if (Err)
1355 return std::move(Err);
1356
1357 return Importer.getToContext().getFunctionType(
1358 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1359}
1360
1361ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1362 const UnresolvedUsingType *T) {
1363 Error Err = Error::success();
1364 auto ToD = importChecked(Err, T->getDecl());
1365 auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
1366 if (Err)
1367 return std::move(Err);
1368
1369 return Importer.getToContext().getTypeDeclType(
1370 ToD, cast_or_null<TypeDecl>(ToPrevD));
1371}
1372
1373ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1374 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1375 if (!ToInnerTypeOrErr)
1376 return ToInnerTypeOrErr.takeError();
1377
1378 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1379}
1380
1382ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1383
1384 ExpectedType Pattern = import(T->getPattern());
1385 if (!Pattern)
1386 return Pattern.takeError();
1387 ExpectedExpr Index = import(T->getIndexExpr());
1388 if (!Index)
1389 return Index.takeError();
1390 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1391}
1392
1393ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1394 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1395 if (!ToDeclOrErr)
1396 return ToDeclOrErr.takeError();
1397
1398 TypedefNameDecl *ToDecl = *ToDeclOrErr;
1399 if (ToDecl->getTypeForDecl())
1400 return QualType(ToDecl->getTypeForDecl(), 0);
1401
1402 ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
1403 if (!ToUnderlyingTypeOrErr)
1404 return ToUnderlyingTypeOrErr.takeError();
1405
1406 return Importer.getToContext().getTypedefType(ToDecl, *ToUnderlyingTypeOrErr);
1407}
1408
1409ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1410 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1411 if (!ToExprOrErr)
1412 return ToExprOrErr.takeError();
1413 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1414}
1415
1416ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1417 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1418 if (!ToUnderlyingTypeOrErr)
1419 return ToUnderlyingTypeOrErr.takeError();
1420 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1421 T->getKind());
1422}
1423
1424ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1425 Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl());
1426 if (!FoundOrErr)
1427 return FoundOrErr.takeError();
1428 Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType());
1429 if (!UnderlyingOrErr)
1430 return UnderlyingOrErr.takeError();
1431
1432 return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr);
1433}
1434
1435ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1436 // FIXME: Make sure that the "to" context supports C++0x!
1437 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1438 if (!ToExprOrErr)
1439 return ToExprOrErr.takeError();
1440
1441 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1442 if (!ToUnderlyingTypeOrErr)
1443 return ToUnderlyingTypeOrErr.takeError();
1444
1445 return Importer.getToContext().getDecltypeType(
1446 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1447}
1448
1450ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1451 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1452 if (!ToBaseTypeOrErr)
1453 return ToBaseTypeOrErr.takeError();
1454
1455 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1456 if (!ToUnderlyingTypeOrErr)
1457 return ToUnderlyingTypeOrErr.takeError();
1458
1459 return Importer.getToContext().getUnaryTransformType(
1460 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1461}
1462
1463ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1464 // FIXME: Make sure that the "to" context supports C++11!
1465 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1466 if (!ToDeducedTypeOrErr)
1467 return ToDeducedTypeOrErr.takeError();
1468
1469 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1470 if (!ToTypeConstraintConcept)
1471 return ToTypeConstraintConcept.takeError();
1472
1473 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1474 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1475 ToTemplateArgs))
1476 return std::move(Err);
1477
1478 return Importer.getToContext().getAutoType(
1479 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1480 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1481 ToTemplateArgs);
1482}
1483
1484ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1486 // FIXME: Make sure that the "to" context supports C++17!
1487 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1488 if (!ToTemplateNameOrErr)
1489 return ToTemplateNameOrErr.takeError();
1490 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1491 if (!ToDeducedTypeOrErr)
1492 return ToDeducedTypeOrErr.takeError();
1493
1495 *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
1496}
1497
1498ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
1499 const InjectedClassNameType *T) {
1500 Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1501 if (!ToDeclOrErr)
1502 return ToDeclOrErr.takeError();
1503
1504 // The InjectedClassNameType is created in VisitRecordDecl when the
1505 // T->getDecl() is imported. Here we can return the existing type.
1506 const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1507 assert(Ty && isa<InjectedClassNameType>(Ty));
1508 return QualType(Ty, 0);
1509}
1510
1511ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1512 Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1513 if (!ToDeclOrErr)
1514 return ToDeclOrErr.takeError();
1515
1516 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1517}
1518
1519ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1520 Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1521 if (!ToDeclOrErr)
1522 return ToDeclOrErr.takeError();
1523
1524 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1525}
1526
1527ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1528 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1529 if (!ToModifiedTypeOrErr)
1530 return ToModifiedTypeOrErr.takeError();
1531 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1532 if (!ToEquivalentTypeOrErr)
1533 return ToEquivalentTypeOrErr.takeError();
1534
1535 return Importer.getToContext().getAttributedType(T->getAttrKind(),
1536 *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr);
1537}
1538
1540ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1541 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1542 if (!ToWrappedTypeOrErr)
1543 return ToWrappedTypeOrErr.takeError();
1544
1545 Error Err = Error::success();
1546 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1547
1549 for (auto TI : T->dependent_decls()) {
1550 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1551 if (!ToDeclOrErr)
1552 return ToDeclOrErr.takeError();
1553 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1554 }
1555
1556 return Importer.getToContext().getCountAttributedType(
1557 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1558 ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
1559}
1560
1561ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1562 const TemplateTypeParmType *T) {
1563 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1564 if (!ToDeclOrErr)
1565 return ToDeclOrErr.takeError();
1566
1567 return Importer.getToContext().getTemplateTypeParmType(
1568 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1569}
1570
1571ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1573 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1574 if (!ReplacedOrErr)
1575 return ReplacedOrErr.takeError();
1576
1577 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1578 if (!ToReplacementTypeOrErr)
1579 return ToReplacementTypeOrErr.takeError();
1580
1582 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(),
1583 T->getPackIndex());
1584}
1585
1586ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1588 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1589 if (!ReplacedOrErr)
1590 return ReplacedOrErr.takeError();
1591
1592 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1593 if (!ToArgumentPack)
1594 return ToArgumentPack.takeError();
1595
1597 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1598}
1599
1600ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1602 auto ToTemplateOrErr = import(T->getTemplateName());
1603 if (!ToTemplateOrErr)
1604 return ToTemplateOrErr.takeError();
1605
1606 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1607 if (Error Err =
1608 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1609 return std::move(Err);
1610
1611 QualType ToCanonType;
1612 if (!T->isCanonicalUnqualified()) {
1613 QualType FromCanonType
1614 = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1615 if (ExpectedType TyOrErr = import(FromCanonType))
1616 ToCanonType = *TyOrErr;
1617 else
1618 return TyOrErr.takeError();
1619 }
1620 return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1621 ToTemplateArgs,
1622 ToCanonType);
1623}
1624
1625ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
1626 // Note: the qualifier in an ElaboratedType is optional.
1627 auto ToQualifierOrErr = import(T->getQualifier());
1628 if (!ToQualifierOrErr)
1629 return ToQualifierOrErr.takeError();
1630
1631 ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1632 if (!ToNamedTypeOrErr)
1633 return ToNamedTypeOrErr.takeError();
1634
1635 Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1636 if (!ToOwnedTagDeclOrErr)
1637 return ToOwnedTagDeclOrErr.takeError();
1638
1639 return Importer.getToContext().getElaboratedType(T->getKeyword(),
1640 *ToQualifierOrErr,
1641 *ToNamedTypeOrErr,
1642 *ToOwnedTagDeclOrErr);
1643}
1644
1646ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1647 ExpectedType ToPatternOrErr = import(T->getPattern());
1648 if (!ToPatternOrErr)
1649 return ToPatternOrErr.takeError();
1650
1651 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1652 T->getNumExpansions(),
1653 /*ExpactPack=*/false);
1654}
1655
1656ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1658 auto ToQualifierOrErr = import(T->getQualifier());
1659 if (!ToQualifierOrErr)
1660 return ToQualifierOrErr.takeError();
1661
1662 IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1663
1665 ToPack.reserve(T->template_arguments().size());
1666 if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1667 return std::move(Err);
1668
1670 T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1671}
1672
1674ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1675 auto ToQualifierOrErr = import(T->getQualifier());
1676 if (!ToQualifierOrErr)
1677 return ToQualifierOrErr.takeError();
1678
1679 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1680
1681 QualType Canon;
1682 if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1683 if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1684 Canon = (*TyOrErr).getCanonicalType();
1685 else
1686 return TyOrErr.takeError();
1687 }
1688
1689 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1690 *ToQualifierOrErr,
1691 Name, Canon);
1692}
1693
1695ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1696 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1697 if (!ToDeclOrErr)
1698 return ToDeclOrErr.takeError();
1699
1700 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1701}
1702
1703ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1704 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1705 if (!ToBaseTypeOrErr)
1706 return ToBaseTypeOrErr.takeError();
1707
1708 SmallVector<QualType, 4> TypeArgs;
1709 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1710 if (ExpectedType TyOrErr = import(TypeArg))
1711 TypeArgs.push_back(*TyOrErr);
1712 else
1713 return TyOrErr.takeError();
1714 }
1715
1717 for (auto *P : T->quals()) {
1718 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1719 Protocols.push_back(*ProtocolOrErr);
1720 else
1721 return ProtocolOrErr.takeError();
1722
1723 }
1724
1725 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1726 Protocols,
1727 T->isKindOfTypeAsWritten());
1728}
1729
1731ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1732 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1733 if (!ToPointeeTypeOrErr)
1734 return ToPointeeTypeOrErr.takeError();
1735
1736 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1737}
1738
1740ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1741 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1742 if (!ToUnderlyingTypeOrErr)
1743 return ToUnderlyingTypeOrErr.takeError();
1744
1745 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1746 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1747 ToIdentifier);
1748}
1749
1750ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1751 Error Err = Error::success();
1752 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1753 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1754 if (Err)
1755 return std::move(Err);
1756
1757 return Importer.getToContext().getAdjustedType(ToOriginalType,
1758 ToAdjustedType);
1759}
1760
1761ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1762 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1763 T->getNumBits());
1764}
1765
1766ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1768 Error Err = Error::success();
1769 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1770 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1771 if (Err)
1772 return std::move(Err);
1773
1774 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1775 ToWrappedType);
1776}
1777
1778ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
1780 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1781 if (!ToElementTypeOrErr)
1782 return ToElementTypeOrErr.takeError();
1783
1784 return Importer.getToContext().getConstantMatrixType(
1785 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
1786}
1787
1788ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
1790 Error Err = Error::success();
1791 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
1792 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
1793 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1794 if (Err)
1795 return std::move(Err);
1796
1797 return Importer.getToContext().getDependentAddressSpaceType(
1798 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
1799}
1800
1801ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
1803 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
1804 if (!ToNumBitsExprOrErr)
1805 return ToNumBitsExprOrErr.takeError();
1806 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
1807 *ToNumBitsExprOrErr);
1808}
1809
1810ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
1812 Error Err = Error::success();
1813 QualType ToElementType = importChecked(Err, T->getElementType());
1814 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
1815 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
1816 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1817 if (Err)
1818 return std::move(Err);
1819
1820 return Importer.getToContext().getDependentSizedMatrixType(
1821 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
1822}
1823
1824ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
1826 Error Err = Error::success();
1827 QualType ToElementType = importChecked(Err, T->getElementType());
1828 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1829 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1830 if (Err)
1831 return std::move(Err);
1832
1833 return Importer.getToContext().getDependentVectorType(
1834 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
1835}
1836
1837ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
1838 const clang::ObjCTypeParamType *T) {
1839 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
1840 if (!ToDeclOrErr)
1841 return ToDeclOrErr.takeError();
1842
1844 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
1845 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
1846 if (!ToProtocolOrErr)
1847 return ToProtocolOrErr.takeError();
1848 ToProtocols.push_back(*ToProtocolOrErr);
1849 }
1850
1851 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
1852 ToProtocols);
1853}
1854
1855ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
1856 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1857 if (!ToElementTypeOrErr)
1858 return ToElementTypeOrErr.takeError();
1859
1860 ASTContext &ToCtx = Importer.getToContext();
1861 if (T->isReadOnly())
1862 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
1863 else
1864 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
1865}
1866
1867//----------------------------------------------------------------------------
1868// Import Declarations
1869//----------------------------------------------------------------------------
1871 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1872 DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) {
1873 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1874 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1875 // FIXME: We could support these constructs by importing a different type of
1876 // this parameter and by importing the original type of the parameter only
1877 // after the FunctionDecl is created. See
1878 // VisitFunctionDecl::UsedDifferentProtoType.
1879 DeclContext *OrigDC = D->getDeclContext();
1880 FunctionDecl *FunDecl;
1881 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1882 FunDecl->hasBody()) {
1883 auto getLeafPointeeType = [](const Type *T) {
1884 while (T->isPointerType() || T->isArrayType()) {
1886 }
1887 return T;
1888 };
1889 for (const ParmVarDecl *P : FunDecl->parameters()) {
1890 const Type *LeafT =
1891 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1892 auto *RT = dyn_cast<RecordType>(LeafT);
1893 if (RT && RT->getDecl() == D) {
1894 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1895 << D->getDeclKindName();
1896 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1897 }
1898 }
1899 }
1900
1901 // Import the context of this declaration.
1902 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1903 return Err;
1904
1905 // Import the name of this declaration.
1906 if (Error Err = importInto(Name, D->getDeclName()))
1907 return Err;
1908
1909 // Import the location of this declaration.
1910 if (Error Err = importInto(Loc, D->getLocation()))
1911 return Err;
1912
1913 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1914 if (ToD)
1915 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1916 return Err;
1917
1918 return Error::success();
1919}
1920
1922 NamedDecl *&ToD, SourceLocation &Loc) {
1923
1924 // Import the name of this declaration.
1925 if (Error Err = importInto(Name, D->getDeclName()))
1926 return Err;
1927
1928 // Import the location of this declaration.
1929 if (Error Err = importInto(Loc, D->getLocation()))
1930 return Err;
1931
1932 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1933 if (ToD)
1934 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1935 return Err;
1936
1937 return Error::success();
1938}
1939
1941 if (!FromD)
1942 return Error::success();
1943
1944 if (!ToD)
1945 if (Error Err = importInto(ToD, FromD))
1946 return Err;
1947
1948 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
1949 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
1950 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
1951 !ToRecord->getDefinition()) {
1952 if (Error Err = ImportDefinition(FromRecord, ToRecord))
1953 return Err;
1954 }
1955 }
1956 return Error::success();
1957 }
1958
1959 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
1960 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
1961 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
1962 if (Error Err = ImportDefinition(FromEnum, ToEnum))
1963 return Err;
1964 }
1965 }
1966 return Error::success();
1967 }
1968
1969 return Error::success();
1970}
1971
1972Error
1974 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
1975 // NOTE: To.Name and To.Loc are already imported.
1976 // We only have to import To.LocInfo.
1977 switch (To.getName().getNameKind()) {
1984 return Error::success();
1985
1987 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
1988 To.setCXXOperatorNameRange(*ToRangeOrErr);
1989 else
1990 return ToRangeOrErr.takeError();
1991 return Error::success();
1992 }
1994 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
1995 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
1996 else
1997 return LocOrErr.takeError();
1998 return Error::success();
1999 }
2003 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2004 To.setNamedTypeInfo(*ToTInfoOrErr);
2005 else
2006 return ToTInfoOrErr.takeError();
2007 return Error::success();
2008 }
2009 }
2010 llvm_unreachable("Unknown name kind.");
2011}
2012
2013Error
2015 if (Importer.isMinimalImport() && !ForceImport) {
2016 auto ToDCOrErr = Importer.ImportContext(FromDC);
2017 return ToDCOrErr.takeError();
2018 }
2019
2020 // We use strict error handling in case of records and enums, but not
2021 // with e.g. namespaces.
2022 //
2023 // FIXME Clients of the ASTImporter should be able to choose an
2024 // appropriate error handling strategy for their needs. For instance,
2025 // they may not want to mark an entire namespace as erroneous merely
2026 // because there is an ODR error with two typedefs. As another example,
2027 // the client may allow EnumConstantDecls with same names but with
2028 // different values in two distinct translation units.
2029 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2030
2031 auto MightNeedReordering = [](const Decl *D) {
2032 return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2033 };
2034
2035 // Import everything that might need reordering first.
2036 Error ChildErrors = Error::success();
2037 for (auto *From : FromDC->decls()) {
2038 if (!MightNeedReordering(From))
2039 continue;
2040
2041 ExpectedDecl ImportedOrErr = import(From);
2042
2043 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2044 // want to make sure that we are also completing each FieldDecl. There
2045 // are currently cases where this does not happen and this is correctness
2046 // fix since operations such as code generation will expect this to be so.
2047 if (!ImportedOrErr) {
2048 HandleChildErrors.handleChildImportResult(ChildErrors,
2049 ImportedOrErr.takeError());
2050 continue;
2051 }
2052 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2053 Decl *ImportedDecl = *ImportedOrErr;
2054 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2055 if (FieldFrom && FieldTo) {
2056 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2057 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2058 }
2059 }
2060
2061 // We reorder declarations in RecordDecls because they may have another order
2062 // in the "to" context than they have in the "from" context. This may happen
2063 // e.g when we import a class like this:
2064 // struct declToImport {
2065 // int a = c + b;
2066 // int b = 1;
2067 // int c = 2;
2068 // };
2069 // During the import of `a` we import first the dependencies in sequence,
2070 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2071 // first removing the already imported members and then adding them in the
2072 // order as they appear in the "from" context.
2073 //
2074 // Keeping field order is vital because it determines structure layout.
2075 //
2076 // Here and below, we cannot call field_begin() method and its callers on
2077 // ToDC if it has an external storage. Calling field_begin() will
2078 // automatically load all the fields by calling
2079 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2080 // call ASTImporter::Import(). This is because the ExternalASTSource
2081 // interface in LLDB is implemented by the means of the ASTImporter. However,
2082 // calling an import at this point would result in an uncontrolled import, we
2083 // must avoid that.
2084
2085 auto ToDCOrErr = Importer.ImportContext(FromDC);
2086 if (!ToDCOrErr) {
2087 consumeError(std::move(ChildErrors));
2088 return ToDCOrErr.takeError();
2089 }
2090
2091 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2092 DeclContext *ToDC = *ToDCOrErr;
2093 // Remove all declarations, which may be in wrong order in the
2094 // lexical DeclContext and then add them in the proper order.
2095 for (auto *D : FromRD->decls()) {
2096 if (!MightNeedReordering(D))
2097 continue;
2098
2099 assert(D && "DC contains a null decl");
2100 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2101 // Remove only the decls which we successfully imported.
2102 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2103 // Remove the decl from its wrong place in the linked list.
2104 ToDC->removeDecl(ToD);
2105 // Add the decl to the end of the linked list.
2106 // This time it will be at the proper place because the enclosing for
2107 // loop iterates in the original (good) order of the decls.
2108 ToDC->addDeclInternal(ToD);
2109 }
2110 }
2111 }
2112
2113 // Import everything else.
2114 for (auto *From : FromDC->decls()) {
2115 if (MightNeedReordering(From))
2116 continue;
2117
2118 ExpectedDecl ImportedOrErr = import(From);
2119 if (!ImportedOrErr)
2120 HandleChildErrors.handleChildImportResult(ChildErrors,
2121 ImportedOrErr.takeError());
2122 }
2123
2124 return ChildErrors;
2125}
2126
2128 const FieldDecl *To) {
2129 RecordDecl *FromRecordDecl = nullptr;
2130 RecordDecl *ToRecordDecl = nullptr;
2131 // If we have a field that is an ArrayType we need to check if the array
2132 // element is a RecordDecl and if so we need to import the definition.
2133 QualType FromType = From->getType();
2134 QualType ToType = To->getType();
2135 if (FromType->isArrayType()) {
2136 // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
2137 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2138 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2139 }
2140
2141 if (!FromRecordDecl || !ToRecordDecl) {
2142 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2143 const RecordType *RecordTo = ToType->getAs<RecordType>();
2144
2145 if (RecordFrom && RecordTo) {
2146 FromRecordDecl = RecordFrom->getDecl();
2147 ToRecordDecl = RecordTo->getDecl();
2148 }
2149 }
2150
2151 if (FromRecordDecl && ToRecordDecl) {
2152 if (FromRecordDecl->isCompleteDefinition() &&
2153 !ToRecordDecl->isCompleteDefinition())
2154 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2155 }
2156
2157 return Error::success();
2158}
2159
2161 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2162 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2163 if (!ToDCOrErr)
2164 return ToDCOrErr.takeError();
2165 ToDC = *ToDCOrErr;
2166
2167 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2168 auto ToLexicalDCOrErr = Importer.ImportContext(
2169 FromD->getLexicalDeclContext());
2170 if (!ToLexicalDCOrErr)
2171 return ToLexicalDCOrErr.takeError();
2172 ToLexicalDC = *ToLexicalDCOrErr;
2173 } else
2174 ToLexicalDC = ToDC;
2175
2176 return Error::success();
2177}
2178
2180 const CXXRecordDecl *From, CXXRecordDecl *To) {
2181 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2182 "Import implicit methods to or from non-definition");
2183
2184 for (CXXMethodDecl *FromM : From->methods())
2185 if (FromM->isImplicit()) {
2186 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2187 if (!ToMOrErr)
2188 return ToMOrErr.takeError();
2189 }
2190
2191 return Error::success();
2192}
2193
2195 ASTImporter &Importer) {
2196 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2197 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2198 To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2199 else
2200 return ToTypedefOrErr.takeError();
2201 }
2202 return Error::success();
2203}
2204
2206 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2207 auto DefinitionCompleter = [To]() {
2208 // There are cases in LLDB when we first import a class without its
2209 // members. The class will have DefinitionData, but no members. Then,
2210 // importDefinition is called from LLDB, which tries to get the members, so
2211 // when we get here, the class already has the DefinitionData set, so we
2212 // must unset the CompleteDefinition here to be able to complete again the
2213 // definition.
2214 To->setCompleteDefinition(false);
2215 To->completeDefinition();
2216 };
2217
2218 if (To->getDefinition() || To->isBeingDefined()) {
2219 if (Kind == IDK_Everything ||
2220 // In case of lambdas, the class already has a definition ptr set, but
2221 // the contained decls are not imported yet. Also, isBeingDefined was
2222 // set in CXXRecordDecl::CreateLambda. We must import the contained
2223 // decls here and finish the definition.
2224 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2225 if (To->isLambda()) {
2226 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2228 ToCaptures.reserve(FromCXXRD->capture_size());
2229 for (const auto &FromCapture : FromCXXRD->captures()) {
2230 if (auto ToCaptureOrErr = import(FromCapture))
2231 ToCaptures.push_back(*ToCaptureOrErr);
2232 else
2233 return ToCaptureOrErr.takeError();
2234 }
2235 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2236 ToCaptures);
2237 }
2238
2239 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2240 // Finish the definition of the lambda, set isBeingDefined to false.
2241 if (To->isLambda())
2242 DefinitionCompleter();
2243 return Result;
2244 }
2245
2246 return Error::success();
2247 }
2248
2249 To->startDefinition();
2250 // Set the definition to complete even if it is really not complete during
2251 // import. Some AST constructs (expressions) require the record layout
2252 // to be calculated (see 'clang::computeDependence') at the time they are
2253 // constructed. Import of such AST node is possible during import of the
2254 // same record, there is no way to have a completely defined record (all
2255 // fields imported) at that time without multiple AST import passes.
2256 if (!Importer.isMinimalImport())
2257 To->setCompleteDefinition(true);
2258 // Complete the definition even if error is returned.
2259 // The RecordDecl may be already part of the AST so it is better to
2260 // have it in complete state even if something is wrong with it.
2261 auto DefinitionCompleterScopeExit =
2262 llvm::make_scope_exit(DefinitionCompleter);
2263
2264 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2265 return Err;
2266
2267 // Add base classes.
2268 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2269 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2270 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2271
2272 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2273 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2274
2275 #define FIELD(Name, Width, Merge) \
2276 ToData.Name = FromData.Name;
2277 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2278
2279 // Copy over the data stored in RecordDeclBits
2280 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2281
2283 for (const auto &Base1 : FromCXX->bases()) {
2284 ExpectedType TyOrErr = import(Base1.getType());
2285 if (!TyOrErr)
2286 return TyOrErr.takeError();
2287
2288 SourceLocation EllipsisLoc;
2289 if (Base1.isPackExpansion()) {
2290 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2291 EllipsisLoc = *LocOrErr;
2292 else
2293 return LocOrErr.takeError();
2294 }
2295
2296 // Ensure that we have a definition for the base.
2297 if (Error Err =
2298 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2299 return Err;
2300
2301 auto RangeOrErr = import(Base1.getSourceRange());
2302 if (!RangeOrErr)
2303 return RangeOrErr.takeError();
2304
2305 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2306 if (!TSIOrErr)
2307 return TSIOrErr.takeError();
2308
2309 Bases.push_back(
2310 new (Importer.getToContext()) CXXBaseSpecifier(
2311 *RangeOrErr,
2312 Base1.isVirtual(),
2313 Base1.isBaseOfClass(),
2314 Base1.getAccessSpecifierAsWritten(),
2315 *TSIOrErr,
2316 EllipsisLoc));
2317 }
2318 if (!Bases.empty())
2319 ToCXX->setBases(Bases.data(), Bases.size());
2320 }
2321
2322 if (shouldForceImportDeclContext(Kind)) {
2323 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2324 return Err;
2325 }
2326
2327 return Error::success();
2328}
2329
2331 if (To->getAnyInitializer())
2332 return Error::success();
2333
2334 Expr *FromInit = From->getInit();
2335 if (!FromInit)
2336 return Error::success();
2337
2338 ExpectedExpr ToInitOrErr = import(FromInit);
2339 if (!ToInitOrErr)
2340 return ToInitOrErr.takeError();
2341
2342 To->setInit(*ToInitOrErr);
2343 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2344 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2345 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2346 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2347 // FIXME: Also import the initializer value.
2348 }
2349
2350 // FIXME: Other bits to merge?
2351 return Error::success();
2352}
2353
2355 EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) {
2356 if (To->getDefinition() || To->isBeingDefined()) {
2357 if (Kind == IDK_Everything)
2358 return ImportDeclContext(From, /*ForceImport=*/true);
2359 return Error::success();
2360 }
2361
2362 To->startDefinition();
2363
2364 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2365 return Err;
2366
2367 ExpectedType ToTypeOrErr =
2368 import(Importer.getFromContext().getTypeDeclType(From));
2369 if (!ToTypeOrErr)
2370 return ToTypeOrErr.takeError();
2371
2372 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2373 if (!ToPromotionTypeOrErr)
2374 return ToPromotionTypeOrErr.takeError();
2375
2377 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2378 return Err;
2379
2380 // FIXME: we might need to merge the number of positive or negative bits
2381 // if the enumerator lists don't match.
2382 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2383 From->getNumPositiveBits(),
2384 From->getNumNegativeBits());
2385 return Error::success();
2386}
2387
2391 for (const auto &Arg : FromArgs) {
2392 if (auto ToOrErr = import(Arg))
2393 ToArgs.push_back(*ToOrErr);
2394 else
2395 return ToOrErr.takeError();
2396 }
2397
2398 return Error::success();
2399}
2400
2401// FIXME: Do not forget to remove this and use only 'import'.
2404 return import(From);
2405}
2406
2407template <typename InContainerTy>
2409 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2410 for (const auto &FromLoc : Container) {
2411 if (auto ToLocOrErr = import(FromLoc))
2412 ToTAInfo.addArgument(*ToLocOrErr);
2413 else
2414 return ToLocOrErr.takeError();
2415 }
2416 return Error::success();
2417}
2418
2423}
2424
2425bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2426 bool IgnoreTemplateParmDepth) {
2427 // Eliminate a potential failure point where we attempt to re-import
2428 // something we're trying to import while completing ToRecord.
2429 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2430 if (ToOrigin) {
2431 To = ToOrigin;
2432 }
2433
2435 Importer.getFromContext(), Importer.getToContext(),
2437 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2438 IgnoreTemplateParmDepth);
2439 return Ctx.IsEquivalent(From, To);
2440}
2441
2443 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2444 << D->getDeclKindName();
2445 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2446}
2447
2449 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2450 << D->getDeclKindName();
2451 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2452}
2453
2455 // Import the context of this declaration.
2456 DeclContext *DC, *LexicalDC;
2457 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2458 return std::move(Err);
2459
2460 // Import the location of this declaration.
2461 ExpectedSLoc LocOrErr = import(D->getLocation());
2462 if (!LocOrErr)
2463 return LocOrErr.takeError();
2464
2465 EmptyDecl *ToD;
2466 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2467 return ToD;
2468
2469 ToD->setLexicalDeclContext(LexicalDC);
2470 LexicalDC->addDeclInternal(ToD);
2471 return ToD;
2472}
2473
2475 TranslationUnitDecl *ToD =
2477
2478 Importer.MapImported(D, ToD);
2479
2480 return ToD;
2481}
2482
2484 DeclContext *DC, *LexicalDC;
2485 DeclarationName Name;
2486 SourceLocation Loc;
2487 NamedDecl *ToND;
2488 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2489 return std::move(Err);
2490 if (ToND)
2491 return ToND;
2492
2493 BindingDecl *ToD;
2494 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2495 Name.getAsIdentifierInfo()))
2496 return ToD;
2497
2498 Error Err = Error::success();
2499 QualType ToType = importChecked(Err, D->getType());
2500 Expr *ToBinding = importChecked(Err, D->getBinding());
2501 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2502 if (Err)
2503 return std::move(Err);
2504
2505 ToD->setBinding(ToType, ToBinding);
2506 ToD->setDecomposedDecl(ToDecomposedDecl);
2507 addDeclToContexts(D, ToD);
2508
2509 return ToD;
2510}
2511
2513 ExpectedSLoc LocOrErr = import(D->getLocation());
2514 if (!LocOrErr)
2515 return LocOrErr.takeError();
2516 auto ColonLocOrErr = import(D->getColonLoc());
2517 if (!ColonLocOrErr)
2518 return ColonLocOrErr.takeError();
2519
2520 // Import the context of this declaration.
2521 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2522 if (!DCOrErr)
2523 return DCOrErr.takeError();
2524 DeclContext *DC = *DCOrErr;
2525
2526 AccessSpecDecl *ToD;
2527 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2528 DC, *LocOrErr, *ColonLocOrErr))
2529 return ToD;
2530
2531 // Lexical DeclContext and Semantic DeclContext
2532 // is always the same for the accessSpec.
2533 ToD->setLexicalDeclContext(DC);
2534 DC->addDeclInternal(ToD);
2535
2536 return ToD;
2537}
2538
2540 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2541 if (!DCOrErr)
2542 return DCOrErr.takeError();
2543 DeclContext *DC = *DCOrErr;
2544 DeclContext *LexicalDC = DC;
2545
2546 Error Err = Error::success();
2547 auto ToLocation = importChecked(Err, D->getLocation());
2548 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2549 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2550 auto ToMessage = importChecked(Err, D->getMessage());
2551 if (Err)
2552 return std::move(Err);
2553
2554 StaticAssertDecl *ToD;
2555 if (GetImportedOrCreateDecl(
2556 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2557 ToRParenLoc, D->isFailed()))
2558 return ToD;
2559
2560 ToD->setLexicalDeclContext(LexicalDC);
2561 LexicalDC->addDeclInternal(ToD);
2562 return ToD;
2563}
2564
2566 // Import the major distinguishing characteristics of this namespace.
2567 DeclContext *DC, *LexicalDC;
2568 DeclarationName Name;
2569 SourceLocation Loc;
2570 NamedDecl *ToD;
2571 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2572 return std::move(Err);
2573 if (ToD)
2574 return ToD;
2575
2576 NamespaceDecl *MergeWithNamespace = nullptr;
2577 if (!Name) {
2578 // This is an anonymous namespace. Adopt an existing anonymous
2579 // namespace if we can.
2580 // FIXME: Not testable.
2581 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2582 MergeWithNamespace = TU->getAnonymousNamespace();
2583 else
2584 MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2585 } else {
2586 SmallVector<NamedDecl *, 4> ConflictingDecls;
2587 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2588 for (auto *FoundDecl : FoundDecls) {
2590 continue;
2591
2592 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2593 MergeWithNamespace = FoundNS;
2594 ConflictingDecls.clear();
2595 break;
2596 }
2597
2598 ConflictingDecls.push_back(FoundDecl);
2599 }
2600
2601 if (!ConflictingDecls.empty()) {
2602 ExpectedName NameOrErr = Importer.HandleNameConflict(
2603 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2604 ConflictingDecls.size());
2605 if (NameOrErr)
2606 Name = NameOrErr.get();
2607 else
2608 return NameOrErr.takeError();
2609 }
2610 }
2611
2612 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2613 if (!BeginLocOrErr)
2614 return BeginLocOrErr.takeError();
2615 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2616 if (!RBraceLocOrErr)
2617 return RBraceLocOrErr.takeError();
2618
2619 // Create the "to" namespace, if needed.
2620 NamespaceDecl *ToNamespace = MergeWithNamespace;
2621 if (!ToNamespace) {
2622 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2623 D->isInline(), *BeginLocOrErr, Loc,
2624 Name.getAsIdentifierInfo(),
2625 /*PrevDecl=*/nullptr, D->isNested()))
2626 return ToNamespace;
2627 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2628 ToNamespace->setLexicalDeclContext(LexicalDC);
2629 LexicalDC->addDeclInternal(ToNamespace);
2630
2631 // If this is an anonymous namespace, register it as the anonymous
2632 // namespace within its context.
2633 if (!Name) {
2634 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2635 TU->setAnonymousNamespace(ToNamespace);
2636 else
2637 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2638 }
2639 }
2640 Importer.MapImported(D, ToNamespace);
2641
2642 if (Error Err = ImportDeclContext(D))
2643 return std::move(Err);
2644
2645 return ToNamespace;
2646}
2647
2649 // Import the major distinguishing characteristics of this namespace.
2650 DeclContext *DC, *LexicalDC;
2651 DeclarationName Name;
2652 SourceLocation Loc;
2653 NamedDecl *LookupD;
2654 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2655 return std::move(Err);
2656 if (LookupD)
2657 return LookupD;
2658
2659 // NOTE: No conflict resolution is done for namespace aliases now.
2660
2661 Error Err = Error::success();
2662 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2663 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2664 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2665 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2666 auto ToNamespace = importChecked(Err, D->getNamespace());
2667 if (Err)
2668 return std::move(Err);
2669
2670 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2671
2672 NamespaceAliasDecl *ToD;
2673 if (GetImportedOrCreateDecl(
2674 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2675 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2676 return ToD;
2677
2678 ToD->setLexicalDeclContext(LexicalDC);
2679 LexicalDC->addDeclInternal(ToD);
2680
2681 return ToD;
2682}
2683
2686 // Import the major distinguishing characteristics of this typedef.
2687 DeclarationName Name;
2688 SourceLocation Loc;
2689 NamedDecl *ToD;
2690 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2691 // is created.
2692 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2693 return std::move(Err);
2694 if (ToD)
2695 return ToD;
2696
2697 DeclContext *DC = cast_or_null<DeclContext>(
2698 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2699 DeclContext *LexicalDC =
2700 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2701 cast<Decl>(D->getLexicalDeclContext())));
2702
2703 // If this typedef is not in block scope, determine whether we've
2704 // seen a typedef with the same name (that we can merge with) or any
2705 // other entity by that name (which name lookup could conflict with).
2706 // Note: Repeated typedefs are not valid in C99:
2707 // 'typedef int T; typedef int T;' is invalid
2708 // We do not care about this now.
2709 if (DC && !DC->isFunctionOrMethod()) {
2710 SmallVector<NamedDecl *, 4> ConflictingDecls;
2711 unsigned IDNS = Decl::IDNS_Ordinary;
2712 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2713 for (auto *FoundDecl : FoundDecls) {
2714 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2715 continue;
2716 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2717 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2718 continue;
2719
2720 QualType FromUT = D->getUnderlyingType();
2721 QualType FoundUT = FoundTypedef->getUnderlyingType();
2722 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2723 // If the underlying declarations are unnamed records these can be
2724 // imported as different types. We should create a distinct typedef
2725 // node in this case.
2726 // If we found an existing underlying type with a record in a
2727 // different context (than the imported), this is already reason for
2728 // having distinct typedef nodes for these.
2729 // Again this can create situation like
2730 // 'typedef int T; typedef int T;' but this is hard to avoid without
2731 // a rename strategy at import.
2732 if (!FromUT.isNull() && !FoundUT.isNull()) {
2733 RecordDecl *FromR = FromUT->getAsRecordDecl();
2734 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
2735 if (FromR && FoundR &&
2736 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
2737 continue;
2738 }
2739 // If the "From" context has a complete underlying type but we
2740 // already have a complete underlying type then return with that.
2741 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2742 return Importer.MapImported(D, FoundTypedef);
2743 // FIXME Handle redecl chain. When you do that make consistent changes
2744 // in ASTImporterLookupTable too.
2745 } else {
2746 ConflictingDecls.push_back(FoundDecl);
2747 }
2748 }
2749 }
2750
2751 if (!ConflictingDecls.empty()) {
2752 ExpectedName NameOrErr = Importer.HandleNameConflict(
2753 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2754 if (NameOrErr)
2755 Name = NameOrErr.get();
2756 else
2757 return NameOrErr.takeError();
2758 }
2759 }
2760
2761 Error Err = Error::success();
2763 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
2764 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2765 if (Err)
2766 return std::move(Err);
2767
2768 // Create the new typedef node.
2769 // FIXME: ToUnderlyingType is not used.
2770 (void)ToUnderlyingType;
2771 TypedefNameDecl *ToTypedef;
2772 if (IsAlias) {
2773 if (GetImportedOrCreateDecl<TypeAliasDecl>(
2774 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2775 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2776 return ToTypedef;
2777 } else if (GetImportedOrCreateDecl<TypedefDecl>(
2778 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2779 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2780 return ToTypedef;
2781
2782 // Import the DeclContext and set it to the Typedef.
2783 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
2784 return std::move(Err);
2785 ToTypedef->setDeclContext(DC);
2786 ToTypedef->setLexicalDeclContext(LexicalDC);
2787 // Add to the lookupTable because we could not do that in MapImported.
2788 Importer.AddToLookupTable(ToTypedef);
2789
2790 ToTypedef->setAccess(D->getAccess());
2791
2792 // Templated declarations should not appear in DeclContext.
2793 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2794 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2795 LexicalDC->addDeclInternal(ToTypedef);
2796
2797 return ToTypedef;
2798}
2799
2801 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2802}
2803
2805 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2806}
2807
2810 // Import the major distinguishing characteristics of this typedef.
2811 DeclContext *DC, *LexicalDC;
2812 DeclarationName Name;
2813 SourceLocation Loc;
2814 NamedDecl *FoundD;
2815 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2816 return std::move(Err);
2817 if (FoundD)
2818 return FoundD;
2819
2820 // If this typedef is not in block scope, determine whether we've
2821 // seen a typedef with the same name (that we can merge with) or any
2822 // other entity by that name (which name lookup could conflict with).
2823 if (!DC->isFunctionOrMethod()) {
2824 SmallVector<NamedDecl *, 4> ConflictingDecls;
2825 unsigned IDNS = Decl::IDNS_Ordinary;
2826 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2827 for (auto *FoundDecl : FoundDecls) {
2828 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2829 continue;
2830 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
2831 if (IsStructuralMatch(D, FoundAlias))
2832 return Importer.MapImported(D, FoundAlias);
2833 ConflictingDecls.push_back(FoundDecl);
2834 }
2835 }
2836
2837 if (!ConflictingDecls.empty()) {
2838 ExpectedName NameOrErr = Importer.HandleNameConflict(
2839 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2840 if (NameOrErr)
2841 Name = NameOrErr.get();
2842 else
2843 return NameOrErr.takeError();
2844 }
2845 }
2846
2847 Error Err = Error::success();
2848 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
2849 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
2850 if (Err)
2851 return std::move(Err);
2852
2853 TypeAliasTemplateDecl *ToAlias;
2854 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2855 Name, ToTemplateParameters, ToTemplatedDecl))
2856 return ToAlias;
2857
2858 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2859
2860 ToAlias->setAccess(D->getAccess());
2861 ToAlias->setLexicalDeclContext(LexicalDC);
2862 LexicalDC->addDeclInternal(ToAlias);
2863 if (DC != Importer.getToContext().getTranslationUnitDecl())
2864 updateLookupTableForTemplateParameters(*ToTemplateParameters);
2865 return ToAlias;
2866}
2867
2869 // Import the major distinguishing characteristics of this label.
2870 DeclContext *DC, *LexicalDC;
2871 DeclarationName Name;
2872 SourceLocation Loc;
2873 NamedDecl *ToD;
2874 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2875 return std::move(Err);
2876 if (ToD)
2877 return ToD;
2878
2879 assert(LexicalDC->isFunctionOrMethod());
2880
2881 LabelDecl *ToLabel;
2882 if (D->isGnuLocal()) {
2883 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2884 if (!BeginLocOrErr)
2885 return BeginLocOrErr.takeError();
2886 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2887 Name.getAsIdentifierInfo(), *BeginLocOrErr))
2888 return ToLabel;
2889
2890 } else {
2891 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2892 Name.getAsIdentifierInfo()))
2893 return ToLabel;
2894
2895 }
2896
2897 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2898 if (!ToStmtOrErr)
2899 return ToStmtOrErr.takeError();
2900
2901 ToLabel->setStmt(*ToStmtOrErr);
2902 ToLabel->setLexicalDeclContext(LexicalDC);
2903 LexicalDC->addDeclInternal(ToLabel);
2904 return ToLabel;
2905}
2906
2908 // Import the major distinguishing characteristics of this enum.
2909 DeclContext *DC, *LexicalDC;
2910 DeclarationName Name;
2911 SourceLocation Loc;
2912 NamedDecl *ToD;
2913 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2914 return std::move(Err);
2915 if (ToD)
2916 return ToD;
2917
2918 // Figure out what enum name we're looking for.
2919 unsigned IDNS = Decl::IDNS_Tag;
2920 DeclarationName SearchName = Name;
2921 if (!SearchName && D->getTypedefNameForAnonDecl()) {
2922 if (Error Err = importInto(
2923 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2924 return std::move(Err);
2925 IDNS = Decl::IDNS_Ordinary;
2926 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2927 IDNS |= Decl::IDNS_Ordinary;
2928
2929 // We may already have an enum of the same name; try to find and match it.
2930 EnumDecl *PrevDecl = nullptr;
2931 if (!DC->isFunctionOrMethod() && SearchName) {
2932 SmallVector<NamedDecl *, 4> ConflictingDecls;
2933 auto FoundDecls =
2934 Importer.findDeclsInToCtx(DC, SearchName);
2935 for (auto *FoundDecl : FoundDecls) {
2936 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2937 continue;
2938
2939 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2940 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2941 FoundDecl = Tag->getDecl();
2942 }
2943
2944 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
2945 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
2946 continue;
2947 if (IsStructuralMatch(D, FoundEnum)) {
2948 EnumDecl *FoundDef = FoundEnum->getDefinition();
2949 if (D->isThisDeclarationADefinition() && FoundDef)
2950 return Importer.MapImported(D, FoundDef);
2951 PrevDecl = FoundEnum->getMostRecentDecl();
2952 break;
2953 }
2954 ConflictingDecls.push_back(FoundDecl);
2955 }
2956 }
2957
2958 if (!ConflictingDecls.empty()) {
2959 ExpectedName NameOrErr = Importer.HandleNameConflict(
2960 SearchName, DC, IDNS, ConflictingDecls.data(),
2961 ConflictingDecls.size());
2962 if (NameOrErr)
2963 Name = NameOrErr.get();
2964 else
2965 return NameOrErr.takeError();
2966 }
2967 }
2968
2969 Error Err = Error::success();
2970 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2971 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2972 auto ToIntegerType = importChecked(Err, D->getIntegerType());
2973 auto ToBraceRange = importChecked(Err, D->getBraceRange());
2974 if (Err)
2975 return std::move(Err);
2976
2977 // Create the enum declaration.
2978 EnumDecl *D2;
2979 if (GetImportedOrCreateDecl(
2980 D2, D, Importer.getToContext(), DC, ToBeginLoc,
2981 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
2982 D->isScopedUsingClassTag(), D->isFixed()))
2983 return D2;
2984
2985 D2->setQualifierInfo(ToQualifierLoc);
2986 D2->setIntegerType(ToIntegerType);
2987 D2->setBraceRange(ToBraceRange);
2988 D2->setAccess(D->getAccess());
2989 D2->setLexicalDeclContext(LexicalDC);
2990 addDeclToContexts(D, D2);
2991
2993 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
2994 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
2995 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
2996 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
2997 else
2998 return ToInstOrErr.takeError();
2999 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3001 else
3002 return POIOrErr.takeError();
3003 }
3004
3005 // Import the definition
3006 if (D->isCompleteDefinition())
3007 if (Error Err = ImportDefinition(D, D2))
3008 return std::move(Err);
3009
3010 return D2;
3011}
3012
3014 bool IsFriendTemplate = false;
3015 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3016 IsFriendTemplate =
3017 DCXX->getDescribedClassTemplate() &&
3018 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3020 }
3021
3022 // Import the major distinguishing characteristics of this record.
3023 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3024 DeclarationName Name;
3025 SourceLocation Loc;
3026 NamedDecl *ToD = nullptr;
3027 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3028 return std::move(Err);
3029 if (ToD)
3030 return ToD;
3031
3032 // Figure out what structure name we're looking for.
3033 unsigned IDNS = Decl::IDNS_Tag;
3034 DeclarationName SearchName = Name;
3035 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3036 if (Error Err = importInto(
3037 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3038 return std::move(Err);
3039 IDNS = Decl::IDNS_Ordinary;
3040 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3042
3043 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3044 : DC->isDependentContext();
3045 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3046
3047 // We may already have a record of the same name; try to find and match it.
3048 RecordDecl *PrevDecl = nullptr;
3049 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3050 SmallVector<NamedDecl *, 4> ConflictingDecls;
3051 auto FoundDecls =
3052 Importer.findDeclsInToCtx(DC, SearchName);
3053 if (!FoundDecls.empty()) {
3054 // We're going to have to compare D against potentially conflicting Decls,
3055 // so complete it.
3058 }
3059
3060 for (auto *FoundDecl : FoundDecls) {
3061 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3062 continue;
3063
3064 Decl *Found = FoundDecl;
3065 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3066 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3067 Found = Tag->getDecl();
3068 }
3069
3070 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3071 // Do not emit false positive diagnostic in case of unnamed
3072 // struct/union and in case of anonymous structs. Would be false
3073 // because there may be several anonymous/unnamed structs in a class.
3074 // E.g. these are both valid:
3075 // struct A { // unnamed structs
3076 // struct { struct A *next; } entry0;
3077 // struct { struct A *next; } entry1;
3078 // };
3079 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3080 if (!SearchName)
3081 if (!IsStructuralMatch(D, FoundRecord, false))
3082 continue;
3083
3084 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3085 continue;
3086
3087 if (IsStructuralMatch(D, FoundRecord)) {
3088 RecordDecl *FoundDef = FoundRecord->getDefinition();
3089 if (D->isThisDeclarationADefinition() && FoundDef) {
3090 // FIXME: Structural equivalence check should check for same
3091 // user-defined methods.
3092 Importer.MapImported(D, FoundDef);
3093 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3094 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3095 assert(FoundCXX && "Record type mismatch");
3096
3097 if (!Importer.isMinimalImport())
3098 // FoundDef may not have every implicit method that D has
3099 // because implicit methods are created only if they are used.
3100 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3101 return std::move(Err);
3102 }
3103 }
3104 PrevDecl = FoundRecord->getMostRecentDecl();
3105 break;
3106 }
3107 ConflictingDecls.push_back(FoundDecl);
3108 } // kind is RecordDecl
3109 } // for
3110
3111 if (!ConflictingDecls.empty() && SearchName) {
3112 ExpectedName NameOrErr = Importer.HandleNameConflict(
3113 SearchName, DC, IDNS, ConflictingDecls.data(),
3114 ConflictingDecls.size());
3115 if (NameOrErr)
3116 Name = NameOrErr.get();
3117 else
3118 return NameOrErr.takeError();
3119 }
3120 }
3121
3122 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3123 if (!BeginLocOrErr)
3124 return BeginLocOrErr.takeError();
3125
3126 // Create the record declaration.
3127 RecordDecl *D2 = nullptr;
3128 CXXRecordDecl *D2CXX = nullptr;
3129 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3130 if (DCXX->isLambda()) {
3131 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3132 if (!TInfoOrErr)
3133 return TInfoOrErr.takeError();
3134 if (GetImportedOrCreateSpecialDecl(
3135 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3136 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3137 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3138 return D2CXX;
3139 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3140 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3141 if (!CDeclOrErr)
3142 return CDeclOrErr.takeError();
3143 Numbering.ContextDecl = *CDeclOrErr;
3144 D2CXX->setLambdaNumbering(Numbering);
3145 } else if (DCXX->isInjectedClassName()) {
3146 // We have to be careful to do a similar dance to the one in
3147 // Sema::ActOnStartCXXMemberDeclarations
3148 const bool DelayTypeCreation = true;
3149 if (GetImportedOrCreateDecl(
3150 D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
3151 *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
3152 cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
3153 return D2CXX;
3154 Importer.getToContext().getTypeDeclType(
3155 D2CXX, dyn_cast<CXXRecordDecl>(DC));
3156 } else {
3157 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3158 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3159 Name.getAsIdentifierInfo(),
3160 cast_or_null<CXXRecordDecl>(PrevDecl)))
3161 return D2CXX;
3162 }
3163
3164 D2 = D2CXX;
3165 D2->setAccess(D->getAccess());
3166 D2->setLexicalDeclContext(LexicalDC);
3167 addDeclToContexts(D, D2);
3168
3169 if (ClassTemplateDecl *FromDescribed =
3170 DCXX->getDescribedClassTemplate()) {
3171 ClassTemplateDecl *ToDescribed;
3172 if (Error Err = importInto(ToDescribed, FromDescribed))
3173 return std::move(Err);
3174 D2CXX->setDescribedClassTemplate(ToDescribed);
3175 if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
3176 // In a record describing a template the type should be an
3177 // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
3178 // previously set type to the correct value here (ToDescribed is not
3179 // available at record create).
3180 CXXRecordDecl *Injected = nullptr;
3181 for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
3182 auto *Record = dyn_cast<CXXRecordDecl>(Found);
3183 if (Record && Record->isInjectedClassName()) {
3184 Injected = Record;
3185 break;
3186 }
3187 }
3188 // Create an injected type for the whole redecl chain.
3189 // The chain may contain an already existing injected type at the start,
3190 // if yes this should be reused. We must ensure that only one type
3191 // object exists for the injected type (including the injected record
3192 // declaration), ASTContext does not check it.
3193 SmallVector<Decl *, 2> Redecls =
3195 const Type *FrontTy =
3196 cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
3197 QualType InjSpec;
3198 if (auto *InjTy = FrontTy->getAs<InjectedClassNameType>())
3199 InjSpec = InjTy->getInjectedSpecializationType();
3200 else
3201 InjSpec = ToDescribed->getInjectedClassNameSpecialization();
3202 for (auto *R : Redecls) {
3203 auto *RI = cast<CXXRecordDecl>(R);
3204 if (R != Redecls.front() ||
3205 !isa<InjectedClassNameType>(RI->getTypeForDecl()))
3206 RI->setTypeForDecl(nullptr);
3207 // This function tries to get the injected type from getTypeForDecl,
3208 // then from the previous declaration if possible. If not, it creates
3209 // a new type.
3210 Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
3211 }
3212 // Set the new type for the injected decl too.
3213 if (Injected) {
3214 Injected->setTypeForDecl(nullptr);
3215 // This function will copy the injected type from D2CXX into Injected.
3216 // The injected decl does not have a previous decl to copy from.
3217 Importer.getToContext().getTypeDeclType(Injected, D2CXX);
3218 }
3219 }
3220 } else if (MemberSpecializationInfo *MemberInfo =
3221 DCXX->getMemberSpecializationInfo()) {
3223 MemberInfo->getTemplateSpecializationKind();
3225
3226 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3227 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3228 else
3229 return ToInstOrErr.takeError();
3230
3231 if (ExpectedSLoc POIOrErr =
3232 import(MemberInfo->getPointOfInstantiation()))
3234 *POIOrErr);
3235 else
3236 return POIOrErr.takeError();
3237 }
3238
3239 } else {
3240 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3241 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3242 Name.getAsIdentifierInfo(), PrevDecl))
3243 return D2;
3244 D2->setLexicalDeclContext(LexicalDC);
3245 addDeclToContexts(D, D2);
3246 }
3247
3248 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3249 D2->setBraceRange(*BraceRangeOrErr);
3250 else
3251 return BraceRangeOrErr.takeError();
3252 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3253 D2->setQualifierInfo(*QualifierLocOrErr);
3254 else
3255 return QualifierLocOrErr.takeError();
3256
3257 if (D->isAnonymousStructOrUnion())
3258 D2->setAnonymousStructOrUnion(true);
3259
3260 if (D->isCompleteDefinition())
3261 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3262 return std::move(Err);
3263
3264 return D2;
3265}
3266
3268 // Import the major distinguishing characteristics of this enumerator.
3269 DeclContext *DC, *LexicalDC;
3270 DeclarationName Name;
3271 SourceLocation Loc;
3272 NamedDecl *ToD;
3273 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3274 return std::move(Err);
3275 if (ToD)
3276 return ToD;
3277
3278 // Determine whether there are any other declarations with the same name and
3279 // in the same context.
3280 if (!LexicalDC->isFunctionOrMethod()) {
3281 SmallVector<NamedDecl *, 4> ConflictingDecls;
3282 unsigned IDNS = Decl::IDNS_Ordinary;
3283 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3284 for (auto *FoundDecl : FoundDecls) {
3285 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3286 continue;
3287
3288 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3289 if (IsStructuralMatch(D, FoundEnumConstant))
3290 return Importer.MapImported(D, FoundEnumConstant);
3291 ConflictingDecls.push_back(FoundDecl);
3292 }
3293 }
3294
3295 if (!ConflictingDecls.empty()) {
3296 ExpectedName NameOrErr = Importer.HandleNameConflict(
3297 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3298 if (NameOrErr)
3299 Name = NameOrErr.get();
3300 else
3301 return NameOrErr.takeError();
3302 }
3303 }
3304
3305 ExpectedType TypeOrErr = import(D->getType());
3306 if (!TypeOrErr)
3307 return TypeOrErr.takeError();
3308
3309 ExpectedExpr InitOrErr = import(D->getInitExpr());
3310 if (!InitOrErr)
3311 return InitOrErr.takeError();
3312
3313 EnumConstantDecl *ToEnumerator;
3314 if (GetImportedOrCreateDecl(
3315 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3316 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3317 return ToEnumerator;
3318
3319 ToEnumerator->setAccess(D->getAccess());
3320 ToEnumerator->setLexicalDeclContext(LexicalDC);
3321 LexicalDC->addDeclInternal(ToEnumerator);
3322 return ToEnumerator;
3323}
3324
3326 DeclaratorDecl *ToD) {
3327 unsigned int Num = FromD->getNumTemplateParameterLists();
3328 if (Num == 0)
3329 return Error::success();
3331 for (unsigned int I = 0; I < Num; ++I)
3332 if (Expected<TemplateParameterList *> ToTPListOrErr =
3333 import(FromD->getTemplateParameterList(I)))
3334 ToTPLists[I] = *ToTPListOrErr;
3335 else
3336 return ToTPListOrErr.takeError();
3337 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3338 return Error::success();
3339}
3340
3342 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3343 switch (FromFD->getTemplatedKind()) {
3346 return Error::success();
3347
3349 if (Expected<FunctionDecl *> InstFDOrErr =
3350 import(FromFD->getInstantiatedFromDecl()))
3351 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3352 return Error::success();
3355
3356 if (Expected<FunctionDecl *> InstFDOrErr =
3357 import(FromFD->getInstantiatedFromMemberFunction()))
3358 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3359 else
3360 return InstFDOrErr.takeError();
3361
3362 if (ExpectedSLoc POIOrErr = import(
3365 else
3366 return POIOrErr.takeError();
3367
3368 return Error::success();
3369 }
3370
3372 auto FunctionAndArgsOrErr =
3374 if (!FunctionAndArgsOrErr)
3375 return FunctionAndArgsOrErr.takeError();
3376
3378 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3379
3380 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3381 TemplateArgumentListInfo ToTAInfo;
3382 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3383 if (FromTAArgsAsWritten)
3384 if (Error Err = ImportTemplateArgumentListInfo(
3385 *FromTAArgsAsWritten, ToTAInfo))
3386 return Err;
3387
3388 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3389 if (!POIOrErr)
3390 return POIOrErr.takeError();
3391
3392 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3393 return Err;
3394
3395 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3396 ToFD->setFunctionTemplateSpecialization(
3397 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3398 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3399 return Error::success();
3400 }
3401
3403 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3404 UnresolvedSet<8> Candidates;
3405 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3406 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3407 Candidates.addDecl(*ToFTDOrErr);
3408 else
3409 return ToFTDOrErr.takeError();
3410 }
3411
3412 // Import TemplateArgumentListInfo.
3413 TemplateArgumentListInfo ToTAInfo;
3414 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3415 if (FromTAArgsAsWritten)
3416 if (Error Err =
3417 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3418 return Err;
3419
3421 Importer.getToContext(), Candidates,
3422 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3423 return Error::success();
3424 }
3425 }
3426 llvm_unreachable("All cases should be covered!");
3427}
3428
3431 auto FunctionAndArgsOrErr =
3433 if (!FunctionAndArgsOrErr)
3434 return FunctionAndArgsOrErr.takeError();
3435
3436 FunctionTemplateDecl *Template;
3437 TemplateArgsTy ToTemplArgs;
3438 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3439 void *InsertPos = nullptr;
3440 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3441 return FoundSpec;
3442}
3443
3445 FunctionDecl *ToFD) {
3446 if (Stmt *FromBody = FromFD->getBody()) {
3447 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3448 ToFD->setBody(*ToBodyOrErr);
3449 else
3450 return ToBodyOrErr.takeError();
3451 }
3452 return Error::success();
3453}
3454
3455// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3456// which is equal to the given DC, or D is equal to DC.
3457static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3458 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3459 if (!DCi)
3460 DCi = D->getDeclContext();
3461 assert(DCi && "Declaration should have a context");
3462 while (DCi != D->getTranslationUnitDecl()) {
3463 if (DCi == DC)
3464 return true;
3465 DCi = DCi->getParent();
3466 }
3467 return false;
3468}
3469
3470// Check if there is a declaration that has 'DC' as parent context and is
3471// referenced from statement 'S' or one of its children. The search is done in
3472// BFS order through children of 'S'.
3473static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3474 SmallVector<const Stmt *> ToProcess;
3475 ToProcess.push_back(S);
3476 while (!ToProcess.empty()) {
3477 const Stmt *CurrentS = ToProcess.pop_back_val();
3478 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3479 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3480 if (const Decl *D = DeclRef->getDecl())
3481 if (isAncestorDeclContextOf(DC, D))
3482 return true;
3483 } else if (const auto *E =
3484 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3485 if (const Decl *D = E->getAssociatedDecl())
3486 if (isAncestorDeclContextOf(DC, D))
3487 return true;
3488 }
3489 }
3490 return false;
3491}
3492
3493namespace {
3494/// Check if a type has any reference to a declaration that is inside the body
3495/// of a function.
3496/// The \c CheckType(QualType) function should be used to determine
3497/// this property.
3498///
3499/// The type visitor visits one type object only (not recursive).
3500/// To find all referenced declarations we must discover all type objects until
3501/// the canonical type is reached (walk over typedef and similar objects). This
3502/// is done by loop over all "sugar" type objects. For every such type we must
3503/// check all declarations that are referenced from it. For this check the
3504/// visitor is used. In the visit functions all referenced declarations except
3505/// the one that follows in the sugar chain (if any) must be checked. For this
3506/// check the same visitor is re-used (it has no state-dependent data).
3507///
3508/// The visit functions have 3 possible return values:
3509/// - True, found a declaration inside \c ParentDC.
3510/// - False, found declarations only outside \c ParentDC and it is not possible
3511/// to find more declarations (the "sugar" chain does not continue).
3512/// - Empty optional value, found no declarations or only outside \c ParentDC,
3513/// but it is possible to find more declarations in the type "sugar" chain.
3514/// The loop over the "sugar" types can be implemented by using type visit
3515/// functions only (call \c CheckType with the desugared type). With the current
3516/// solution no visit function is needed if the type has only a desugared type
3517/// as data.
3518class IsTypeDeclaredInsideVisitor
3519 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3520public:
3521 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3522 : ParentDC(ParentDC) {}
3523
3524 bool CheckType(QualType T) {
3525 // Check the chain of "sugar" types.
3526 // The "sugar" types are typedef or similar types that have the same
3527 // canonical type.
3528 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3529 return *Res;
3530 QualType DsT =
3531 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3532 while (DsT != T) {
3533 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3534 return *Res;
3535 T = DsT;
3536 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3537 }
3538 return false;
3539 }
3540
3541 std::optional<bool> VisitTagType(const TagType *T) {
3542 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3543 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3544 if (checkTemplateArgument(Arg))
3545 return true;
3546 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3547 }
3548
3549 std::optional<bool> VisitPointerType(const PointerType *T) {
3550 return CheckType(T->getPointeeType());
3551 }
3552
3553 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3554 return CheckType(T->getPointeeTypeAsWritten());
3555 }
3556
3557 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3558 const TypedefNameDecl *TD = T->getDecl();
3559 assert(TD);
3560 return isAncestorDeclContextOf(ParentDC, TD);
3561 }
3562
3563 std::optional<bool> VisitUsingType(const UsingType *T) {
3564 if (T->getFoundDecl() &&
3565 isAncestorDeclContextOf(ParentDC, T->getFoundDecl()))
3566 return true;
3567
3568 return {};
3569 }
3570
3571 std::optional<bool>
3572 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3573 for (const auto &Arg : T->template_arguments())
3574 if (checkTemplateArgument(Arg))
3575 return true;
3576 // This type is a "sugar" to a record type, it can have a desugared type.
3577 return {};
3578 }
3579
3580 std::optional<bool>
3581 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3582 // The "associated declaration" can be the same as ParentDC.
3583 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3584 return true;
3585 return {};
3586 }
3587
3588 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3589 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3590 return true;
3591
3592 return CheckType(T->getElementType());
3593 }
3594
3595 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3596 llvm_unreachable(
3597 "Variable array should not occur in deduced return type of a function");
3598 }
3599
3600 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3601 llvm_unreachable("Incomplete array should not occur in deduced return type "
3602 "of a function");
3603 }
3604
3605 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3606 llvm_unreachable("Dependent array should not occur in deduced return type "
3607 "of a function");
3608 }
3609
3610private:
3611 const DeclContext *const ParentDC;
3612
3613 bool checkTemplateArgument(const TemplateArgument &Arg) {
3614 switch (Arg.getKind()) {
3616 return false;
3618 return CheckType(Arg.getIntegralType());
3620 return CheckType(Arg.getAsType());
3622 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3624 // FIXME: The declaration in this case is not allowed to be in a function?
3625 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3627 // FIXME: The type is not allowed to be in the function?
3628 return CheckType(Arg.getNullPtrType());
3630 return CheckType(Arg.getStructuralValueType());
3632 for (const auto &PackArg : Arg.getPackAsArray())
3633 if (checkTemplateArgument(PackArg))
3634 return true;
3635 return false;
3637 // Templates can not be defined locally in functions.
3638 // A template passed as argument can be not in ParentDC.
3639 return false;
3641 // Templates can not be defined locally in functions.
3642 // A template passed as argument can be not in ParentDC.
3643 return false;
3644 }
3645 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3646 };
3647};
3648} // namespace
3649
3650/// This function checks if the given function has a return type that contains
3651/// a reference (in any way) to a declaration inside the same function.
3653 QualType FromTy = D->getType();
3654 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3655 assert(FromFPT && "Must be called on FunctionProtoType");
3656
3657 auto IsCXX11LambdaWithouTrailingReturn = [&]() {
3658 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3659 return false;
3660
3661 if (FromFPT->hasTrailingReturn())
3662 return false;
3663
3664 if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
3665 return cast<CXXRecordDecl>(MD->getDeclContext())->isLambda();
3666
3667 return false;
3668 };
3669
3670 QualType RetT = FromFPT->getReturnType();
3671 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11LambdaWithouTrailingReturn()) {
3672 FunctionDecl *Def = D->getDefinition();
3673 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3674 return Visitor.CheckType(RetT);
3675 }
3676
3677 return false;
3678}
3679
3681ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3682 Expr *ExplicitExpr = ESpec.getExpr();
3683 if (ExplicitExpr)
3684 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3685 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3686}
3687
3689
3691 auto RedeclIt = Redecls.begin();
3692 // Import the first part of the decl chain. I.e. import all previous
3693 // declarations starting from the canonical decl.
3694 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3695 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3696 if (!ToRedeclOrErr)
3697 return ToRedeclOrErr.takeError();
3698 }
3699 assert(*RedeclIt == D);
3700
3701 // Import the major distinguishing characteristics of this function.
3702 DeclContext *DC, *LexicalDC;
3703 DeclarationName Name;
3704 SourceLocation Loc;
3705 NamedDecl *ToD;
3706 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3707 return std::move(Err);
3708 if (ToD)
3709 return ToD;
3710
3711 FunctionDecl *FoundByLookup = nullptr;
3713
3714 // If this is a function template specialization, then try to find the same
3715 // existing specialization in the "to" context. The lookup below will not
3716 // find any specialization, but would find the primary template; thus, we
3717 // have to skip normal lookup in case of specializations.
3718 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3719 if (D->getTemplatedKind() ==
3721 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3722 if (!FoundFunctionOrErr)
3723 return FoundFunctionOrErr.takeError();
3724 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3725 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3726 return Def;
3727 FoundByLookup = FoundFunction;
3728 }
3729 }
3730 // Try to find a function in our own ("to") context with the same name, same
3731 // type, and in the same context as the function we're importing.
3732 else if (!LexicalDC->isFunctionOrMethod()) {
3733 SmallVector<NamedDecl *, 4> ConflictingDecls;
3735 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3736 for (auto *FoundDecl : FoundDecls) {
3737 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3738 continue;
3739
3740 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3741 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3742 continue;
3743
3744 if (IsStructuralMatch(D, FoundFunction)) {
3745 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3746 return Def;
3747 FoundByLookup = FoundFunction;
3748 break;
3749 }
3750 // FIXME: Check for overloading more carefully, e.g., by boosting
3751 // Sema::IsOverload out to the AST library.
3752
3753 // Function overloading is okay in C++.
3754 if (Importer.getToContext().getLangOpts().CPlusPlus)
3755 continue;
3756
3757 // Complain about inconsistent function types.
3758 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3759 << Name << D->getType() << FoundFunction->getType();
3760 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3761 << FoundFunction->getType();
3762 ConflictingDecls.push_back(FoundDecl);
3763 }
3764 }
3765
3766 if (!ConflictingDecls.empty()) {
3767 ExpectedName NameOrErr = Importer.HandleNameConflict(
3768 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3769 if (NameOrErr)
3770 Name = NameOrErr.get();
3771 else
3772 return NameOrErr.takeError();
3773 }
3774 }
3775
3776 // We do not allow more than one in-class declaration of a function. This is
3777 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3778 // assumes there is only one in-class declaration. Building a redecl
3779 // chain would result in more than one in-class declaration for
3780 // overrides (even if they are part of the same redecl chain inside the
3781 // derived class.)
3782 if (FoundByLookup) {
3783 if (isa<CXXMethodDecl>(FoundByLookup)) {
3784 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3785 if (!D->doesThisDeclarationHaveABody()) {
3786 if (FunctionTemplateDecl *DescribedD =
3788 // Handle a "templated" function together with its described
3789 // template. This avoids need for a similar check at import of the
3790 // described template.
3791 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3792 "Templated function mapped to non-templated?");
3793 Importer.MapImported(DescribedD,
3794 FoundByLookup->getDescribedFunctionTemplate());
3795 }
3796 return Importer.MapImported(D, FoundByLookup);
3797 } else {
3798 // Let's continue and build up the redecl chain in this case.
3799 // FIXME Merge the functions into one decl.
3800 }
3801 }
3802 }
3803 }
3804
3805 DeclarationNameInfo NameInfo(Name, Loc);
3806 // Import additional name location/type info.
3807 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3808 return std::move(Err);
3809
3810 QualType FromTy = D->getType();
3811 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3812 // Set to true if we do not import the type of the function as is. There are
3813 // cases when the original type would result in an infinite recursion during
3814 // the import. To avoid an infinite recursion when importing, we create the
3815 // FunctionDecl with a simplified function type and update it only after the
3816 // relevant AST nodes are already imported.
3817 // The type is related to TypeSourceInfo (it references the type), so we must
3818 // do the same with TypeSourceInfo.
3819 bool UsedDifferentProtoType = false;
3820 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3821 QualType FromReturnTy = FromFPT->getReturnType();
3822 // Functions with auto return type may define a struct inside their body
3823 // and the return type could refer to that struct.
3824 // E.g.: auto foo() { struct X{}; return X(); }
3825 // To avoid an infinite recursion when importing, create the FunctionDecl
3826 // with a simplified return type.
3828 FromReturnTy = Importer.getFromContext().VoidTy;
3829 UsedDifferentProtoType = true;
3830 }
3831 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3832 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3833 // FunctionDecl that we are importing the FunctionProtoType for.
3834 // To avoid an infinite recursion when importing, create the FunctionDecl
3835 // with a simplified function type.
3836 if (FromEPI.ExceptionSpec.SourceDecl ||
3837 FromEPI.ExceptionSpec.SourceTemplate ||
3838 FromEPI.ExceptionSpec.NoexceptExpr) {
3840 FromEPI = DefaultEPI;
3841 UsedDifferentProtoType = true;
3842 }
3843 FromTy = Importer.getFromContext().getFunctionType(
3844 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3845 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3846 FromTy, D->getBeginLoc());
3847 }
3848
3849 Error Err = Error::success();
3850 auto T = importChecked(Err, FromTy);
3851 auto TInfo = importChecked(Err, FromTSI);
3852 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3853 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3854 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3855 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3856 auto TrailingRequiresClause =
3858 if (Err)
3859 return std::move(Err);
3860
3861 // Import the function parameters.
3863 for (auto *P : D->parameters()) {
3864 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3865 Parameters.push_back(*ToPOrErr);
3866 else
3867 return ToPOrErr.takeError();
3868 }
3869
3870 // Create the imported function.
3871 FunctionDecl *ToFunction = nullptr;
3872 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3873 ExplicitSpecifier ESpec =
3874 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3875 if (Err)
3876 return std::move(Err);
3877 auto ToInheritedConstructor = InheritedConstructor();
3878 if (FromConstructor->isInheritingConstructor()) {
3879 Expected<InheritedConstructor> ImportedInheritedCtor =
3880 import(FromConstructor->getInheritedConstructor());
3881 if (!ImportedInheritedCtor)
3882 return ImportedInheritedCtor.takeError();
3883 ToInheritedConstructor = *ImportedInheritedCtor;
3884 }
3885 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3886 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3887 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3889 ToInheritedConstructor, TrailingRequiresClause))
3890 return ToFunction;
3891 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3892
3893 Error Err = Error::success();
3894 auto ToOperatorDelete = importChecked(
3895 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
3896 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
3897 if (Err)
3898 return std::move(Err);
3899
3900 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3901 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3902 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3904 TrailingRequiresClause))
3905 return ToFunction;
3906
3907 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
3908
3909 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
3910 } else if (CXXConversionDecl *FromConversion =
3911 dyn_cast<CXXConversionDecl>(D)) {
3912 ExplicitSpecifier ESpec =
3913 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
3914 if (Err)
3915 return std::move(Err);
3916 if (GetImportedOrCreateDecl<CXXConversionDecl>(
3917 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3918 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3919 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
3920 SourceLocation(), TrailingRequiresClause))
3921 return ToFunction;
3922 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3923 if (GetImportedOrCreateDecl<CXXMethodDecl>(
3924 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3925 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3926 Method->UsesFPIntrin(), Method->isInlineSpecified(),
3927 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
3928 return ToFunction;
3929 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
3930 ExplicitSpecifier ESpec =
3931 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
3932 CXXConstructorDecl *Ctor =
3933 importChecked(Err, Guide->getCorrespondingConstructor());
3934 if (Err)
3935 return std::move(Err);
3936 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
3937 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
3938 NameInfo, T, TInfo, ToEndLoc, Ctor))
3939 return ToFunction;
3940 cast<CXXDeductionGuideDecl>(ToFunction)
3941 ->setDeductionCandidateKind(Guide->getDeductionCandidateKind());
3942 } else {
3943 if (GetImportedOrCreateDecl(
3944 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
3945 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
3947 D->getConstexprKind(), TrailingRequiresClause))
3948 return ToFunction;
3949 }
3950
3951 // Connect the redecl chain.
3952 if (FoundByLookup) {
3953 auto *Recent = const_cast<FunctionDecl *>(
3954 FoundByLookup->getMostRecentDecl());
3955 ToFunction->setPreviousDecl(Recent);
3956 // FIXME Probably we should merge exception specifications. E.g. In the
3957 // "To" context the existing function may have exception specification with
3958 // noexcept-unevaluated, while the newly imported function may have an
3959 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
3960 // decl and its redeclarations may be required.
3961 }
3962
3963 StringLiteral *Msg = D->getDeletedMessage();
3964 if (Msg) {
3965 auto Imported = import(Msg);
3966 if (!Imported)
3967 return Imported.takeError();
3968 Msg = *Imported;
3969 }
3970
3971 ToFunction->setQualifierInfo(ToQualifierLoc);
3972 ToFunction->setAccess(D->getAccess());
3973 ToFunction->setLexicalDeclContext(LexicalDC);
3974 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
3975 ToFunction->setTrivial(D->isTrivial());
3976 ToFunction->setIsPureVirtual(D->isPureVirtual());
3977 ToFunction->setDefaulted(D->isDefaulted());
3979 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
3982 ToFunction->setRangeEnd(ToEndLoc);
3983 ToFunction->setDefaultLoc(ToDefaultLoc);
3984
3985 if (Msg)
3986 ToFunction->setDefaultedOrDeletedInfo(
3988 Importer.getToContext(), {}, Msg));
3989
3990 // Set the parameters.
3991 for (auto *Param : Parameters) {
3992 Param->setOwningFunction(ToFunction);
3993 ToFunction->addDeclInternal(Param);
3994 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
3995 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
3996 }
3997 ToFunction->setParams(Parameters);
3998
3999 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4000 // params it refers to.
4001 if (TInfo) {
4002 if (auto ProtoLoc =
4003 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4004 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4005 ProtoLoc.setParam(I, Parameters[I]);
4006 }
4007 }
4008
4009 // Import the describing template function, if any.
4010 if (FromFT) {
4011 auto ToFTOrErr = import(FromFT);
4012 if (!ToFTOrErr)
4013 return ToFTOrErr.takeError();
4014 }
4015
4016 // Import Ctor initializers.
4017 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4018 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4019 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4020 // Import first, then allocate memory and copy if there was no error.
4021 if (Error Err = ImportContainerChecked(
4022 FromConstructor->inits(), CtorInitializers))
4023 return std::move(Err);
4024 auto **Memory =
4025 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4026 std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
4027 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4028 ToCtor->setCtorInitializers(Memory);
4029 ToCtor->setNumCtorInitializers(NumInitializers);
4030 }
4031 }
4032
4033 // If it is a template, import all related things.
4034 if (Error Err = ImportTemplateInformation(D, ToFunction))
4035 return std::move(Err);
4036
4037 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4038 if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
4039 FromCXXMethod))
4040 return std::move(Err);
4041
4043 Error Err = ImportFunctionDeclBody(D, ToFunction);
4044
4045 if (Err)
4046 return std::move(Err);
4047 }
4048
4049 // Import and set the original type in case we used another type.
4050 if (UsedDifferentProtoType) {
4051 if (ExpectedType TyOrErr = import(D->getType()))
4052 ToFunction->setType(*TyOrErr);
4053 else
4054 return TyOrErr.takeError();
4055 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4056 ToFunction->setTypeSourceInfo(*TSIOrErr);
4057 else
4058 return TSIOrErr.takeError();
4059 }
4060
4061 // FIXME: Other bits to merge?
4062
4063 addDeclToContexts(D, ToFunction);
4064
4065 // Import the rest of the chain. I.e. import all subsequent declarations.
4066 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4067 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4068 if (!ToRedeclOrErr)
4069 return ToRedeclOrErr.takeError();
4070 }
4071
4072 return ToFunction;
4073}
4074
4076 return VisitFunctionDecl(D);
4077}
4078
4080 return VisitCXXMethodDecl(D);
4081}
4082
4084 return VisitCXXMethodDecl(D);
4085}
4086
4088 return VisitCXXMethodDecl(D);
4089}
4090
4093 return VisitFunctionDecl(D);
4094}
4095
4097 // Import the major distinguishing characteristics of a variable.
4098 DeclContext *DC, *LexicalDC;
4099 DeclarationName Name;
4100 SourceLocation Loc;
4101 NamedDecl *ToD;
4102 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4103 return std::move(Err);
4104 if (ToD)
4105 return ToD;
4106
4107 // Determine whether we've already imported this field.
4108 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4109 for (auto *FoundDecl : FoundDecls) {
4110 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4111 // For anonymous fields, match up by index.
4112 if (!Name &&
4114 ASTImporter::getFieldIndex(FoundField))
4115 continue;
4116
4117 if (Importer.IsStructurallyEquivalent(D->getType(),
4118 FoundField->getType())) {
4119 Importer.MapImported(D, FoundField);
4120 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4121 // initializer of a FieldDecl might not had been instantiated in the
4122 // "To" context. However, the "From" context might instantiated that,
4123 // thus we have to merge that.
4124 // Note: `hasInClassInitializer()` is not the same as non-null
4125 // `getInClassInitializer()` value.
4126 if (Expr *FromInitializer = D->getInClassInitializer()) {
4127 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4128 // Import of the FromInitializer may result in the setting of
4129 // InClassInitializer. If not, set it here.
4130 assert(FoundField->hasInClassInitializer() &&
4131 "Field should have an in-class initializer if it has an "
4132 "expression for it.");
4133 if (!FoundField->getInClassInitializer())
4134 FoundField->setInClassInitializer(*ToInitializerOrErr);
4135 } else {
4136 return ToInitializerOrErr.takeError();
4137 }
4138 }
4139 return FoundField;
4140 }
4141
4142 // FIXME: Why is this case not handled with calling HandleNameConflict?
4143 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4144 << Name << D->getType() << FoundField->getType();
4145 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4146 << FoundField->getType();
4147
4148 return make_error<ASTImportError>(ASTImportError::NameConflict);
4149 }
4150 }
4151
4152 Error Err = Error::success();
4153 auto ToType = importChecked(Err, D->getType());
4154 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4155 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4156 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4157 if (Err)
4158 return std::move(Err);
4159 const Type *ToCapturedVLAType = nullptr;
4160 if (Error Err = Importer.importInto(
4161 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4162 return std::move(Err);
4163
4164 FieldDecl *ToField;
4165 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4166 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4167 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4168 D->getInClassInitStyle()))
4169 return ToField;
4170
4171 // We need [[no_unqiue_address]] attributes to be added to FieldDecl, before
4172 // we add fields in CXXRecordDecl::addedMember, otherwise record will be
4173 // marked as having non-zero size.
4174 Err = Importer.ImportAttrs(ToField, D);
4175 if (Err)
4176 return std::move(Err);
4177 ToField->setAccess(D->getAccess());
4178 ToField->setLexicalDeclContext(LexicalDC);
4179 ToField->setImplicit(D->isImplicit());
4180 if (ToCapturedVLAType)
4181 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4182 LexicalDC->addDeclInternal(ToField);
4183 // Import initializer only after the field was created, it may have recursive
4184 // reference to the field.
4185 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4186 if (Err)
4187 return std::move(Err);
4188 if (ToInitializer) {
4189 auto *AlreadyImported = ToField->getInClassInitializer();
4190 if (AlreadyImported)
4191 assert(ToInitializer == AlreadyImported &&
4192 "Duplicate import of in-class initializer.");
4193 else
4194 ToField->setInClassInitializer(ToInitializer);
4195 }
4196
4197 return ToField;
4198}
4199
4201 // Import the major distinguishing characteristics of a variable.
4202 DeclContext *DC, *LexicalDC;
4203 DeclarationName Name;
4204 SourceLocation Loc;
4205 NamedDecl *ToD;
4206 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4207 return std::move(Err);
4208 if (ToD)
4209 return ToD;
4210
4211 // Determine whether we've already imported this field.
4212 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4213 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4214 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4215 // For anonymous indirect fields, match up by index.
4216 if (!Name &&
4218 ASTImporter::getFieldIndex(FoundField))
4219 continue;
4220
4221 if (Importer.IsStructurallyEquivalent(D->getType(),
4222 FoundField->getType(),
4223 !Name.isEmpty())) {
4224 Importer.MapImported(D, FoundField);
4225 return FoundField;
4226 }
4227
4228 // If there are more anonymous fields to check, continue.
4229 if (!Name && I < N-1)
4230 continue;
4231
4232 // FIXME: Why is this case not handled with calling HandleNameConflict?
4233 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4234 << Name << D->getType() << FoundField->getType();
4235 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4236 << FoundField->getType();
4237
4238 return make_error<ASTImportError>(ASTImportError::NameConflict);
4239 }
4240 }
4241
4242 // Import the type.
4243 auto TypeOrErr = import(D->getType());
4244 if (!TypeOrErr)
4245 return TypeOrErr.takeError();
4246
4247 auto **NamedChain =
4248 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4249
4250 unsigned i = 0;
4251 for (auto *PI : D->chain())
4252 if (Expected<NamedDecl *> ToD = import(PI))
4253 NamedChain[i++] = *ToD;
4254 else
4255 return ToD.takeError();
4256
4258 IndirectFieldDecl *ToIndirectField;
4259 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4260 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4261 // FIXME here we leak `NamedChain` which is allocated before
4262 return ToIndirectField;
4263
4264 ToIndirectField->setAccess(D->getAccess());
4265 ToIndirectField->setLexicalDeclContext(LexicalDC);
4266 LexicalDC->addDeclInternal(ToIndirectField);
4267 return ToIndirectField;
4268}
4269
4270/// Used as return type of getFriendCountAndPosition.
4272 /// Number of similar looking friends.
4273 unsigned int TotalCount;
4274 /// Index of the specific FriendDecl.
4275 unsigned int IndexOfDecl;
4276};
4277
4278static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4279 FriendDecl *FD2) {
4280 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4281 return false;
4282
4283 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4284 return Importer.IsStructurallyEquivalent(
4285 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4286
4287 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4289 FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
4291 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4292 return Ctx.IsEquivalent(FD1, FD2);
4293}
4294
4296 FriendDecl *FD) {
4297 unsigned int FriendCount = 0;
4298 std::optional<unsigned int> FriendPosition;
4299 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4300
4301 for (FriendDecl *FoundFriend : RD->friends()) {
4302 if (FoundFriend == FD) {
4303 FriendPosition = FriendCount;
4304 ++FriendCount;
4305 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4306 ++FriendCount;
4307 }
4308 }
4309
4310 assert(FriendPosition && "Friend decl not found in own parent.");
4311
4312 return {FriendCount, *FriendPosition};
4313}
4314
4316 // Import the major distinguishing characteristics of a declaration.
4317 DeclContext *DC, *LexicalDC;
4318 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4319 return std::move(Err);
4320
4321 // Determine whether we've already imported this decl.
4322 // FriendDecl is not a NamedDecl so we cannot use lookup.
4323 // We try to maintain order and count of redundant friend declarations.
4324 const auto *RD = cast<CXXRecordDecl>(DC);
4325 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4326 for (FriendDecl *ImportedFriend : RD->friends())
4327 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4328 ImportedEquivalentFriends.push_back(ImportedFriend);
4329
4330 FriendCountAndPosition CountAndPosition =
4331 getFriendCountAndPosition(Importer, D);
4332
4333 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4334 "Class with non-matching friends is imported, ODR check wrong?");
4335 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4336 return Importer.MapImported(
4337 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4338
4339 // Not found. Create it.
4340 // The declarations will be put into order later by ImportDeclContext.
4342 if (NamedDecl *FriendD = D->getFriendDecl()) {
4343 NamedDecl *ToFriendD;
4344 if (Error Err = importInto(ToFriendD, FriendD))
4345 return std::move(Err);
4346
4347 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4348 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4349 ToFriendD->setObjectOfFriendDecl(false);
4350
4351 ToFU = ToFriendD;
4352 } else { // The friend is a type, not a decl.
4353 if (auto TSIOrErr = import(D->getFriendType()))
4354 ToFU = *TSIOrErr;
4355 else
4356 return TSIOrErr.takeError();
4357 }
4358
4359 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4360 auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4361 for (unsigned I = 0; I < D->NumTPLists; I++) {
4362 if (auto ListOrErr = import(FromTPLists[I]))
4363 ToTPLists[I] = *ListOrErr;
4364 else
4365 return ListOrErr.takeError();
4366 }
4367
4368 auto LocationOrErr = import(D->getLocation());
4369 if (!LocationOrErr)
4370 return LocationOrErr.takeError();
4371 auto FriendLocOrErr = import(D->getFriendLoc());
4372 if (!FriendLocOrErr)
4373 return FriendLocOrErr.takeError();
4374
4375 FriendDecl *FrD;
4376 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4377 *LocationOrErr, ToFU,
4378 *FriendLocOrErr, ToTPLists))
4379 return FrD;
4380
4381 FrD->setAccess(D->getAccess());
4382 FrD->setLexicalDeclContext(LexicalDC);
4383 LexicalDC->addDeclInternal(FrD);
4384 return FrD;
4385}
4386
4388 // Import the major distinguishing characteristics of an ivar.
4389 DeclContext *DC, *LexicalDC;
4390 DeclarationName Name;
4391 SourceLocation Loc;
4392 NamedDecl *ToD;
4393 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4394 return std::move(Err);
4395 if (ToD)
4396 return ToD;
4397
4398 // Determine whether we've already imported this ivar
4399 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4400 for (auto *FoundDecl : FoundDecls) {
4401 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4402 if (Importer.IsStructurallyEquivalent(D->getType(),
4403 FoundIvar->getType())) {
4404 Importer.MapImported(D, FoundIvar);
4405 return FoundIvar;
4406 }
4407
4408 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4409 << Name << D->getType() << FoundIvar->getType();
4410 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4411 << FoundIvar->getType();
4412
4413 return make_error<ASTImportError>(ASTImportError::NameConflict);
4414 }
4415 }
4416
4417 Error Err = Error::success();
4418 auto ToType = importChecked(Err, D->getType());
4419 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4420 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4421 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4422 if (Err)
4423 return std::move(Err);
4424
4425 ObjCIvarDecl *ToIvar;
4426 if (GetImportedOrCreateDecl(
4427 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4428 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4429 ToType, ToTypeSourceInfo,
4430 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4431 return ToIvar;
4432
4433 ToIvar->setLexicalDeclContext(LexicalDC);
4434 LexicalDC->addDeclInternal(ToIvar);
4435 return ToIvar;
4436}
4437
4439
4441 auto RedeclIt = Redecls.begin();
4442 // Import the first part of the decl chain. I.e. import all previous
4443 // declarations starting from the canonical decl.
4444 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4445 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4446 if (!RedeclOrErr)
4447 return RedeclOrErr.takeError();
4448 }
4449 assert(*RedeclIt == D);
4450
4451 // Import the major distinguishing characteristics of a variable.
4452 DeclContext *DC, *LexicalDC;
4453 DeclarationName Name;
4454 SourceLocation Loc;
4455 NamedDecl *ToD;
4456 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4457 return std::move(Err);
4458 if (ToD)
4459 return ToD;
4460
4461 // Try to find a variable in our own ("to") context with the same name and
4462 // in the same context as the variable we're importing.
4463 VarDecl *FoundByLookup = nullptr;
4464 if (D->isFileVarDecl()) {
4465 SmallVector<NamedDecl *, 4> ConflictingDecls;
4466 unsigned IDNS = Decl::IDNS_Ordinary;
4467 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4468 for (auto *FoundDecl : FoundDecls) {
4469 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4470 continue;
4471
4472 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4473 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4474 continue;
4475 if (Importer.IsStructurallyEquivalent(D->getType(),
4476 FoundVar->getType())) {
4477
4478 // The VarDecl in the "From" context has a definition, but in the
4479 // "To" context we already have a definition.
4480 VarDecl *FoundDef = FoundVar->getDefinition();
4481 if (D->isThisDeclarationADefinition() && FoundDef)
4482 // FIXME Check for ODR error if the two definitions have
4483 // different initializers?
4484 return Importer.MapImported(D, FoundDef);
4485
4486 // The VarDecl in the "From" context has an initializer, but in the
4487 // "To" context we already have an initializer.
4488 const VarDecl *FoundDInit = nullptr;
4489 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4490 // FIXME Diagnose ODR error if the two initializers are different?
4491 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4492
4493 FoundByLookup = FoundVar;
4494 break;
4495 }
4496
4497 const ArrayType *FoundArray
4498 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4499 const ArrayType *TArray
4500 = Importer.getToContext().getAsArrayType(D->getType());
4501 if (FoundArray && TArray) {
4502 if (isa<IncompleteArrayType>(FoundArray) &&
4503 isa<ConstantArrayType>(TArray)) {
4504 // Import the type.
4505 if (auto TyOrErr = import(D->getType()))
4506 FoundVar->setType(*TyOrErr);
4507 else
4508 return TyOrErr.takeError();
4509
4510 FoundByLookup = FoundVar;
4511 break;
4512 } else if (isa<IncompleteArrayType>(TArray) &&
4513 isa<ConstantArrayType>(FoundArray)) {
4514 FoundByLookup = FoundVar;
4515 break;
4516 }
4517 }
4518
4519 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4520 << Name << D->getType() << FoundVar->getType();
4521 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4522 << FoundVar->getType();
4523 ConflictingDecls.push_back(FoundDecl);
4524 }
4525 }
4526
4527 if (!ConflictingDecls.empty()) {
4528 ExpectedName NameOrErr = Importer.HandleNameConflict(
4529 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4530 if (NameOrErr)
4531 Name = NameOrErr.get();
4532 else
4533 return NameOrErr.takeError();
4534 }
4535 }
4536
4537 Error Err = Error::success();
4538 auto ToType = importChecked(Err, D->getType());
4539 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4540 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4541 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4542 if (Err)
4543 return std::move(Err);
4544
4545 VarDecl *ToVar;
4546 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4547 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4548 if (Error Err =
4549 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4550 return std::move(Err);
4551 DecompositionDecl *ToDecomp;
4552 if (GetImportedOrCreateDecl(
4553 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4554 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4555 return ToDecomp;
4556 ToVar = ToDecomp;
4557 } else {
4558 // Create the imported variable.
4559 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4560 ToInnerLocStart, Loc,
4561 Name.getAsIdentifierInfo(), ToType,
4562 ToTypeSourceInfo, D->getStorageClass()))
4563 return ToVar;
4564 }
4565
4566 ToVar->setTSCSpec(D->getTSCSpec());
4567 ToVar->setQualifierInfo(ToQualifierLoc);
4568 ToVar->setAccess(D->getAccess());
4569 ToVar->setLexicalDeclContext(LexicalDC);
4570 if (D->isInlineSpecified())
4571 ToVar->setInlineSpecified();
4572 if (D->isInline())
4573 ToVar->setImplicitlyInline();
4574
4575 if (FoundByLookup) {
4576 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4577 ToVar->setPreviousDecl(Recent);
4578 }
4579
4580 // Import the described template, if any.
4581 if (D->getDescribedVarTemplate()) {
4582 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4583 if (!ToVTOrErr)
4584 return ToVTOrErr.takeError();
4586 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4588 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4589 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4590 else
4591 return ToInstOrErr.takeError();
4592 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4594 else
4595 return POIOrErr.takeError();
4596 }
4597
4598 if (Error Err = ImportInitializer(D, ToVar))
4599 return std::move(Err);
4600
4601 if (D->isConstexpr())
4602 ToVar->setConstexpr(true);
4603
4604 addDeclToContexts(D, ToVar);
4605
4606 // Import the rest of the chain. I.e. import all subsequent declarations.
4607 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4608 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4609 if (!RedeclOrErr)
4610 return RedeclOrErr.takeError();
4611 }
4612
4613 return ToVar;
4614}
4615
4617 // Parameters are created in the translation unit's context, then moved
4618 // into the function declaration's context afterward.
4620
4621 Error Err = Error::success();
4622 auto ToDeclName = importChecked(Err, D->getDeclName());
4623 auto ToLocation = importChecked(Err, D->getLocation());
4624 auto ToType = importChecked(Err, D->getType());
4625 if (Err)
4626 return std::move(Err);
4627
4628 // Create the imported parameter.
4629 ImplicitParamDecl *ToParm = nullptr;
4630 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4631 ToLocation, ToDeclName.getAsIdentifierInfo(),
4632 ToType, D->getParameterKind()))
4633 return ToParm;
4634 return ToParm;
4635}
4636
4638 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4641 FromParam->getExplicitObjectParamThisLoc());
4642 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4643
4644 if (FromParam->hasUninstantiatedDefaultArg()) {
4645 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4646 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4647 else
4648 return ToDefArgOrErr.takeError();
4649 } else if (FromParam->hasUnparsedDefaultArg()) {
4650 ToParam->setUnparsedDefaultArg();
4651 } else if (FromParam->hasDefaultArg()) {
4652 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4653 ToParam->setDefaultArg(*ToDefArgOrErr);
4654 else
4655 return ToDefArgOrErr.takeError();
4656 }
4657
4658 return Error::success();
4659}
4660
4663 Error Err = Error::success();
4664 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4665 ConstructorUsingShadowDecl *ToShadow =
4666 importChecked(Err, From.getShadowDecl());
4667 if (Err)
4668 return std::move(Err);
4669 return InheritedConstructor(ToShadow, ToBaseCtor);
4670}
4671
4673 // Parameters are created in the translation unit's context, then moved
4674 // into the function declaration's context afterward.
4676
4677 Error Err = Error::success();
4678 auto ToDeclName = importChecked(Err, D->getDeclName());
4679 auto ToLocation = importChecked(Err, D->getLocation());
4680 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4681 auto ToType = importChecked(Err, D->getType());
4682 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4683 if (Err)
4684 return std::move(Err);
4685
4686 ParmVarDecl *ToParm;
4687 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4688 ToInnerLocStart, ToLocation,
4689 ToDeclName.getAsIdentifierInfo(), ToType,
4690 ToTypeSourceInfo, D->getStorageClass(),
4691 /*DefaultArg*/ nullptr))
4692 return ToParm;
4693
4694 // Set the default argument. It should be no problem if it was already done.
4695 // Do not import the default expression before GetImportedOrCreateDecl call
4696 // to avoid possible infinite import loop because circular dependency.
4697 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4698 return std::move(Err);
4699
4700 if (D->isObjCMethodParameter()) {
4703 } else {
4706 }
4707
4708 return ToParm;
4709}
4710
4712 // Import the major distinguishing characteristics of a method.
4713 DeclContext *DC, *LexicalDC;
4714 DeclarationName Name;
4715 SourceLocation Loc;
4716 NamedDecl *ToD;
4717 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4718 return std::move(Err);
4719 if (ToD)
4720 return ToD;
4721
4722 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4723 for (auto *FoundDecl : FoundDecls) {
4724 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4725 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4726 continue;
4727
4728 // Check return types.
4729 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4730 FoundMethod->getReturnType())) {
4731 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4732 << D->isInstanceMethod() << Name << D->getReturnType()
4733 << FoundMethod->getReturnType();
4734 Importer.ToDiag(FoundMethod->getLocation(),
4735 diag::note_odr_objc_method_here)
4736 << D->isInstanceMethod() << Name;
4737
4738 return make_error<ASTImportError>(ASTImportError::NameConflict);
4739 }
4740
4741 // Check the number of parameters.
4742 if (D->param_size() != FoundMethod->param_size()) {
4743 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4744 << D->isInstanceMethod() << Name
4745 << D->param_size() << FoundMethod->param_size();
4746 Importer.ToDiag(FoundMethod->getLocation(),
4747 diag::note_odr_objc_method_here)
4748 << D->isInstanceMethod() << Name;
4749
4750 return make_error<ASTImportError>(ASTImportError::NameConflict);
4751 }
4752
4753 // Check parameter types.
4755 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4756 P != PEnd; ++P, ++FoundP) {
4757 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4758 (*FoundP)->getType())) {
4759 Importer.FromDiag((*P)->getLocation(),
4760 diag::warn_odr_objc_method_param_type_inconsistent)
4761 << D->isInstanceMethod() << Name
4762 << (*P)->getType() << (*FoundP)->getType();
4763 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4764 << (*FoundP)->getType();
4765
4766 return make_error<ASTImportError>(ASTImportError::NameConflict);
4767 }
4768 }
4769
4770 // Check variadic/non-variadic.
4771 // Check the number of parameters.
4772 if (D->isVariadic() != FoundMethod->isVariadic()) {
4773 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4774 << D->isInstanceMethod() << Name;
4775 Importer.ToDiag(FoundMethod->getLocation(),
4776 diag::note_odr_objc_method_here)
4777 << D->isInstanceMethod() << Name;
4778
4779 return make_error<ASTImportError>(ASTImportError::NameConflict);
4780 }
4781
4782 // FIXME: Any other bits we need to merge?
4783 return Importer.MapImported(D, FoundMethod);
4784 }
4785 }
4786
4787 Error Err = Error::success();
4788 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4789 auto ToReturnType = importChecked(Err, D->getReturnType());
4790 auto ToReturnTypeSourceInfo =
4792 if (Err)
4793 return std::move(Err);
4794
4795 ObjCMethodDecl *ToMethod;
4796 if (GetImportedOrCreateDecl(
4797 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4798 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4802 return ToMethod;
4803
4804 // FIXME: When we decide to merge method definitions, we'll need to
4805 // deal with implicit parameters.
4806
4807 // Import the parameters
4809 for (auto *FromP : D->parameters()) {
4810 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4811 ToParams.push_back(*ToPOrErr);
4812 else
4813 return ToPOrErr.takeError();
4814 }
4815
4816 // Set the parameters.
4817 for (auto *ToParam : ToParams) {
4818 ToParam->setOwningFunction(ToMethod);
4819 ToMethod->addDeclInternal(ToParam);
4820 }
4821
4823 D->getSelectorLocs(FromSelLocs);
4824 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4825 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4826 return std::move(Err);
4827
4828 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4829
4830 ToMethod->setLexicalDeclContext(LexicalDC);
4831 LexicalDC->addDeclInternal(ToMethod);
4832
4833 // Implicit params are declared when Sema encounters the definition but this
4834 // never happens when the method is imported. Manually declare the implicit
4835 // params now that the MethodDecl knows its class interface.
4836 if (D->getSelfDecl())
4837 ToMethod->createImplicitParams(Importer.getToContext(),
4838 ToMethod->getClassInterface());
4839
4840 return ToMethod;
4841}
4842
4844 // Import the major distinguishing characteristics of a category.
4845 DeclContext *DC, *LexicalDC;
4846 DeclarationName Name;
4847 SourceLocation Loc;
4848 NamedDecl *ToD;
4849 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4850 return std::move(Err);
4851 if (ToD)
4852 return ToD;
4853
4854 Error Err = Error::success();
4855 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4856 auto ToLocation = importChecked(Err, D->getLocation());
4857 auto ToColonLoc = importChecked(Err, D->getColonLoc());
4858 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4859 if (Err)
4860 return std::move(Err);
4861
4863 if (GetImportedOrCreateDecl(
4864 Result, D, Importer.getToContext(), DC, D->getVariance(),
4865 ToVarianceLoc, D->getIndex(),
4866 ToLocation, Name.getAsIdentifierInfo(),
4867 ToColonLoc, ToTypeSourceInfo))
4868 return Result;
4869
4870 // Only import 'ObjCTypeParamType' after the decl is created.
4871 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4872 if (Err)
4873 return std::move(Err);
4874 Result->setTypeForDecl(ToTypeForDecl);
4875 Result->setLexicalDeclContext(LexicalDC);
4876 return Result;
4877}
4878
4880 // Import the major distinguishing characteristics of a category.
4881 DeclContext *DC, *LexicalDC;
4882 DeclarationName Name;
4883 SourceLocation Loc;
4884 NamedDecl *ToD;
4885 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4886 return std::move(Err);
4887 if (ToD)
4888 return ToD;
4889
4890 ObjCInterfaceDecl *ToInterface;
4891 if (Error Err = importInto(ToInterface, D->getClassInterface()))
4892 return std::move(Err);
4893
4894 // Determine if we've already encountered this category.
4895 ObjCCategoryDecl *MergeWithCategory
4896 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
4897 ObjCCategoryDecl *ToCategory = MergeWithCategory;
4898 if (!ToCategory) {
4899
4900 Error Err = Error::success();
4901 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
4902 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
4903 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
4904 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
4905 if (Err)
4906 return std::move(Err);
4907
4908 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
4909 ToAtStartLoc, Loc,
4910 ToCategoryNameLoc,
4911 Name.getAsIdentifierInfo(), ToInterface,
4912 /*TypeParamList=*/nullptr,
4913 ToIvarLBraceLoc,
4914 ToIvarRBraceLoc))
4915 return ToCategory;
4916
4917 ToCategory->setLexicalDeclContext(LexicalDC);
4918 LexicalDC->addDeclInternal(ToCategory);
4919 // Import the type parameter list after MapImported, to avoid
4920 // loops when bringing in their DeclContext.
4921 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
4922 ToCategory->setTypeParamList(*PListOrErr);
4923 else
4924 return PListOrErr.takeError();
4925
4926 // Import protocols
4928 SmallVector<SourceLocation, 4> ProtocolLocs;
4930 = D->protocol_loc_begin();
4932 FromProtoEnd = D->protocol_end();
4933 FromProto != FromProtoEnd;
4934 ++FromProto, ++FromProtoLoc) {
4935 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4936 Protocols.push_back(*ToProtoOrErr);
4937 else
4938 return ToProtoOrErr.takeError();
4939
4940 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
4941 ProtocolLocs.push_back(*ToProtoLocOrErr);
4942 else
4943 return ToProtoLocOrErr.takeError();
4944 }
4945
4946 // FIXME: If we're merging, make sure that the protocol list is the same.
4947 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
4948 ProtocolLocs.data(), Importer.getToContext());
4949
4950 } else {
4951 Importer.MapImported(D, ToCategory);
4952 }
4953
4954 // Import all of the members of this category.
4955 if (Error Err = ImportDeclContext(D))
4956 return std::move(Err);
4957
4958 // If we have an implementation, import it as well.
4959 if (D->getImplementation()) {
4960 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
4961 import(D->getImplementation()))
4962 ToCategory->setImplementation(*ToImplOrErr);
4963 else
4964 return ToImplOrErr.takeError();
4965 }
4966
4967 return ToCategory;
4968}
4969
4972 if (To->getDefinition()) {
4974 if (Error Err = ImportDeclContext(From))
4975 return Err;
4976 return Error::success();
4977 }
4978
4979 // Start the protocol definition
4980 To->startDefinition();
4981
4982 // Import protocols
4984 SmallVector<SourceLocation, 4> ProtocolLocs;
4986 From->protocol_loc_begin();
4987 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
4988 FromProtoEnd = From->protocol_end();
4989 FromProto != FromProtoEnd;
4990 ++FromProto, ++FromProtoLoc) {
4991 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4992 Protocols.push_back(*ToProtoOrErr);
4993 else
4994 return ToProtoOrErr.takeError();
4995
4996 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
4997 ProtocolLocs.push_back(*ToProtoLocOrErr);
4998 else
4999 return ToProtoLocOrErr.takeError();
5000
5001 }
5002
5003 // FIXME: If we're merging, make sure that the protocol list is the same.
5004 To->setProtocolList(Protocols.data(), Protocols.size(),
5005 ProtocolLocs.data(), Importer.getToContext());
5006
5007 if (shouldForceImportDeclContext(Kind)) {
5008 // Import all of the members of this protocol.
5009 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5010 return Err;
5011 }
5012 return Error::success();
5013}
5014
5016 // If this protocol has a definition in the translation unit we're coming
5017 // from, but this particular declaration is not that definition, import the
5018 // definition and map to that.
5020 if (Definition && Definition != D) {
5021 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5022 return Importer.MapImported(D, *ImportedDefOrErr);
5023 else
5024 return ImportedDefOrErr.takeError();
5025 }
5026
5027 // Import the major distinguishing characteristics of a protocol.
5028 DeclContext *DC, *LexicalDC;
5029 DeclarationName Name;
5030 SourceLocation Loc;
5031 NamedDecl *ToD;
5032 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5033 return std::move(Err);
5034 if (ToD)
5035 return ToD;
5036
5037 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5038 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5039 for (auto *FoundDecl : FoundDecls) {
5041 continue;
5042
5043 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5044 break;
5045 }
5046
5047 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5048 if (!ToProto) {
5049 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5050 if (!ToAtBeginLocOrErr)
5051 return ToAtBeginLocOrErr.takeError();
5052
5053 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5054 Name.getAsIdentifierInfo(), Loc,
5055 *ToAtBeginLocOrErr,
5056 /*PrevDecl=*/nullptr))
5057 return ToProto;
5058 ToProto->setLexicalDeclContext(LexicalDC);
5059 LexicalDC->addDeclInternal(ToProto);
5060 }
5061
5062 Importer.MapImported(D, ToProto);
5063
5065 if (Error Err = ImportDefinition(D, ToProto))
5066 return std::move(Err);
5067
5068 return ToProto;
5069}
5070
5072 DeclContext *DC, *LexicalDC;
5073 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5074 return std::move(Err);
5075
5076 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5077 if (!ExternLocOrErr)
5078 return ExternLocOrErr.takeError();
5079
5080 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5081 if (!LangLocOrErr)
5082 return LangLocOrErr.takeError();
5083
5084 bool HasBraces = D->hasBraces();
5085
5086 LinkageSpecDecl *ToLinkageSpec;
5087 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5088 *ExternLocOrErr, *LangLocOrErr,
5089 D->getLanguage(), HasBraces))
5090 return ToLinkageSpec;
5091
5092 if (HasBraces) {
5093 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5094 if (!RBraceLocOrErr)
5095 return RBraceLocOrErr.takeError();
5096 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5097 }
5098
5099 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5100 LexicalDC->addDeclInternal(ToLinkageSpec);
5101
5102 return ToLinkageSpec;
5103}
5104
5106 BaseUsingDecl *ToSI) {
5107 for (UsingShadowDecl *FromShadow : D->shadows()) {
5108 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5109 ToSI->addShadowDecl(*ToShadowOrErr);
5110 else
5111 // FIXME: We return error here but the definition is already created
5112 // and available with lookups. How to fix this?..
5113 return ToShadowOrErr.takeError();
5114 }
5115 return ToSI;
5116}
5117
5119 DeclContext *DC, *LexicalDC;
5120 DeclarationName Name;
5121 SourceLocation Loc;
5122 NamedDecl *ToD = nullptr;
5123 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5124 return std::move(Err);
5125 if (ToD)
5126 return ToD;
5127
5128 Error Err = Error::success();
5129 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5130 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5131 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5132 if (Err)
5133 return std::move(Err);
5134
5135 DeclarationNameInfo NameInfo(Name, ToLoc);
5136 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5137 return std::move(Err);
5138
5139 UsingDecl *ToUsing;
5140 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5141 ToUsingLoc, ToQualifierLoc, NameInfo,
5142 D->hasTypename()))
5143 return ToUsing;
5144
5145 ToUsing->setLexicalDeclContext(LexicalDC);
5146 LexicalDC->addDeclInternal(ToUsing);
5147
5148 if (NamedDecl *FromPattern =
5150 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5152 ToUsing, *ToPatternOrErr);
5153 else
5154 return ToPatternOrErr.takeError();
5155 }
5156
5157 return ImportUsingShadowDecls(D, ToUsing);
5158}
5159
5161 DeclContext *DC, *LexicalDC;
5162 DeclarationName Name;
5163 SourceLocation Loc;
5164 NamedDecl *ToD = nullptr;
5165 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5166 return std::move(Err);
5167 if (ToD)
5168 return ToD;
5169
5170 Error Err = Error::success();
5171 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5172 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5173 auto ToNameLoc = importChecked(Err, D->getLocation());
5174 auto *ToEnumType = importChecked(Err, D->getEnumType());
5175 if (Err)
5176 return std::move(Err);
5177
5178 UsingEnumDecl *ToUsingEnum;
5179 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5180 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5181 return ToUsingEnum;
5182
5183 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5184 LexicalDC->addDeclInternal(ToUsingEnum);
5185
5186 if (UsingEnumDecl *FromPattern =
5188 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5189 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5190 *ToPatternOrErr);
5191 else
5192 return ToPatternOrErr.takeError();
5193 }
5194
5195 return ImportUsingShadowDecls(D, ToUsingEnum);
5196}
5197
5199 DeclContext *DC, *LexicalDC;
5200 DeclarationName Name;
5201 SourceLocation Loc;
5202 NamedDecl *ToD = nullptr;
5203 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5204 return std::move(Err);
5205 if (ToD)
5206 return ToD;
5207
5208 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5209 if (!ToIntroducerOrErr)
5210 return ToIntroducerOrErr.takeError();
5211
5212 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5213 if (!ToTargetOrErr)
5214 return ToTargetOrErr.takeError();
5215
5216 UsingShadowDecl *ToShadow;
5217 if (auto *FromConstructorUsingShadow =
5218 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5219 Error Err = Error::success();
5221 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5222 if (Err)
5223 return std::move(Err);
5224 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5225 // is really the "NominatedBaseClassShadowDecl" value if it exists
5226 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5227 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5228 // get the correct values.
5229 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5230 ToShadow, D, Importer.getToContext(), DC, Loc,
5231 cast<UsingDecl>(*ToIntroducerOrErr),
5232 Nominated ? Nominated : *ToTargetOrErr,
5233 FromConstructorUsingShadow->constructsVirtualBase()))
5234 return ToShadow;
5235 } else {
5236 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5237 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5238 return ToShadow;
5239 }
5240
5241 ToShadow->setLexicalDeclContext(LexicalDC);
5242 ToShadow->setAccess(D->getAccess());
5243
5244 if (UsingShadowDecl *FromPattern =
5246 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5248 ToShadow, *ToPatternOrErr);
5249 else
5250 // FIXME: We return error here but the definition is already created
5251 // and available with lookups. How to fix this?..
5252 return ToPatternOrErr.takeError();
5253 }
5254
5255 LexicalDC->addDeclInternal(ToShadow);
5256
5257 return ToShadow;
5258}
5259
5261 DeclContext *DC, *LexicalDC;
5262 DeclarationName Name;
5263 SourceLocation Loc;
5264 NamedDecl *ToD = nullptr;
5265 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5266 return std::move(Err);
5267 if (ToD)
5268 return ToD;
5269
5270 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5271 if (!ToComAncestorOrErr)
5272 return ToComAncestorOrErr.takeError();
5273
5274 Error Err = Error::success();
5275 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5276 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5277 auto ToNamespaceKeyLocation =
5279 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5280 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5281 if (Err)
5282 return std::move(Err);
5283
5284 UsingDirectiveDecl *ToUsingDir;
5285 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5286 ToUsingLoc,
5287 ToNamespaceKeyLocation,
5288 ToQualifierLoc,
5289 ToIdentLocation,
5290 ToNominatedNamespace, *ToComAncestorOrErr))
5291 return ToUsingDir;
5292
5293 ToUsingDir->setLexicalDeclContext(LexicalDC);
5294 LexicalDC->addDeclInternal(ToUsingDir);
5295
5296 return ToUsingDir;
5297}
5298
5300 DeclContext *DC, *LexicalDC;
5301 DeclarationName Name;
5302 SourceLocation Loc;
5303 NamedDecl *ToD = nullptr;
5304 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5305 return std::move(Err);
5306 if (ToD)
5307 return ToD;
5308
5309 auto ToInstantiatedFromUsingOrErr =
5310 Importer.Import(D->getInstantiatedFromUsingDecl());
5311 if (!ToInstantiatedFromUsingOrErr)
5312 return ToInstantiatedFromUsingOrErr.takeError();
5313 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5314 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5315 return std::move(Err);
5316
5317 UsingPackDecl *ToUsingPack;
5318 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5319 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5320 Expansions))
5321 return ToUsingPack;
5322
5323 addDeclToContexts(D, ToUsingPack);
5324
5325 return ToUsingPack;
5326}
5327
5330 DeclContext *DC, *LexicalDC;
5331 DeclarationName Name;
5332 SourceLocation Loc;
5333 NamedDecl *ToD = nullptr;
5334 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5335 return std::move(Err);
5336 if (ToD)
5337 return ToD;
5338
5339 Error Err = Error::success();
5340 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5341 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5342 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5343 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5344 if (Err)
5345 return std::move(Err);
5346
5347 DeclarationNameInfo NameInfo(Name, ToLoc);
5348 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5349 return std::move(Err);
5350
5351 UnresolvedUsingValueDecl *ToUsingValue;
5352 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5353 ToUsingLoc, ToQualifierLoc, NameInfo,
5354 ToEllipsisLoc))
5355 return ToUsingValue;
5356
5357 ToUsingValue->setAccess(D->getAccess());
5358 ToUsingValue->setLexicalDeclContext(LexicalDC);
5359 LexicalDC->addDeclInternal(ToUsingValue);
5360
5361 return ToUsingValue;
5362}
5363
5366 DeclContext *DC, *LexicalDC;
5367 DeclarationName Name;
5368 SourceLocation Loc;
5369 NamedDecl *ToD = nullptr;
5370 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5371 return std::move(Err);
5372 if (ToD)
5373 return ToD;
5374
5375 Error Err = Error::success();
5376 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5377 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5378 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5379 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5380 if (Err)
5381 return std::move(Err);
5382
5384 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5385 ToUsingLoc, ToTypenameLoc,
5386 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5387 return ToUsing;
5388
5389 ToUsing->setAccess(D->getAccess());
5390 ToUsing->setLexicalDeclContext(LexicalDC);
5391 LexicalDC->addDeclInternal(ToUsing);
5392
5393 return ToUsing;
5394}
5395
5397 Decl* ToD = nullptr;
5398 switch (D->getBuiltinTemplateKind()) {
5400 ToD = Importer.getToContext().getMakeIntegerSeqDecl();
5401 break;
5403 ToD = Importer.getToContext().getTypePackElementDecl();
5404 break;
5405 }
5406 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5407 Importer.MapImported(D, ToD);
5408 return ToD;
5409}
5410
5413 if (To->getDefinition()) {
5414 // Check consistency of superclass.
5415 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5416 if (FromSuper) {
5417 if (auto FromSuperOrErr = import(FromSuper))
5418 FromSuper = *FromSuperOrErr;
5419 else
5420 return FromSuperOrErr.takeError();
5421 }
5422
5423 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5424 if ((bool)FromSuper != (bool)ToSuper ||
5425 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5426 Importer.ToDiag(To->getLocation(),
5427 diag::warn_odr_objc_superclass_inconsistent)
5428 << To->getDeclName();
5429 if (ToSuper)
5430 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5431 << To->getSuperClass()->getDeclName();
5432 else
5433 Importer.ToDiag(To->getLocation(),
5434 diag::note_odr_objc_missing_superclass);
5435 if (From->getSuperClass())
5436 Importer.FromDiag(From->getSuperClassLoc(),
5437 diag::note_odr_objc_superclass)
5438 << From->getSuperClass()->getDeclName();
5439 else
5440 Importer.FromDiag(From->getLocation(),
5441 diag::note_odr_objc_missing_superclass);
5442 }
5443
5445 if (Error Err = ImportDeclContext(From))
5446 return Err;
5447 return Error::success();
5448 }
5449
5450 // Start the definition.
5451 To->startDefinition();
5452
5453 // If this class has a superclass, import it.
5454 if (From->getSuperClass()) {
5455 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5456 To->setSuperClass(*SuperTInfoOrErr);
5457 else
5458 return SuperTInfoOrErr.takeError();
5459 }
5460
5461 // Import protocols
5463 SmallVector<SourceLocation, 4> ProtocolLocs;
5465 From->protocol_loc_begin();
5466
5468 FromProtoEnd = From->protocol_end();
5469 FromProto != FromProtoEnd;
5470 ++FromProto, ++FromProtoLoc) {
5471 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5472 Protocols.push_back(*ToProtoOrErr);
5473 else
5474 return ToProtoOrErr.takeError();
5475
5476 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5477 ProtocolLocs.push_back(*ToProtoLocOrErr);
5478 else
5479 return ToProtoLocOrErr.takeError();
5480
5481 }
5482
5483 // FIXME: If we're merging, make sure that the protocol list is the same.
5484 To->setProtocolList(Protocols.data(), Protocols.size(),
5485 ProtocolLocs.data(), Importer.getToContext());
5486
5487 // Import categories. When the categories themselves are imported, they'll
5488 // hook themselves into this interface.
5489 for (auto *Cat : From->known_categories()) {
5490 auto ToCatOrErr = import(Cat);
5491 if (!ToCatOrErr)
5492 return ToCatOrErr.takeError();
5493 }
5494
5495 // If we have an @implementation, import it as well.
5496 if (From->getImplementation()) {
5497 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5498 import(From->getImplementation()))
5499 To->setImplementation(*ToImplOrErr);
5500 else
5501 return ToImplOrErr.takeError();
5502 }
5503
5504 // Import all of the members of this class.
5505 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5506 return Err;
5507
5508 return Error::success();
5509}
5510
5513 if (!list)
5514 return nullptr;
5515
5517 for (auto *fromTypeParam : *list) {
5518 if (auto toTypeParamOrErr = import(fromTypeParam))
5519 toTypeParams.push_back(*toTypeParamOrErr);
5520 else
5521 return toTypeParamOrErr.takeError();
5522 }
5523
5524 auto LAngleLocOrErr = import(list->getLAngleLoc());
5525 if (!LAngleLocOrErr)
5526 return LAngleLocOrErr.takeError();
5527
5528 auto RAngleLocOrErr = import(list->getRAngleLoc());
5529 if (!RAngleLocOrErr)
5530 return RAngleLocOrErr.takeError();
5531
5532 return ObjCTypeParamList::create(Importer.getToContext(),
5533 *LAngleLocOrErr,
5534 toTypeParams,
5535 *RAngleLocOrErr);
5536}
5537
5539 // If this class has a definition in the translation unit we're coming from,
5540 // but this particular declaration is not that definition, import the
5541 // definition and map to that.
5543 if (Definition && Definition != D) {
5544 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5545 return Importer.MapImported(D, *ImportedDefOrErr);
5546 else
5547 return ImportedDefOrErr.takeError();
5548 }
5549
5550 // Import the major distinguishing characteristics of an @interface.
5551 DeclContext *DC, *LexicalDC;
5552 DeclarationName Name;
5553 SourceLocation Loc;
5554 NamedDecl *ToD;
5555 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5556 return std::move(Err);
5557 if (ToD)
5558 return ToD;
5559
5560 // Look for an existing interface with the same name.
5561 ObjCInterfaceDecl *MergeWithIface = nullptr;
5562 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5563 for (auto *FoundDecl : FoundDecls) {
5565 continue;
5566
5567 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5568 break;
5569 }
5570
5571 // Create an interface declaration, if one does not already exist.
5572 ObjCInterfaceDecl *ToIface = MergeWithIface;
5573 if (!ToIface) {
5574 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5575 if (!AtBeginLocOrErr)
5576 return AtBeginLocOrErr.takeError();
5577
5578 if (GetImportedOrCreateDecl(
5579 ToIface, D, Importer.getToContext(), DC,
5580 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5581 /*TypeParamList=*/nullptr,
5582 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5583 return ToIface;
5584 ToIface->setLexicalDeclContext(LexicalDC);
5585 LexicalDC->addDeclInternal(ToIface);
5586 }
5587 Importer.MapImported(D, ToIface);
5588 // Import the type parameter list after MapImported, to avoid
5589 // loops when bringing in their DeclContext.
5590 if (auto ToPListOrErr =
5592 ToIface->setTypeParamList(*ToPListOrErr);
5593 else
5594 return ToPListOrErr.takeError();
5595
5597 if (Error Err = ImportDefinition(D, ToIface))
5598 return std::move(Err);
5599
5600 return ToIface;
5601}
5602
5606 if (Error Err = importInto(Category, D->getCategoryDecl()))
5607 return std::move(Err);
5608
5609 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5610 if (!ToImpl) {
5611 DeclContext *DC, *LexicalDC;
5612 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5613 return std::move(Err);
5614
5615 Error Err = Error::success();
5616 auto ToLocation = importChecked(Err, D->getLocation());
5617 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5618 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5619 if (Err)
5620 return std::move(Err);
5621
5622 if (GetImportedOrCreateDecl(
5623 ToImpl, D, Importer.getToContext(), DC,
5624 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5625 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5626 return ToImpl;
5627
5628 ToImpl->setLexicalDeclContext(LexicalDC);
5629 LexicalDC->addDeclInternal(ToImpl);
5630 Category->setImplementation(ToImpl);
5631 }
5632
5633 Importer.MapImported(D, ToImpl);
5634 if (Error Err = ImportDeclContext(D))
5635 return std::move(Err);
5636
5637 return ToImpl;
5638}
5639
5642 // Find the corresponding interface.
5643 ObjCInterfaceDecl *Iface;
5644 if (Error Err = importInto(Iface, D->getClassInterface()))
5645 return std::move(Err);
5646
5647 // Import the superclass, if any.
5648 ObjCInterfaceDecl *Super;
5649 if (Error Err = importInto(Super, D->getSuperClass()))
5650 return std::move(Err);
5651
5653 if (!Impl) {
5654 // We haven't imported an implementation yet. Create a new @implementation
5655 // now.
5656 DeclContext *DC, *LexicalDC;
5657 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5658 return std::move(Err);
5659
5660 Error Err = Error::success();
5661 auto ToLocation = importChecked(Err, D->getLocation());
5662 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5663 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5664 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5665 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5666 if (Err)
5667 return std::move(Err);
5668
5669 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5670 DC, Iface, Super,
5671 ToLocation,
5672 ToAtStartLoc,
5673 ToSuperClassLoc,
5674 ToIvarLBraceLoc,
5675 ToIvarRBraceLoc))
5676 return Impl;
5677
5678 Impl->setLexicalDeclContext(LexicalDC);
5679
5680 // Associate the implementation with the class it implements.
5681 Iface->setImplementation(Impl);
5682 Importer.MapImported(D, Iface->getImplementation());
5683 } else {
5684 Importer.MapImported(D, Iface->getImplementation());
5685
5686 // Verify that the existing @implementation has the same superclass.
5687 if ((Super && !Impl->getSuperClass()) ||
5688 (!Super && Impl->getSuperClass()) ||
5689 (Super && Impl->getSuperClass() &&
5691 Impl->getSuperClass()))) {
5692 Importer.ToDiag(Impl->getLocation(),
5693 diag::warn_odr_objc_superclass_inconsistent)
5694 << Iface->getDeclName();
5695 // FIXME: It would be nice to have the location of the superclass
5696 // below.
5697 if (Impl->getSuperClass())
5698 Importer.ToDiag(Impl->getLocation(),
5699 diag::note_odr_objc_superclass)
5700 << Impl->getSuperClass()->getDeclName();
5701 else
5702 Importer.ToDiag(Impl->getLocation(),
5703 diag::note_odr_objc_missing_superclass);
5704 if (D->getSuperClass())
5705 Importer.FromDiag(D->getLocation(),
5706 diag::note_odr_objc_superclass)
5707 << D->getSuperClass()->getDeclName();
5708 else
5709 Importer.FromDiag(D->getLocation(),
5710 diag::note_odr_objc_missing_superclass);
5711
5712 return make_error<ASTImportError>(ASTImportError::NameConflict);
5713 }
5714 }
5715
5716 // Import all of the members of this @implementation.
5717 if (Error Err = ImportDeclContext(D))
5718 return std::move(Err);
5719
5720 return Impl;
5721}
5722
5724 // Import the major distinguishing characteristics of an @property.
5725 DeclContext *DC, *LexicalDC;
5726 DeclarationName Name;
5727 SourceLocation Loc;
5728 NamedDecl *ToD;
5729 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5730 return std::move(Err);
5731 if (ToD)
5732 return ToD;
5733
5734 // Check whether we have already imported this property.
5735 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5736 for (auto *FoundDecl : FoundDecls) {
5737 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5738 // Instance and class properties can share the same name but are different
5739 // declarations.
5740 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5741 continue;
5742
5743 // Check property types.
5744 if (!Importer.IsStructurallyEquivalent(D->getType(),
5745 FoundProp->getType())) {
5746 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5747 << Name << D->getType() << FoundProp->getType();
5748 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5749 << FoundProp->getType();
5750
5751 return make_error<ASTImportError>(ASTImportError::NameConflict);
5752 }
5753
5754 // FIXME: Check property attributes, getters, setters, etc.?
5755
5756 // Consider these properties to be equivalent.
5757 Importer.MapImported(D, FoundProp);
5758 return FoundProp;
5759 }
5760 }
5761
5762 Error Err = Error::success();
5763 auto ToType = importChecked(Err, D->getType());
5764 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5765 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5766 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5767 if (Err)
5768 return std::move(Err);
5769
5770 // Create the new property.
5771 ObjCPropertyDecl *ToProperty;
5772 if (GetImportedOrCreateDecl(
5773 ToProperty, D, Importer.getToContext(), DC, Loc,
5774 Name.getAsIdentifierInfo(), ToAtLoc,
5775 ToLParenLoc, ToType,
5776 ToTypeSourceInfo, D->getPropertyImplementation()))
5777 return ToProperty;
5778
5779 auto ToGetterName = importChecked(Err, D->getGetterName());
5780 auto ToSetterName = importChecked(Err, D->getSetterName());
5781 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5782 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5783 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5784 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5785 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5786 if (Err)
5787 return std::move(Err);
5788
5789 ToProperty->setLexicalDeclContext(LexicalDC);
5790 LexicalDC->addDeclInternal(ToProperty);
5791
5795 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5796 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5797 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5798 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5799 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5800 return ToProperty;
5801}
5802
5806 if (Error Err = importInto(Property, D->getPropertyDecl()))
5807 return std::move(Err);
5808
5809 DeclContext *DC, *LexicalDC;
5810 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5811 return std::move(Err);
5812
5813 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5814
5815 // Import the ivar (for an @synthesize).
5816 ObjCIvarDecl *Ivar = nullptr;
5817 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5818 return std::move(Err);
5819
5820 ObjCPropertyImplDecl *ToImpl
5821 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5822 Property->getQueryKind());
5823 if (!ToImpl) {
5824
5825 Error Err = Error::success();
5826 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5827 auto ToLocation = importChecked(Err, D->getLocation());
5828 auto ToPropertyIvarDeclLoc =
5830 if (Err)
5831 return std::move(Err);
5832
5833 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5834 ToBeginLoc,
5835 ToLocation, Property,
5836 D->getPropertyImplementation(), Ivar,
5837 ToPropertyIvarDeclLoc))
5838 return ToImpl;
5839
5840 ToImpl->setLexicalDeclContext(LexicalDC);
5841 LexicalDC->addDeclInternal(ToImpl);
5842 } else {
5843 // Check that we have the same kind of property implementation (@synthesize
5844 // vs. @dynamic).
5846 Importer.ToDiag(ToImpl->getLocation(),
5847 diag::warn_odr_objc_property_impl_kind_inconsistent)
5848 << Property->getDeclName()
5849 << (ToImpl->getPropertyImplementation()
5851 Importer.FromDiag(D->getLocation(),
5852 diag::note_odr_objc_property_impl_kind)
5853 << D->getPropertyDecl()->getDeclName()
5855
5856 return make_error<ASTImportError>(ASTImportError::NameConflict);
5857 }
5858
5859 // For @synthesize, check that we have the same
5861 Ivar != ToImpl->getPropertyIvarDecl()) {
5862 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5863 diag::warn_odr_objc_synthesize_ivar_inconsistent)
5864 << Property->getDeclName()
5865 << ToImpl->getPropertyIvarDecl()->getDeclName()
5866 << Ivar->getDeclName();
5867 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5868 diag::note_odr_objc_synthesize_ivar_here)
5870
5871 return make_error<ASTImportError>(ASTImportError::NameConflict);
5872 }
5873
5874 // Merge the existing implementation with the new implementation.
5875 Importer.MapImported(D, ToImpl);
5876 }
5877
5878 return ToImpl;
5879}
5880
5883 // For template arguments, we adopt the translation unit as our declaration
5884 // context. This context will be fixed when the actual template declaration
5885 // is created.
5886
5887 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5888 if (!BeginLocOrErr)
5889 return BeginLocOrErr.takeError();
5890
5891 ExpectedSLoc LocationOrErr = import(D->getLocation());
5892 if (!LocationOrErr)
5893 return LocationOrErr.takeError();
5894
5895 TemplateTypeParmDecl *ToD = nullptr;
5896 if (GetImportedOrCreateDecl(
5897 ToD, D, Importer.getToContext(),
5899 *BeginLocOrErr, *LocationOrErr,
5900 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
5902 D->hasTypeConstraint()))
5903 return ToD;
5904
5905 // Import the type-constraint
5906 if (const TypeConstraint *TC = D->getTypeConstraint()) {
5907
5908 Error Err = Error::success();
5909 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
5910 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
5911 if (Err)
5912 return std::move(Err);
5913
5914 ToD->setTypeConstraint(ToConceptRef, ToIDC);
5915 }
5916
5917 if (D->hasDefaultArgument()) {
5918 Expected<TypeSourceInfo *> ToDefaultArgOrErr =
5919 import(D->getDefaultArgumentInfo());
5920 if (!ToDefaultArgOrErr)
5921 return ToDefaultArgOrErr.takeError();
5922 ToD->setDefaultArgument(*ToDefaultArgOrErr);
5923 }
5924
5925 return ToD;
5926}
5927
5930
5931 Error Err = Error::success();
5932 auto ToDeclName = importChecked(Err, D->getDeclName());
5933 auto ToLocation = importChecked(Err, D->getLocation());
5934 auto ToType = importChecked(Err, D->getType());
5935 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5936 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
5937 if (Err)
5938 return std::move(Err);
5939
5940 NonTypeTemplateParmDecl *ToD = nullptr;
5941 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
5943 ToInnerLocStart, ToLocation, D->getDepth(),
5944 D->getPosition(),
5945 ToDeclName.getAsIdentifierInfo(), ToType,
5946 D->isParameterPack(), ToTypeSourceInfo))
5947 return ToD;
5948
5949 if (D->hasDefaultArgument()) {
5950 ExpectedExpr ToDefaultArgOrErr = import(D->getDefaultArgument());
5951 if (!ToDefaultArgOrErr)
5952 return ToDefaultArgOrErr.takeError();
5953 ToD->setDefaultArgument(*ToDefaultArgOrErr);
5954 }
5955
5956 return ToD;
5957}
5958
5961 // Import the name of this declaration.
5962 auto NameOrErr = import(D->getDeclName());
5963 if (!NameOrErr)
5964 return NameOrErr.takeError();
5965
5966 // Import the location of this declaration.
5967 ExpectedSLoc LocationOrErr = import(D->getLocation());
5968 if (!LocationOrErr)
5969 return LocationOrErr.takeError();
5970
5971 // Import template parameters.
5972 auto TemplateParamsOrErr = import(D->getTemplateParameters());
5973 if (!TemplateParamsOrErr)
5974 return TemplateParamsOrErr.takeError();
5975
5976 TemplateTemplateParmDecl *ToD = nullptr;
5977 if (GetImportedOrCreateDecl(
5978 ToD, D, Importer.getToContext(),
5979 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
5980 D->getDepth(), D->getPosition(), D->isParameterPack(),
5981 (*NameOrErr).getAsIdentifierInfo(), D->wasDeclaredWithTypename(),
5982 *TemplateParamsOrErr))
5983 return ToD;
5984
5985 if (D->hasDefaultArgument()) {
5986 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
5987 import(D->getDefaultArgument());
5988 if (!ToDefaultArgOrErr)
5989 return ToDefaultArgOrErr.takeError();
5990 ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
5991 }
5992
5993 return ToD;
5994}
5995
5996// Returns the definition for a (forward) declaration of a TemplateDecl, if
5997// it has any definition in the redecl chain.
5998template <typename T> static auto getTemplateDefinition(T *D) -> T * {
5999 assert(D->getTemplatedDecl() && "Should be called on templates only");
6000 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6001 if (!ToTemplatedDef)
6002 return nullptr;
6003 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6004 return cast_or_null<T>(TemplateWithDef);
6005}
6006
6008
6009 // Import the major distinguishing characteristics of this class template.
6010 DeclContext *DC, *LexicalDC;
6011 DeclarationName Name;
6012 SourceLocation Loc;
6013 NamedDecl *ToD;
6014 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6015 return std::move(Err);
6016 if (ToD)
6017 return ToD;
6018
6019 // Should check if a declaration is friend in a dependent context.
6020 // Such templates are not linked together in a declaration chain.
6021 // The ASTImporter strategy is to map existing forward declarations to
6022 // imported ones only if strictly necessary, otherwise import these as new
6023 // forward declarations. In case of the "dependent friend" declarations, new
6024 // declarations are created, but not linked in a declaration chain.
6025 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6026 return TD->getFriendObjectKind() != Decl::FOK_None &&
6028 };
6029 bool DependentFriend = IsDependentFriend(D);
6030
6031 ClassTemplateDecl *FoundByLookup = nullptr;
6032
6033 // We may already have a template of the same name; try to find and match it.
6034 if (!DC->isFunctionOrMethod()) {
6035 SmallVector<NamedDecl *, 4> ConflictingDecls;
6036 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6037 for (auto *FoundDecl : FoundDecls) {
6040 continue;
6041
6042 Decl *Found = FoundDecl;
6043 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found);
6044 if (FoundTemplate) {
6045 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6046 continue;
6047
6048 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
6049 bool IgnoreTemplateParmDepth =
6050 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6052 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6053 IgnoreTemplateParmDepth)) {
6054 if (DependentFriend || IsDependentFriend(FoundTemplate))
6055 continue;
6056
6057 ClassTemplateDecl *TemplateWithDef =
6058 getTemplateDefinition(FoundTemplate);
6059 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6060 return Importer.MapImported(D, TemplateWithDef);
6061 if (!FoundByLookup)
6062 FoundByLookup = FoundTemplate;
6063 // Search in all matches because there may be multiple decl chains,
6064 // see ASTTests test ImportExistingFriendClassTemplateDef.
6065 continue;
6066 }
6067 ConflictingDecls.push_back(FoundDecl);
6068 }
6069 }
6070
6071 if (!ConflictingDecls.empty()) {
6072 ExpectedName NameOrErr = Importer.HandleNameConflict(
6073 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6074 ConflictingDecls.size());
6075 if (NameOrErr)
6076 Name = NameOrErr.get();
6077 else
6078 return NameOrErr.takeError();
6079 }
6080 }
6081
6082 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6083
6084 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6085 if (!TemplateParamsOrErr)
6086 return TemplateParamsOrErr.takeError();
6087
6088 // Create the declaration that is being templated.
6089 CXXRecordDecl *ToTemplated;
6090 if (Error Err = importInto(ToTemplated, FromTemplated))
6091 return std::move(Err);
6092
6093 // Create the class template declaration itself.
6095 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6096 *TemplateParamsOrErr, ToTemplated))
6097 return D2;
6098
6099 ToTemplated->setDescribedClassTemplate(D2);
6100
6101 D2->setAccess(D->getAccess());
6102 D2->setLexicalDeclContext(LexicalDC);
6103
6104 addDeclToContexts(D, D2);
6105 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6106
6107 if (FoundByLookup) {
6108 auto *Recent =
6109 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6110
6111 // It is possible that during the import of the class template definition
6112 // we start the import of a fwd friend decl of the very same class template
6113 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6114 // had been created earlier and by that time the lookup could not find
6115 // anything existing, so it has no previous decl. Later, (still during the
6116 // import of the fwd friend decl) we start to import the definition again
6117 // and this time the lookup finds the previous fwd friend class template.
6118 // In this case we must set up the previous decl for the templated decl.
6119 if (!ToTemplated->getPreviousDecl()) {
6120 assert(FoundByLookup->getTemplatedDecl() &&
6121 "Found decl must have its templated decl set");
6122 CXXRecordDecl *PrevTemplated =
6123 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6124 if (ToTemplated != PrevTemplated)
6125 ToTemplated->setPreviousDecl(PrevTemplated);
6126 }
6127
6128 D2->setPreviousDecl(Recent);
6129 }
6130
6131 return D2;
6132}
6133
6136 ClassTemplateDecl *ClassTemplate;
6137 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6138 return std::move(Err);
6139
6140 // Import the context of this declaration.
6141 DeclContext *DC, *LexicalDC;
6142 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6143 return std::move(Err);
6144
6145 // Import template arguments.
6147 if (Error Err =
6148 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6149 return std::move(Err);
6150 // Try to find an existing specialization with these template arguments and
6151 // template parameter list.
6152 void *InsertPos = nullptr;
6153 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6155 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6156
6157 // Import template parameters.
6158 TemplateParameterList *ToTPList = nullptr;
6159
6160 if (PartialSpec) {
6161 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6162 if (!ToTPListOrErr)
6163 return ToTPListOrErr.takeError();
6164 ToTPList = *ToTPListOrErr;
6165 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6166 *ToTPListOrErr,
6167 InsertPos);
6168 } else
6169 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6170
6171 if (PrevDecl) {
6172 if (IsStructuralMatch(D, PrevDecl)) {
6173 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6174 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6175 Importer.MapImported(D, PrevDefinition);
6176 // Import those default field initializers which have been
6177 // instantiated in the "From" context, but not in the "To" context.
6178 for (auto *FromField : D->fields()) {
6179 auto ToOrErr = import(FromField);
6180 if (!ToOrErr)
6181 return ToOrErr.takeError();
6182 }
6183
6184 // Import those methods which have been instantiated in the
6185 // "From" context, but not in the "To" context.
6186 for (CXXMethodDecl *FromM : D->methods()) {
6187 auto ToOrErr = import(FromM);
6188 if (!ToOrErr)
6189 return ToOrErr.takeError();
6190 }
6191
6192 // TODO Import instantiated default arguments.
6193 // TODO Import instantiated exception specifications.
6194 //
6195 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6196 // what else could be fused during an AST merge.
6197 return PrevDefinition;
6198 }
6199 } else { // ODR violation.
6200 // FIXME HandleNameConflict
6201 return make_error<ASTImportError>(ASTImportError::NameConflict);
6202 }
6203 }
6204
6205 // Import the location of this declaration.
6206 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6207 if (!BeginLocOrErr)
6208 return BeginLocOrErr.takeError();
6209 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6210 if (!IdLocOrErr)
6211 return IdLocOrErr.takeError();
6212
6213 // Create the specialization.
6214 ClassTemplateSpecializationDecl *D2 = nullptr;
6215 if (PartialSpec) {
6216 // Import TemplateArgumentListInfo.
6217 TemplateArgumentListInfo ToTAInfo;
6218 const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten();
6219 if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo))
6220 return std::move(Err);
6221
6222 QualType CanonInjType;
6223 if (Error Err = importInto(
6224 CanonInjType, PartialSpec->getInjectedSpecializationType()))
6225 return std::move(Err);
6226 CanonInjType = CanonInjType.getCanonicalType();
6227
6228 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6229 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6230 *IdLocOrErr, ToTPList, ClassTemplate,
6231 llvm::ArrayRef(TemplateArgs.data(), TemplateArgs.size()), ToTAInfo,
6232 CanonInjType,
6233 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6234 return D2;
6235
6236 // Update InsertPos, because preceding import calls may have invalidated
6237 // it by adding new specializations.
6238 auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6239 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6240 InsertPos))
6241 // Add this partial specialization to the class template.
6242 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6244 import(PartialSpec->getInstantiatedFromMember()))
6245 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6246 else
6247 return ToInstOrErr.takeError();
6248
6249 updateLookupTableForTemplateParameters(*ToTPList);
6250 } else { // Not a partial specialization.
6251 if (GetImportedOrCreateDecl(
6252 D2, D, Importer.getToContext(), D->getTagKind(), DC,
6253 *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
6254 PrevDecl))
6255 return D2;
6256
6257 // Update InsertPos, because preceding import calls may have invalidated
6258 // it by adding new specializations.
6259 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6260 // Add this specialization to the class template.
6261 ClassTemplate->AddSpecialization(D2, InsertPos);
6262 }
6263
6265
6266 // Set the context of this specialization/instantiation.
6267 D2->setLexicalDeclContext(LexicalDC);
6268
6269 // Add to the DC only if it was an explicit specialization/instantiation.
6271 LexicalDC->addDeclInternal(D2);
6272 }
6273
6274 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6275 D2->setBraceRange(*BraceRangeOrErr);
6276 else
6277 return BraceRangeOrErr.takeError();
6278
6279 // Import the qualifier, if any.
6280 if (auto LocOrErr = import(D->getQualifierLoc()))
6281 D2->setQualifierInfo(*LocOrErr);
6282 else
6283 return LocOrErr.takeError();
6284
6285 if (auto *TSI = D->getTypeAsWritten()) {
6286 if (auto TInfoOrErr = import(TSI))
6287 D2->setTypeAsWritten(*TInfoOrErr);
6288 else
6289 return TInfoOrErr.takeError();
6290
6291 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6292 D2->setTemplateKeywordLoc(*LocOrErr);
6293 else
6294 return LocOrErr.takeError();
6295
6296 if (auto LocOrErr = import(D->getExternLoc()))
6297 D2->setExternLoc(*LocOrErr);
6298 else
6299 return LocOrErr.takeError();
6300 }
6301
6302 if (D->getPointOfInstantiation().isValid()) {
6303 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6304 D2->setPointOfInstantiation(*POIOrErr);
6305 else
6306 return POIOrErr.takeError();
6307 }
6308
6310
6311 if (auto P = D->getInstantiatedFrom()) {
6312 if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
6313 if (auto CTDorErr = import(CTD))
6314 D2->setInstantiationOf(*CTDorErr);
6315 } else {
6316 auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6317 auto CTPSDOrErr = import(CTPSD);
6318 if (!CTPSDOrErr)
6319 return CTPSDOrErr.takeError();
6321 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6322 for (unsigned I = 0; I < DArgs.size(); ++I) {
6323 const TemplateArgument &DArg = DArgs[I];
6324 if (auto ArgOrErr = import(DArg))
6325 D2ArgsVec[I] = *ArgOrErr;
6326 else
6327 return ArgOrErr.takeError();
6328 }
6330 *CTPSDOrErr,
6331 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6332 }
6333 }
6334
6335 if (D->isCompleteDefinition())
6336 if (Error Err = ImportDefinition(D, D2))
6337 return std::move(Err);
6338
6339 return D2;
6340}
6341
6343 // Import the major distinguishing characteristics of this variable template.
6344 DeclContext *DC, *LexicalDC;
6345 DeclarationName Name;
6346 SourceLocation Loc;
6347 NamedDecl *ToD;
6348 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6349 return std::move(Err);
6350 if (ToD)
6351 return ToD;
6352
6353 // We may already have a template of the same name; try to find and match it.
6354 assert(!DC->isFunctionOrMethod() &&
6355 "Variable templates cannot be declared at function scope");
6356
6357 SmallVector<NamedDecl *, 4> ConflictingDecls;
6358 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6359 VarTemplateDecl *FoundByLookup = nullptr;
6360 for (auto *FoundDecl : FoundDecls) {
6362 continue;
6363
6364 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6365 // Use the templated decl, some linkage flags are set only there.
6366 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6367 D->getTemplatedDecl()))
6368 continue;
6369 if (IsStructuralMatch(D, FoundTemplate)) {
6370 // FIXME Check for ODR error if the two definitions have
6371 // different initializers?
6372 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6373 if (D->getDeclContext()->isRecord()) {
6374 assert(FoundTemplate->getDeclContext()->isRecord() &&
6375 "Member variable template imported as non-member, "
6376 "inconsistent imported AST?");
6377 if (FoundDef)
6378 return Importer.MapImported(D, FoundDef);
6380 return Importer.MapImported(D, FoundTemplate);
6381 } else {
6382 if (FoundDef && D->isThisDeclarationADefinition())
6383 return Importer.MapImported(D, FoundDef);
6384 }
6385 FoundByLookup = FoundTemplate;
6386 break;
6387 }
6388 ConflictingDecls.push_back(FoundDecl);
6389 }
6390 }
6391
6392 if (!ConflictingDecls.empty()) {
6393 ExpectedName NameOrErr = Importer.HandleNameConflict(
6394 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6395 ConflictingDecls.size());
6396 if (NameOrErr)
6397 Name = NameOrErr.get();
6398 else
6399 return NameOrErr.takeError();
6400 }
6401
6402 VarDecl *DTemplated = D->getTemplatedDecl();
6403
6404 // Import the type.
6405 // FIXME: Value not used?
6406 ExpectedType TypeOrErr = import(DTemplated->getType());
6407 if (!TypeOrErr)
6408 return TypeOrErr.takeError();
6409
6410 // Create the declaration that is being templated.
6411 VarDecl *ToTemplated;
6412 if (Error Err = importInto(ToTemplated, DTemplated))
6413 return std::move(Err);
6414
6415 // Create the variable template declaration itself.
6416 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6417 if (!TemplateParamsOrErr)
6418 return TemplateParamsOrErr.takeError();
6419
6420 VarTemplateDecl *ToVarTD;
6421 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6422 Name, *TemplateParamsOrErr, ToTemplated))
6423 return ToVarTD;
6424
6425 ToTemplated->setDescribedVarTemplate(ToVarTD);
6426
6427 ToVarTD->setAccess(D->getAccess());
6428 ToVarTD->setLexicalDeclContext(LexicalDC);
6429 LexicalDC->addDeclInternal(ToVarTD);
6430 if (DC != Importer.getToContext().getTranslationUnitDecl())
6431 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6432
6433 if (FoundByLookup) {
6434 auto *Recent =
6435 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6436 if (!ToTemplated->getPreviousDecl()) {
6437 auto *PrevTemplated =
6438 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6439 if (ToTemplated != PrevTemplated)
6440 ToTemplated->setPreviousDecl(PrevTemplated);
6441 }
6442 ToVarTD->setPreviousDecl(Recent);
6443 }
6444
6445 return ToVarTD;
6446}
6447
6450 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6451 // in an analog way (but specialized for this case).
6452
6454 auto RedeclIt = Redecls.begin();
6455 // Import the first part of the decl chain. I.e. import all previous
6456 // declarations starting from the canonical decl.
6457 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6458 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6459 if (!RedeclOrErr)
6460 return RedeclOrErr.takeError();
6461 }
6462 assert(*RedeclIt == D);
6463
6464 VarTemplateDecl *VarTemplate = nullptr;
6465 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6466 return std::move(Err);
6467
6468 // Import the context of this declaration.
6469 DeclContext *DC, *LexicalDC;
6470 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6471 return std::move(Err);
6472
6473 // Import the location of this declaration.
6474 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6475 if (!BeginLocOrErr)
6476 return BeginLocOrErr.takeError();
6477
6478 auto IdLocOrErr = import(D->getLocation());
6479 if (!IdLocOrErr)
6480 return IdLocOrErr.takeError();
6481
6482 // Import template arguments.
6484 if (Error Err =
6485 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6486 return std::move(Err);
6487
6488 // Try to find an existing specialization with these template arguments.
6489 void *InsertPos = nullptr;
6490 VarTemplateSpecializationDecl *FoundSpecialization =
6491 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6492 if (FoundSpecialization) {
6493 if (IsStructuralMatch(D, FoundSpecialization)) {
6494 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6495 if (D->getDeclContext()->isRecord()) {
6496 // In a record, it is allowed only to have one optional declaration and
6497 // one definition of the (static or constexpr) variable template.
6498 assert(
6499 FoundSpecialization->getDeclContext()->isRecord() &&
6500 "Member variable template specialization imported as non-member, "
6501 "inconsistent imported AST?");
6502 if (FoundDef)
6503 return Importer.MapImported(D, FoundDef);
6505 return Importer.MapImported(D, FoundSpecialization);
6506 } else {
6507 // If definition is imported and there is already one, map to it.
6508 // Otherwise create a new variable and link it to the existing.
6509 if (FoundDef && D->isThisDeclarationADefinition())
6510 return Importer.MapImported(D, FoundDef);
6511 }
6512 } else {
6513 return make_error<ASTImportError>(ASTImportError::NameConflict);
6514 }
6515 }
6516
6517 VarTemplateSpecializationDecl *D2 = nullptr;
6518
6519 TemplateArgumentListInfo ToTAInfo;
6520 if (const ASTTemplateArgumentListInfo *Args = D->getTemplateArgsInfo()) {
6521 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6522 return std::move(Err);
6523 }
6524
6525 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6526 // Create a new specialization.
6527 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6528 // Import TemplateArgumentListInfo
6529 TemplateArgumentListInfo ArgInfos;
6530 const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten();
6531 // NOTE: FromTAArgsAsWritten and template parameter list are non-null.
6532 if (Error Err =
6533 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos))
6534 return std::move(Err);
6535
6536 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6537 if (!ToTPListOrErr)
6538 return ToTPListOrErr.takeError();
6539
6540 PartVarSpecDecl *ToPartial;
6541 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6542 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6543 VarTemplate, QualType(), nullptr,
6544 D->getStorageClass(), TemplateArgs, ArgInfos))
6545 return ToPartial;
6546
6547 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6548 import(FromPartial->getInstantiatedFromMember()))
6549 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6550 else
6551 return ToInstOrErr.takeError();
6552
6553 if (FromPartial->isMemberSpecialization())
6554 ToPartial->setMemberSpecialization();
6555
6556 D2 = ToPartial;
6557
6558 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6559 // to adopt template parameters.
6560 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6561 } else { // Full specialization
6562 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6563 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6564 QualType(), nullptr, D->getStorageClass(),
6565 TemplateArgs))
6566 return D2;
6567 }
6568
6569 QualType T;
6570 if (Error Err = importInto(T, D->getType()))
6571 return std::move(Err);
6572 D2->setType(T);
6573
6574 auto TInfoOrErr = import(D->getTypeSourceInfo());
6575 if (!TInfoOrErr)
6576 return TInfoOrErr.takeError();
6577 D2->setTypeSourceInfo(*TInfoOrErr);
6578
6579 if (D->getPointOfInstantiation().isValid()) {
6580 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6581 D2->setPointOfInstantiation(*POIOrErr);
6582 else
6583 return POIOrErr.takeError();
6584 }
6585
6587 D2->setTemplateArgsInfo(ToTAInfo);
6588
6589 if (auto LocOrErr = import(D->getQualifierLoc()))
6590 D2->setQualifierInfo(*LocOrErr);
6591 else
6592 return LocOrErr.takeError();
6593
6594 if (D->isConstexpr())
6595 D2->setConstexpr(true);
6596
6597 D2->setAccess(D->getAccess());
6598
6599 if (Error Err = ImportInitializer(D, D2))
6600 return std::move(Err);
6601
6602 if (FoundSpecialization)
6603 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6604
6605 VarTemplate->AddSpecialization(D2, InsertPos);
6606
6607 addDeclToContexts(D, D2);
6608
6609 // Import the rest of the chain. I.e. import all subsequent declarations.
6610 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6611 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6612 if (!RedeclOrErr)
6613 return RedeclOrErr.takeError();
6614 }
6615
6616 return D2;
6617}
6618
6621 DeclContext *DC, *LexicalDC;
6622 DeclarationName Name;
6623 SourceLocation Loc;
6624 NamedDecl *ToD;
6625
6626 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6627 return std::move(Err);
6628
6629 if (ToD)
6630 return ToD;
6631
6632 const FunctionTemplateDecl *FoundByLookup = nullptr;
6633
6634 // Try to find a function in our own ("to") context with the same name, same
6635 // type, and in the same context as the function we're importing.
6636 // FIXME Split this into a separate function.
6637 if (!LexicalDC->isFunctionOrMethod()) {
6639 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6640 for (auto *FoundDecl : FoundDecls) {
6641 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6642 continue;
6643
6644 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6645 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6646 continue;
6647 if (IsStructuralMatch(D, FoundTemplate)) {
6648 FunctionTemplateDecl *TemplateWithDef =
6649 getTemplateDefinition(FoundTemplate);
6650 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6651 return Importer.MapImported(D, TemplateWithDef);
6652
6653 FoundByLookup = FoundTemplate;
6654 break;
6655 // TODO: handle conflicting names
6656 }
6657 }
6658 }
6659 }
6660
6661 auto ParamsOrErr = import(D->getTemplateParameters());
6662 if (!ParamsOrErr)
6663 return ParamsOrErr.takeError();
6664 TemplateParameterList *Params = *ParamsOrErr;
6665
6666 FunctionDecl *TemplatedFD;
6667 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6668 return std::move(Err);
6669
6670 // At creation of the template the template parameters are "adopted"
6671 // (DeclContext is changed). After this possible change the lookup table
6672 // must be updated.
6673 // At deduction guides the DeclContext of the template parameters may be
6674 // different from what we would expect, it may be the class template, or a
6675 // probably different CXXDeductionGuideDecl. This may come from the fact that
6676 // the template parameter objects may be shared between deduction guides or
6677 // the class template, and at creation of multiple FunctionTemplateDecl
6678 // objects (for deduction guides) the same parameters are re-used. The
6679 // "adoption" happens multiple times with different parent, even recursively
6680 // for TemplateTemplateParmDecl. The same happens at import when the
6681 // FunctionTemplateDecl objects are created, but in different order.
6682 // In this way the DeclContext of these template parameters is not necessarily
6683 // the same as in the "from" context.
6685 OldParamDC.reserve(Params->size());
6686 llvm::transform(*Params, std::back_inserter(OldParamDC),
6687 [](NamedDecl *ND) { return ND->getDeclContext(); });
6688
6689 FunctionTemplateDecl *ToFunc;
6690 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6691 Params, TemplatedFD))
6692 return ToFunc;
6693
6694 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6695
6696 ToFunc->setAccess(D->getAccess());
6697 ToFunc->setLexicalDeclContext(LexicalDC);
6698 addDeclToContexts(D, ToFunc);
6699
6700 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6701 if (LT && !OldParamDC.empty()) {
6702 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6703 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6704 }
6705
6706 if (FoundByLookup) {
6707 auto *Recent =
6708 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6709 if (!TemplatedFD->getPreviousDecl()) {
6710 assert(FoundByLookup->getTemplatedDecl() &&
6711 "Found decl must have its templated decl set");
6712 auto *PrevTemplated =
6713 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6714 if (TemplatedFD != PrevTemplated)
6715 TemplatedFD->setPreviousDecl(PrevTemplated);
6716 }
6717 ToFunc->setPreviousDecl(Recent);
6718 }
6719
6720 return ToFunc;
6721}
6722
6723//----------------------------------------------------------------------------
6724// Import Statements
6725//----------------------------------------------------------------------------
6726
6728 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
6729 << S->getStmtClassName();
6730 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6731}
6732
6733
6735 if (Importer.returnWithErrorInTest())
6736 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6738 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6739 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
6740 // ToII is nullptr when no symbolic name is given for output operand
6741 // see ParseStmtAsm::ParseAsmOperandsOpt
6742 Names.push_back(ToII);
6743 }
6744
6745 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6746 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
6747 // ToII is nullptr when no symbolic name is given for input operand
6748 // see ParseStmtAsm::ParseAsmOperandsOpt
6749 Names.push_back(ToII);
6750 }
6751
6753 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
6754 if (auto ClobberOrErr = import(S->getClobberStringLiteral(I)))
6755 Clobbers.push_back(*ClobberOrErr);
6756 else
6757 return ClobberOrErr.takeError();
6758
6759 }
6760
6762 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6763 if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I)))
6764 Constraints.push_back(*OutputOrErr);
6765 else
6766 return OutputOrErr.takeError();
6767 }
6768
6769 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6770 if (auto InputOrErr = import(S->getInputConstraintLiteral(I)))
6771 Constraints.push_back(*InputOrErr);
6772 else
6773 return InputOrErr.takeError();
6774 }
6775
6776 SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() +
6777 S->getNumLabels());
6778 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
6779 return std::move(Err);
6780
6781 if (Error Err =
6782 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
6783 return std::move(Err);
6784
6785 if (Error Err = ImportArrayChecked(
6786 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
6787 return std::move(Err);
6788
6789 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
6790 if (!AsmLocOrErr)
6791 return AsmLocOrErr.takeError();
6792 auto AsmStrOrErr = import(S->getAsmString());
6793 if (!AsmStrOrErr)
6794 return AsmStrOrErr.takeError();
6795 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
6796 if (!RParenLocOrErr)
6797 return RParenLocOrErr.takeError();
6798
6799 return new (Importer.getToContext()) GCCAsmStmt(
6800 Importer.getToContext(),
6801 *AsmLocOrErr,
6802 S->isSimple(),
6803 S->isVolatile(),
6804 S->getNumOutputs(),
6805 S->getNumInputs(),
6806 Names.data(),
6807 Constraints.data(),
6808 Exprs.data(),
6809 *AsmStrOrErr,
6810 S->getNumClobbers(),
6811 Clobbers.data(),
6812 S->getNumLabels(),
6813 *RParenLocOrErr);
6814}
6815
6817
6818 Error Err = Error::success();
6819 auto ToDG = importChecked(Err, S->getDeclGroup());
6820 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
6821 auto ToEndLoc = importChecked(Err, S->getEndLoc());
6822 if (Err)
6823 return std::move(Err);
6824 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
6825}
6826
6828 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
6829 if (!ToSemiLocOrErr)
6830 return ToSemiLocOrErr.takeError();
6831 return new (Importer.getToContext()) NullStmt(
6832 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
6833}
6834
6836 SmallVector<Stmt *, 8> ToStmts(S->size());
6837
6838 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
6839 return std::move(Err);
6840
6841 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
6842 if (!ToLBracLocOrErr)
6843 return ToLBracLocOrErr.takeError();
6844
6845 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
6846 if (!ToRBracLocOrErr)
6847 return ToRBracLocOrErr.takeError();
6848
6849 FPOptionsOverride FPO =
6850 S->hasStoredFPFeatures() ? S->getStoredFPFeatures() : FPOptionsOverride();
6851 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
6852 *ToLBracLocOrErr, *ToRBracLocOrErr);
6853}
6854
6856
6857 Error Err = Error::success();
6858 auto ToLHS = importChecked(Err, S->getLHS());
6859 auto ToRHS = importChecked(Err, S->getRHS());
6860 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6861 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
6862 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
6863 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6864 if (Err)
6865 return std::move(Err);
6866
6867 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
6868 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
6869 ToStmt->setSubStmt(ToSubStmt);
6870
6871 return ToStmt;
6872}
6873
6875
6876 Error Err = Error::success();
6877 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
6878 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6879 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6880 if (Err)
6881 return std::move(Err);
6882
6883 return new (Importer.getToContext()) DefaultStmt(
6884 ToDefaultLoc, ToColonLoc, ToSubStmt);
6885}
6886
6888
6889 Error Err = Error::success();
6890 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
6891 auto ToLabelDecl = importChecked(Err, S->getDecl());
6892 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6893 if (Err)
6894 return std::move(Err);
6895
6896 return new (Importer.getToContext()) LabelStmt(
6897 ToIdentLoc, ToLabelDecl, ToSubStmt);
6898}
6899
6901 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
6902 if (!ToAttrLocOrErr)
6903 return ToAttrLocOrErr.takeError();
6904 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
6905 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
6906 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
6907 return std::move(Err);
6908 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
6909 if (!ToSubStmtOrErr)
6910 return ToSubStmtOrErr.takeError();
6911
6913 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
6914}
6915
6917
6918 Error Err = Error::success();
6919 auto ToIfLoc = importChecked(Err, S->getIfLoc());
6920 auto ToInit = importChecked(Err, S->getInit());
6921 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6922 auto ToCond = importChecked(Err, S->getCond());
6923 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6924 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6925 auto ToThen = importChecked(Err, S->getThen());
6926 auto ToElseLoc = importChecked(Err, S->getElseLoc());
6927 auto ToElse = importChecked(Err, S->getElse());
6928 if (Err)
6929 return std::move(Err);
6930
6931 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
6932 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
6933 ToRParenLoc, ToThen, ToElseLoc, ToElse);
6934}
6935
6937
6938 Error Err = Error::success();
6939 auto ToInit = importChecked(Err, S->getInit());
6940 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6941 auto ToCond = importChecked(Err, S->getCond());
6942 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6943 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6944 auto ToBody = importChecked(Err, S->getBody());
6945 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
6946 if (Err)
6947 return std::move(Err);
6948
6949 auto *ToStmt =
6950 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
6951 ToCond, ToLParenLoc, ToRParenLoc);
6952 ToStmt->setBody(ToBody);
6953 ToStmt->setSwitchLoc(ToSwitchLoc);
6954
6955 // Now we have to re-chain the cases.
6956 SwitchCase *LastChainedSwitchCase = nullptr;
6957 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
6958 SC = SC->getNextSwitchCase()) {
6959 Expected<SwitchCase *> ToSCOrErr = import(SC);
6960 if (!ToSCOrErr)
6961 return ToSCOrErr.takeError();
6962 if (LastChainedSwitchCase)
6963 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
6964 else
6965 ToStmt->setSwitchCaseList(*ToSCOrErr);
6966 LastChainedSwitchCase = *ToSCOrErr;
6967 }
6968
6969 return ToStmt;
6970}
6971
6973
6974 Error Err = Error::success();
6975 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6976 auto ToCond = importChecked(Err, S->getCond());
6977 auto ToBody = importChecked(Err, S->getBody());
6978 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
6979 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6980 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6981 if (Err)
6982 return std::move(Err);
6983
6984 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
6985 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
6986}
6987
6989
6990 Error Err = Error::success();
6991 auto ToBody = importChecked(Err, S->getBody());
6992 auto ToCond = importChecked(Err, S->getCond());
6993 auto ToDoLoc = importChecked(Err, S->getDoLoc());
6994 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
6995 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6996 if (Err)
6997 return std::move(Err);
6998
6999 return new (Importer.getToContext()) DoStmt(
7000 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7001}
7002
7004
7005 Error Err = Error::success();
7006 auto ToInit = importChecked(Err, S->getInit());
7007 auto ToCond = importChecked(Err, S->getCond());
7008 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7009 auto ToInc = importChecked(Err, S->getInc());
7010 auto ToBody = importChecked(Err, S->getBody());
7011 auto ToForLoc = importChecked(Err, S->getForLoc());
7012 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7013 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7014 if (Err)
7015 return std::move(Err);
7016
7017 return new (Importer.getToContext()) ForStmt(
7018 Importer.getToContext(),
7019 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7020 ToRParenLoc);
7021}
7022
7024
7025 Error Err = Error::success();
7026 auto ToLabel = importChecked(Err, S->getLabel());
7027 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7028 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7029 if (Err)
7030 return std::move(Err);
7031
7032 return new (Importer.getToContext()) GotoStmt(
7033 ToLabel, ToGotoLoc, ToLabelLoc);
7034}
7035
7037
7038 Error Err = Error::success();
7039 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7040 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7041 auto ToTarget = importChecked(Err, S->getTarget());
7042 if (Err)
7043 return std::move(Err);
7044
7045 return new (Importer.getToContext()) IndirectGotoStmt(
7046 ToGotoLoc, ToStarLoc, ToTarget);
7047}
7048
7050 ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc());
7051 if (!ToContinueLocOrErr)
7052 return ToContinueLocOrErr.takeError();
7053 return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr);
7054}
7055
7057 auto ToBreakLocOrErr = import(S->getBreakLoc());
7058 if (!ToBreakLocOrErr)
7059 return ToBreakLocOrErr.takeError();
7060 return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr);
7061}
7062
7064
7065 Error Err = Error::success();
7066 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7067 auto ToRetValue = importChecked(Err, S->getRetValue());
7068 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7069 if (Err)
7070 return std::move(Err);
7071
7072 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7073 ToNRVOCandidate);
7074}
7075
7077
7078 Error Err = Error::success();
7079 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7080 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7081 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7082 if (Err)
7083 return std::move(Err);
7084
7085 return new (Importer.getToContext()) CXXCatchStmt (
7086 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7087}
7088
7090 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7091 if (!ToTryLocOrErr)
7092 return ToTryLocOrErr.takeError();
7093
7094 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7095 if (!ToTryBlockOrErr)
7096 return ToTryBlockOrErr.takeError();
7097
7098 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7099 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7100 CXXCatchStmt *FromHandler = S->getHandler(HI);
7101 if (auto ToHandlerOrErr = import(FromHandler))
7102 ToHandlers[HI] = *ToHandlerOrErr;
7103 else
7104 return ToHandlerOrErr.takeError();
7105 }
7106
7107 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7108 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7109}
7110
7112
7113 Error Err = Error::success();
7114 auto ToInit = importChecked(Err, S->getInit());
7115 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7116 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7117 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7118 auto ToCond = importChecked(Err, S->getCond());
7119 auto ToInc = importChecked(Err, S->getInc());
7120 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7121 auto ToBody = importChecked(Err, S->getBody());
7122 auto ToForLoc = importChecked(Err, S->getForLoc());
7123 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7124 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7125 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7126 if (Err)
7127 return std::move(Err);
7128
7129 return new (Importer.getToContext()) CXXForRangeStmt(
7130 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7131 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7132}
7133
7136 Error Err = Error::success();
7137 auto ToElement = importChecked(Err, S->getElement());
7138 auto ToCollection = importChecked(Err, S->getCollection());
7139 auto ToBody = importChecked(Err, S->getBody());
7140 auto ToForLoc = importChecked(Err, S->getForLoc());
7141 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7142 if (Err)
7143 return std::move(Err);
7144
7145 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7146 ToCollection,
7147 ToBody,
7148 ToForLoc,
7149 ToRParenLoc);
7150}
7151
7153
7154 Error Err = Error::success();
7155 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7156 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7157 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7158 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7159 if (Err)
7160 return std::move(Err);
7161
7162 return new (Importer.getToContext()) ObjCAtCatchStmt (
7163 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7164}
7165
7167 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7168 if (!ToAtFinallyLocOrErr)
7169 return ToAtFinallyLocOrErr.takeError();
7170 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7171 if (!ToAtFinallyStmtOrErr)
7172 return ToAtFinallyStmtOrErr.takeError();
7173 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7174 *ToAtFinallyStmtOrErr);
7175}
7176
7178
7179 Error Err = Error::success();
7180 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7181 auto ToTryBody = importChecked(Err, S->getTryBody());
7182 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7183 if (Err)
7184 return std::move(Err);
7185
7186 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7187 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7188 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7189 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7190 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7191 else
7192 return ToCatchStmtOrErr.takeError();
7193 }
7194
7195 return ObjCAtTryStmt::Create(Importer.getToContext(),
7196 ToAtTryLoc, ToTryBody,
7197 ToCatchStmts.begin(), ToCatchStmts.size(),
7198 ToFinallyStmt);
7199}
7200
7203
7204 Error Err = Error::success();
7205 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7206 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7207 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7208 if (Err)
7209 return std::move(Err);
7210
7211 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7212 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7213}
7214
7216 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7217 if (!ToThrowLocOrErr)
7218 return ToThrowLocOrErr.takeError();
7219 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7220 if (!ToThrowExprOrErr)
7221 return ToThrowExprOrErr.takeError();
7222 return new (Importer.getToContext()) ObjCAtThrowStmt(
7223 *ToThrowLocOrErr, *ToThrowExprOrErr);
7224}
7225
7228 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7229 if (!ToAtLocOrErr)
7230 return ToAtLocOrErr.takeError();
7231 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7232 if (!ToSubStmtOrErr)
7233 return ToSubStmtOrErr.takeError();
7234 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7235 *ToSubStmtOrErr);
7236}
7237
7238//----------------------------------------------------------------------------
7239// Import Expressions
7240//----------------------------------------------------------------------------
7242 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7243 << E->getStmtClassName();
7244 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7245}
7246
7248 Error Err = Error::success();
7249 auto ToType = importChecked(Err, E->getType());
7250 auto BLoc = importChecked(Err, E->getBeginLoc());
7251 auto RParenLoc = importChecked(Err, E->getEndLoc());
7252 if (Err)
7253 return std::move(Err);
7254 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7255 if (!ParentContextOrErr)
7256 return ParentContextOrErr.takeError();
7257
7258 return new (Importer.getToContext())
7259 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7260 RParenLoc, *ParentContextOrErr);
7261}
7262
7264
7265 Error Err = Error::success();
7266 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7267 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7268 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7269 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7270 auto ToType = importChecked(Err, E->getType());
7271 if (Err)
7272 return std::move(Err);
7273
7274 return new (Importer.getToContext()) VAArgExpr(
7275 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7276 E->isMicrosoftABI());
7277}
7278
7280
7281 Error Err = Error::success();
7282 auto ToCond = importChecked(Err, E->getCond());
7283 auto ToLHS = importChecked(Err, E->getLHS());
7284 auto ToRHS = importChecked(Err, E->getRHS());
7285 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7286 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7287 auto ToType = importChecked(Err, E->getType());
7288 if (Err)
7289 return std::move(Err);
7290
7291 ExprValueKind VK = E->getValueKind();
7292 ExprObjectKind OK = E->getObjectKind();
7293
7294 // The value of CondIsTrue only matters if the value is not
7295 // condition-dependent.
7296 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7297
7298 return new (Importer.getToContext())
7299 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7300 ToRParenLoc, CondIsTrue);
7301}
7302
7304 Error Err = Error::success();
7305 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7306 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7307 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7308 auto ToType = importChecked(Err, E->getType());
7309 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7310 if (Err)
7311 return std::move(Err);
7312
7313 return new (Importer.getToContext())
7314 ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7315 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc);
7316}
7317
7319 Error Err = Error::success();
7320 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7321 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7322 auto ToType = importChecked(Err, E->getType());
7323 const unsigned NumSubExprs = E->getNumSubExprs();
7324
7326 llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7327 ToSubExprs.resize(NumSubExprs);
7328
7329 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7330 return std::move(Err);
7331
7332 return new (Importer.getToContext()) ShuffleVectorExpr(
7333 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7334}
7335
7337 ExpectedType TypeOrErr = import(E->getType());
7338 if (!TypeOrErr)
7339 return TypeOrErr.takeError();
7340
7341 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7342 if (!BeginLocOrErr)
7343 return BeginLocOrErr.takeError();
7344
7345 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7346}
7347
7350 Error Err = Error::success();
7351 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7352 Expr *ToControllingExpr = nullptr;
7353 TypeSourceInfo *ToControllingType = nullptr;
7354 if (E->isExprPredicate())
7355 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7356 else
7357 ToControllingType = importChecked(Err, E->getControllingType());
7358 assert((ToControllingExpr || ToControllingType) &&
7359 "Either the controlling expr or type must be nonnull");
7360 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7361 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7362 if (Err)
7363 return std::move(Err);
7364
7366 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7367 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7368 return std::move(Err);
7369
7370 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7371 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7372 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7373 return std::move(Err);
7374
7375 const ASTContext &ToCtx = Importer.getToContext();
7376 if (E->isResultDependent()) {
7377 if (ToControllingExpr) {
7379 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7380 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7382 }
7384 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7385 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7387 }
7388
7389 if (ToControllingExpr) {
7391 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7392 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7394 }
7396 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7397 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7399}
7400
7402
7403 Error Err = Error::success();
7404 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7405 auto ToType = importChecked(Err, E->getType());
7406 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7407 if (Err)
7408 return std::move(Err);
7409
7410 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7411 E->getIdentKind(), E->isTransparent(),
7412 ToFunctionName);
7413}
7414
7416
7417 Error Err = Error::success();
7418 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7419 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7420 auto ToDecl = importChecked(Err, E->getDecl());
7421 auto ToLocation = importChecked(Err, E->getLocation());
7422 auto ToType = importChecked(Err, E->getType());
7423 if (Err)
7424 return std::move(Err);
7425
7426 NamedDecl *ToFoundD = nullptr;
7427 if (E->getDecl() != E->getFoundDecl()) {
7428 auto FoundDOrErr = import(E->getFoundDecl());
7429 if (!FoundDOrErr)
7430 return FoundDOrErr.takeError();
7431 ToFoundD = *FoundDOrErr;
7432 }
7433
7434 TemplateArgumentListInfo ToTAInfo;
7435 TemplateArgumentListInfo *ToResInfo = nullptr;
7436 if (E->hasExplicitTemplateArgs()) {
7437 if (Error Err =
7439 E->template_arguments(), ToTAInfo))
7440 return std::move(Err);
7441 ToResInfo = &ToTAInfo;
7442 }
7443
7444 auto *ToE = DeclRefExpr::Create(
7445 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7446 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7447 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7448 if (E->hadMultipleCandidates())
7449 ToE->setHadMultipleCandidates(true);
7450 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7451 return ToE;
7452}
7453
7455 ExpectedType TypeOrErr = import(E->getType());
7456 if (!TypeOrErr)
7457 return TypeOrErr.takeError();
7458
7459 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7460}
7461
7463 ExpectedExpr ToInitOrErr = import(E->getInit());
7464 if (!ToInitOrErr)
7465 return ToInitOrErr.takeError();
7466
7467 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7468 if (!ToEqualOrColonLocOrErr)
7469 return ToEqualOrColonLocOrErr.takeError();
7470
7471 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7472 // List elements from the second, the first is Init itself
7473 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7474 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7475 ToIndexExprs[I - 1] = *ToArgOrErr;
7476 else
7477 return ToArgOrErr.takeError();
7478 }
7479
7480 SmallVector<Designator, 4> ToDesignators(E->size());
7481 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7482 return std::move(Err);
7483
7485 Importer.getToContext(), ToDesignators,
7486 ToIndexExprs, *ToEqualOrColonLocOrErr,
7487 E->usesGNUSyntax(), *ToInitOrErr);
7488}
7489
7492 ExpectedType ToTypeOrErr = import(E->getType());
7493 if (!ToTypeOrErr)
7494 return ToTypeOrErr.takeError();
7495
7496 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7497 if (!ToLocationOrErr)
7498 return ToLocationOrErr.takeError();
7499
7500 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7501 *ToTypeOrErr, *ToLocationOrErr);
7502}
7503
7505 ExpectedType ToTypeOrErr = import(E->getType());
7506 if (!ToTypeOrErr)
7507 return ToTypeOrErr.takeError();
7508
7509 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7510 if (!ToLocationOrErr)
7511 return ToLocationOrErr.takeError();
7512
7514 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7515}
7516
7517
7519 ExpectedType ToTypeOrErr = import(E->getType());
7520 if (!ToTypeOrErr)
7521 return ToTypeOrErr.takeError();
7522
7523 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7524 if (!ToLocationOrErr)
7525 return ToLocationOrErr.takeError();
7526
7528 Importer.getToContext(), E->getValue(), E->isExact(),
7529 *ToTypeOrErr, *ToLocationOrErr);
7530}
7531
7533 auto ToTypeOrErr = import(E->getType());
7534 if (!ToTypeOrErr)
7535 return ToTypeOrErr.takeError();
7536
7537 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7538 if (!ToSubExprOrErr)
7539 return ToSubExprOrErr.takeError();
7540
7541 return new (Importer.getToContext()) ImaginaryLiteral(
7542 *ToSubExprOrErr, *ToTypeOrErr);
7543}
7544
7546 auto ToTypeOrErr = import(E->getType());
7547 if (!ToTypeOrErr)
7548 return ToTypeOrErr.takeError();
7549
7550 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7551 if (!ToLocationOrErr)
7552 return ToLocationOrErr.takeError();
7553
7554 return new (Importer.getToContext()) FixedPointLiteral(
7555 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7556 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7557}
7558
7560 ExpectedType ToTypeOrErr = import(E->getType());
7561 if (!ToTypeOrErr)
7562 return ToTypeOrErr.takeError();
7563
7564 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7565 if (!ToLocationOrErr)
7566 return ToLocationOrErr.takeError();
7567
7568 return new (Importer.getToContext()) CharacterLiteral(
7569 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7570}
7571
7573 ExpectedType ToTypeOrErr = import(E->getType());
7574 if (!ToTypeOrErr)
7575 return ToTypeOrErr.takeError();
7576
7578 if (Error Err = ImportArrayChecked(
7579 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7580 return std::move(Err);
7581
7582 return StringLiteral::Create(
7583 Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
7584 *ToTypeOrErr, ToLocations.data(), ToLocations.size());
7585}
7586
7588
7589 Error Err = Error::success();
7590 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7591 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7592 auto ToType = importChecked(Err, E->getType());
7593 auto ToInitializer = importChecked(Err, E->getInitializer());
7594 if (Err)
7595 return std::move(Err);
7596
7597 return new (Importer.getToContext()) CompoundLiteralExpr(
7598 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7599 ToInitializer, E->isFileScope());
7600}
7601
7603
7604 Error Err = Error::success();
7605 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7606 auto ToType = importChecked(Err, E->getType());
7607 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7608 if (Err)
7609 return std::move(Err);
7610
7612 if (Error Err = ImportArrayChecked(
7613 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7614 ToExprs.begin()))
7615 return std::move(Err);
7616
7617 return new (Importer.getToContext()) AtomicExpr(
7618
7619 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7620}
7621
7623 Error Err = Error::success();
7624 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7625 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7626 auto ToLabel = importChecked(Err, E->getLabel());
7627 auto ToType = importChecked(Err, E->getType());
7628 if (Err)
7629 return std::move(Err);
7630
7631 return new (Importer.getToContext()) AddrLabelExpr(
7632 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7633}
7635 Error Err = Error::success();
7636 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7637 auto ToResult = importChecked(Err, E->getAPValueResult());
7638 if (Err)
7639 return std::move(Err);
7640
7641 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7642}
7644 Error Err = Error::success();
7645 auto ToLParen = importChecked(Err, E->getLParen());
7646 auto ToRParen = importChecked(Err, E->getRParen());
7647 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7648 if (Err)
7649 return std::move(Err);
7650
7651 return new (Importer.getToContext())
7652 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7653}
7654
7656 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7657 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7658 return std::move(Err);
7659
7660 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7661 if (!ToLParenLocOrErr)
7662 return ToLParenLocOrErr.takeError();
7663
7664 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7665 if (!ToRParenLocOrErr)
7666 return ToRParenLocOrErr.takeError();
7667
7668 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7669 ToExprs, *ToRParenLocOrErr);
7670}
7671
7673 Error Err = Error::success();
7674 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7675 auto ToType = importChecked(Err, E->getType());
7676 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7677 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7678 if (Err)
7679 return std::move(Err);
7680
7681 return new (Importer.getToContext())
7682 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7683 E->getTemplateDepth());
7684}
7685
7687 Error Err = Error::success();
7688 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7689 auto ToType = importChecked(Err, E->getType());
7690 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7691 if (Err)
7692 return std::move(Err);
7693
7694 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7695 E->hasStoredFPFeatures());
7696 UO->setType(ToType);
7697 UO->setSubExpr(ToSubExpr);
7698 UO->setOpcode(E->getOpcode());
7699 UO->setOperatorLoc(ToOperatorLoc);
7700 UO->setCanOverflow(E->canOverflow());
7701 if (E->hasStoredFPFeatures())
7702 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7703
7704 return UO;
7705}
7706
7708
7710 Error Err = Error::success();
7711 auto ToType = importChecked(Err, E->getType());
7712 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7713 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7714 if (Err)
7715 return std::move(Err);
7716
7717 if (E->isArgumentType()) {
7718 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
7719 import(E->getArgumentTypeInfo());
7720 if (!ToArgumentTypeInfoOrErr)
7721 return ToArgumentTypeInfoOrErr.takeError();
7722
7723 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7724 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
7725 ToRParenLoc);
7726 }
7727
7728 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
7729 if (!ToArgumentExprOrErr)
7730 return ToArgumentExprOrErr.takeError();
7731
7732 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7733 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
7734}
7735
7737 Error Err = Error::success();
7738 auto ToLHS = importChecked(Err, E->getLHS());
7739 auto ToRHS = importChecked(Err, E->getRHS());
7740 auto ToType = importChecked(Err, E->getType());
7741 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7742 if (Err)
7743 return std::move(Err);
7744
7746 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7747 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7748 E->getFPFeatures());
7749}
7750
7752 Error Err = Error::success();
7753 auto ToCond = importChecked(Err, E->getCond());
7754 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7755 auto ToLHS = importChecked(Err, E->getLHS());
7756 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7757 auto ToRHS = importChecked(Err, E->getRHS());
7758 auto ToType = importChecked(Err, E->getType());
7759 if (Err)
7760 return std::move(Err);
7761
7762 return new (Importer.getToContext()) ConditionalOperator(
7763 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
7764 E->getValueKind(), E->getObjectKind());
7765}
7766
7769 Error Err = Error::success();
7770 auto ToCommon = importChecked(Err, E->getCommon());
7771 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
7772 auto ToCond = importChecked(Err, E->getCond());
7773 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
7774 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
7775 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7776 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7777 auto ToType = importChecked(Err, E->getType());
7778 if (Err)
7779 return std::move(Err);
7780
7781 return new (Importer.getToContext()) BinaryConditionalOperator(
7782 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
7783 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
7784 E->getObjectKind());
7785}
7786
7789 Error Err = Error::success();
7790 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
7791 if (Err)
7792 return std::move(Err);
7793
7794 return new (Importer.getToContext())
7795 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
7796}
7797
7799 Error Err = Error::success();
7800 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7801 auto ToQueriedTypeSourceInfo =
7803 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
7804 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7805 auto ToType = importChecked(Err, E->getType());
7806 if (Err)
7807 return std::move(Err);
7808
7809 return new (Importer.getToContext()) ArrayTypeTraitExpr(
7810 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
7811 ToDimensionExpression, ToEndLoc, ToType);
7812}
7813
7815 Error Err = Error::success();
7816 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7817 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
7818 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7819 auto ToType = importChecked(Err, E->getType());
7820 if (Err)
7821 return std::move(Err);
7822
7823 return new (Importer.getToContext()) ExpressionTraitExpr(
7824 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
7825 ToEndLoc, ToType);
7826}
7827
7829 Error Err = Error::success();
7830 auto ToLocation = importChecked(Err, E->getLocation());
7831 auto ToType = importChecked(Err, E->getType());
7832 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
7833 if (Err)
7834 return std::move(Err);
7835
7836 return new (Importer.getToContext()) OpaqueValueExpr(
7837 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
7838}
7839
7841 Error Err = Error::success();
7842 auto ToLHS = importChecked(Err, E->getLHS());
7843 auto ToRHS = importChecked(Err, E->getRHS());
7844 auto ToType = importChecked(Err, E->getType());
7845 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
7846 if (Err)
7847 return std::move(Err);
7848
7849 return new (Importer.getToContext()) ArraySubscriptExpr(
7850 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
7851 ToRBracketLoc);
7852}
7853
7856 Error Err = Error::success();
7857 auto ToLHS = importChecked(Err, E->getLHS());
7858 auto ToRHS = importChecked(Err, E->getRHS());
7859 auto ToType = importChecked(Err, E->getType());
7860 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
7861 auto ToComputationResultType =
7863 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7864 if (Err)
7865 return std::move(Err);
7866
7868 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7869 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7870 E->getFPFeatures(),
7871 ToComputationLHSType, ToComputationResultType);
7872}
7873
7876 CXXCastPath Path;
7877 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
7878 if (auto SpecOrErr = import(*I))
7879 Path.push_back(*SpecOrErr);
7880 else
7881 return SpecOrErr.takeError();
7882 }
7883 return Path;
7884}
7885
7887 ExpectedType ToTypeOrErr = import(E->getType());
7888 if (!ToTypeOrErr)
7889 return ToTypeOrErr.takeError();
7890
7891 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7892 if (!ToSubExprOrErr)
7893 return ToSubExprOrErr.takeError();
7894
7895 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7896 if (!ToBasePathOrErr)
7897 return ToBasePathOrErr.takeError();
7898
7900 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
7901 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
7902}
7903
7905 Error Err = Error::success();
7906 auto ToType = importChecked(Err, E->getType());
7907 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7908 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
7909 if (Err)
7910 return std::move(Err);
7911
7912 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7913 if (!ToBasePathOrErr)
7914 return ToBasePathOrErr.takeError();
7915 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
7916
7917 switch (E->getStmtClass()) {
7918 case Stmt::CStyleCastExprClass: {
7919 auto *CCE = cast<CStyleCastExpr>(E);
7920 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
7921 if (!ToLParenLocOrErr)
7922 return ToLParenLocOrErr.takeError();
7923 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
7924 if (!ToRParenLocOrErr)
7925 return ToRParenLocOrErr.takeError();
7927 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
7928 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
7929 *ToLParenLocOrErr, *ToRParenLocOrErr);
7930 }
7931
7932 case Stmt::CXXFunctionalCastExprClass: {
7933 auto *FCE = cast<CXXFunctionalCastExpr>(E);
7934 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
7935 if (!ToLParenLocOrErr)
7936 return ToLParenLocOrErr.takeError();
7937 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
7938 if (!ToRParenLocOrErr)
7939 return ToRParenLocOrErr.takeError();
7941 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
7942 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
7943 *ToLParenLocOrErr, *ToRParenLocOrErr);
7944 }
7945
7946 case Stmt::ObjCBridgedCastExprClass: {
7947 auto *OCE = cast<ObjCBridgedCastExpr>(E);
7948 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
7949 if (!ToLParenLocOrErr)
7950 return ToLParenLocOrErr.takeError();
7951 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
7952 if (!ToBridgeKeywordLocOrErr)
7953 return ToBridgeKeywordLocOrErr.takeError();
7954 return new (Importer.getToContext()) ObjCBridgedCastExpr(
7955 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
7956 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
7957 }
7958 case Stmt::BuiltinBitCastExprClass: {
7959 auto *BBC = cast<BuiltinBitCastExpr>(E);
7960 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
7961 if (!ToKWLocOrErr)
7962 return ToKWLocOrErr.takeError();
7963 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
7964 if (!ToRParenLocOrErr)
7965 return ToRParenLocOrErr.takeError();
7966 return new (Importer.getToContext()) BuiltinBitCastExpr(
7967 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
7968 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
7969 }
7970 default:
7971 llvm_unreachable("Cast expression of unsupported type!");
7972 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7973 }
7974}
7975
7978 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
7979 const OffsetOfNode &FromNode = E->getComponent(I);
7980
7981 SourceLocation ToBeginLoc, ToEndLoc;
7982
7983 if (FromNode.getKind() != OffsetOfNode::Base) {
7984 Error Err = Error::success();
7985 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
7986 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
7987 if (Err)
7988 return std::move(Err);
7989 }
7990
7991 switch (FromNode.getKind()) {
7993 ToNodes.push_back(
7994 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
7995 break;
7996 case OffsetOfNode::Base: {
7997 auto ToBSOrErr = import(FromNode.getBase());
7998 if (!ToBSOrErr)
7999 return ToBSOrErr.takeError();
8000 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8001 break;
8002 }
8003 case OffsetOfNode::Field: {
8004 auto ToFieldOrErr = import(FromNode.getField());
8005 if (!ToFieldOrErr)
8006 return ToFieldOrErr.takeError();
8007 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8008 break;
8009 }
8011 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8012 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8013 break;
8014 }
8015 }
8016 }
8017
8019 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8020 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8021 if (!ToIndexExprOrErr)
8022 return ToIndexExprOrErr.takeError();
8023 ToExprs[I] = *ToIndexExprOrErr;
8024 }
8025
8026 Error Err = Error::success();
8027 auto ToType = importChecked(Err, E->getType());
8028 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8029 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8030 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8031 if (Err)
8032 return std::move(Err);
8033
8034 return OffsetOfExpr::Create(
8035 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8036 ToExprs, ToRParenLoc);
8037}
8038
8040 Error Err = Error::success();
8041 auto ToType = importChecked(Err, E->getType());
8042 auto ToOperand = importChecked(Err, E->getOperand());
8043 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8044 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8045 if (Err)
8046 return std::move(Err);
8047
8048 CanThrowResult ToCanThrow;
8049 if (E->isValueDependent())
8050 ToCanThrow = CT_Dependent;
8051 else
8052 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8053
8054 return new (Importer.getToContext()) CXXNoexceptExpr(
8055 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8056}
8057
8059 Error Err = Error::success();
8060 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8061 auto ToType = importChecked(Err, E->getType());
8062 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8063 if (Err)
8064 return std::move(Err);
8065
8066 return new (Importer.getToContext()) CXXThrowExpr(
8067 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8068}
8069
8071 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8072 if (!ToUsedLocOrErr)
8073 return ToUsedLocOrErr.takeError();
8074
8075 auto ToParamOrErr = import(E->getParam());
8076 if (!ToParamOrErr)
8077 return ToParamOrErr.takeError();
8078
8079 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8080 if (!UsedContextOrErr)
8081 return UsedContextOrErr.takeError();
8082
8083 // Import the default arg if it was not imported yet.
8084 // This is needed because it can happen that during the import of the
8085 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8086 // encountered here. The default argument for a ParmVarDecl is set in the
8087 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8088 // see VisitParmVarDecl).
8089 ParmVarDecl *ToParam = *ToParamOrErr;
8090 if (!ToParam->getDefaultArg()) {
8091 std::optional<ParmVarDecl *> FromParam =
8092 Importer.getImportedFromDecl(ToParam);
8093 assert(FromParam && "ParmVarDecl was not imported?");
8094
8095 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8096 return std::move(Err);
8097 }
8098 Expr *RewrittenInit = nullptr;
8099 if (E->hasRewrittenInit()) {
8100 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8101 if (!ExprOrErr)
8102 return ExprOrErr.takeError();
8103 RewrittenInit = ExprOrErr.get();
8104 }
8105 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8106 *ToParamOrErr, RewrittenInit,
8107 *UsedContextOrErr);
8108}
8109
8112 Error Err = Error::success();
8113 auto ToType = importChecked(Err, E->getType());
8114 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8115 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8116 if (Err)
8117 return std::move(Err);
8118
8119 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8120 ToType, ToTypeSourceInfo, ToRParenLoc);
8121}
8122
8125 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8126 if (!ToSubExprOrErr)
8127 return ToSubExprOrErr.takeError();
8128
8129 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8130 if (!ToDtorOrErr)
8131 return ToDtorOrErr.takeError();
8132
8133 ASTContext &ToCtx = Importer.getToContext();
8134 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8135 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8136}
8137
8139
8141 Error Err = Error::success();
8142 auto ToConstructor = importChecked(Err, E->getConstructor());
8143 auto ToType = importChecked(Err, E->getType());
8144 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8145 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8146 if (Err)
8147 return std::move(Err);
8148
8150 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8151 return std::move(Err);
8152
8154 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8155 ToParenOrBraceRange, E->hadMultipleCandidates(),
8158}
8159
8162 DeclContext *DC, *LexicalDC;
8163 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8164 return std::move(Err);
8165
8166 Error Err = Error::success();
8167 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8168 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8169 if (Err)
8170 return std::move(Err);
8171 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8172
8174 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8175 D->getManglingNumber()))
8176 return To;
8177
8178 To->setLexicalDeclContext(LexicalDC);
8179 LexicalDC->addDeclInternal(To);
8180 return To;
8181}
8182
8185 Error Err = Error::success();
8186 auto ToType = importChecked(Err, E->getType());
8187 Expr *ToTemporaryExpr = importChecked(
8188 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8189 auto ToMaterializedDecl =
8191 if (Err)
8192 return std::move(Err);
8193
8194 if (!ToTemporaryExpr)
8195 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8196
8197 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8198 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8199 ToMaterializedDecl);
8200
8201 return ToMTE;
8202}
8203
8205 Error Err = Error::success();
8206 auto ToType = importChecked(Err, E->getType());
8207 auto ToPattern = importChecked(Err, E->getPattern());
8208 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8209 if (Err)
8210 return std::move(Err);
8211
8212 return new (Importer.getToContext()) PackExpansionExpr(
8213 ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
8214}
8215
8217 Error Err = Error::success();
8218 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8219 auto ToPack = importChecked(Err, E->getPack());
8220 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8221 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8222 if (Err)
8223 return std::move(Err);
8224
8225 std::optional<unsigned> Length;
8226 if (!E->isValueDependent())
8227 Length = E->getPackLength();
8228
8229 SmallVector<TemplateArgument, 8> ToPartialArguments;
8230 if (E->isPartiallySubstituted()) {
8231 if (Error Err = ImportTemplateArguments(E->getPartialArguments(),
8232 ToPartialArguments))
8233 return std::move(Err);
8234 }
8235
8237 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8238 Length, ToPartialArguments);
8239}
8240
8241
8243 Error Err = Error::success();
8244 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8245 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8246 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8247 auto ToArraySize = importChecked(Err, E->getArraySize());
8248 auto ToInitializer = importChecked(Err, E->getInitializer());
8249 auto ToType = importChecked(Err, E->getType());
8250 auto ToAllocatedTypeSourceInfo =
8252 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8253 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8254 if (Err)
8255 return std::move(Err);
8256
8257 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8258 if (Error Err =
8259 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8260 return std::move(Err);
8261
8262 return CXXNewExpr::Create(
8263 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8264 ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(),
8265 ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(),
8266 ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange,
8267 ToDirectInitRange);
8268}
8269
8271 Error Err = Error::success();
8272 auto ToType = importChecked(Err, E->getType());
8273 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8274 auto ToArgument = importChecked(Err, E->getArgument());
8275 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8276 if (Err)
8277 return std::move(Err);
8278
8279 return new (Importer.getToContext()) CXXDeleteExpr(
8280 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8281 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8282 ToBeginLoc);
8283}
8284
8286 Error Err = Error::success();
8287 auto ToType = importChecked(Err, E->getType());
8288 auto ToLocation = importChecked(Err, E->getLocation());
8289 auto ToConstructor = importChecked(Err, E->getConstructor());
8290 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8291 if (Err)
8292 return std::move(Err);
8293
8295 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8296 return std::move(Err);
8297
8299 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8300 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8303 ToParenOrBraceRange);
8305 return ToE;
8306}
8307
8309 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8310 if (!ToSubExprOrErr)
8311 return ToSubExprOrErr.takeError();
8312
8314 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8315 return std::move(Err);
8316
8318 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8319 ToObjects);
8320}
8321
8323 Error Err = Error::success();
8324 auto ToCallee = importChecked(Err, E->getCallee());
8325 auto ToType = importChecked(Err, E->getType());
8326 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8327 if (Err)
8328 return std::move(Err);
8329
8331 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8332 return std::move(Err);
8333
8334 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8335 ToType, E->getValueKind(), ToRParenLoc,
8336 E->getFPFeatures());
8337}
8338
8340 ExpectedType ToTypeOrErr = import(E->getType());
8341 if (!ToTypeOrErr)
8342 return ToTypeOrErr.takeError();
8343
8344 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8345 if (!ToLocationOrErr)
8346 return ToLocationOrErr.takeError();
8347
8348 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8349 *ToTypeOrErr, E->isImplicit());
8350}
8351
8353 ExpectedType ToTypeOrErr = import(E->getType());
8354 if (!ToTypeOrErr)
8355 return ToTypeOrErr.takeError();
8356
8357 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8358 if (!ToLocationOrErr)
8359 return ToLocationOrErr.takeError();
8360
8361 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8362 *ToTypeOrErr, *ToLocationOrErr);
8363}
8364
8366 Error Err = Error::success();
8367 auto ToBase = importChecked(Err, E->getBase());
8368 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8369 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8370 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8371 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8372 auto ToType = importChecked(Err, E->getType());
8373 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8374 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8375 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8376 if (Err)
8377 return std::move(Err);
8378
8379 DeclAccessPair ToFoundDecl =
8381
8382 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8383
8384 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8385 if (E->hasExplicitTemplateArgs()) {
8386 if (Error Err =
8388 E->template_arguments(), ToTAInfo))
8389 return std::move(Err);
8390 ResInfo = &ToTAInfo;
8391 }
8392
8393 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8394 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8395 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8396 ResInfo, ToType, E->getValueKind(),
8397 E->getObjectKind(), E->isNonOdrUse());
8398}
8399
8402 Error Err = Error::success();
8403 auto ToBase = importChecked(Err, E->getBase());
8404 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8405 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8406 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8407 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8408 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8409 if (Err)
8410 return std::move(Err);
8411
8413 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8414 const IdentifierInfo *ToII = Importer.Import(FromII);
8415 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8416 if (!ToDestroyedTypeLocOrErr)
8417 return ToDestroyedTypeLocOrErr.takeError();
8418 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8419 } else {
8420 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8421 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8422 else
8423 return ToTIOrErr.takeError();
8424 }
8425
8426 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8427 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8428 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8429}
8430
8433 Error Err = Error::success();
8434 auto ToType = importChecked(Err, E->getType());
8435 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8436 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8437 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8438 auto ToFirstQualifierFoundInScope =
8440 if (Err)
8441 return std::move(Err);
8442
8443 Expr *ToBase = nullptr;
8444 if (!E->isImplicitAccess()) {
8445 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8446 ToBase = *ToBaseOrErr;
8447 else
8448 return ToBaseOrErr.takeError();
8449 }
8450
8451 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8452
8453 if (E->hasExplicitTemplateArgs()) {
8454 if (Error Err =
8456 E->template_arguments(), ToTAInfo))
8457 return std::move(Err);
8458 ResInfo = &ToTAInfo;
8459 }
8460 auto ToMember = importChecked(Err, E->getMember());
8461 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8462 if (Err)
8463 return std::move(Err);
8464 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8465
8466 // Import additional name location/type info.
8467 if (Error Err =
8468 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8469 return std::move(Err);
8470
8472 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8473 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8474 ToMemberNameInfo, ResInfo);
8475}
8476
8479 Error Err = Error::success();
8480 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8481 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8482 auto ToDeclName = importChecked(Err, E->getDeclName());
8483 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8484 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8485 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8486 if (Err)
8487 return std::move(Err);
8488
8489 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8490 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8491 return std::move(Err);
8492
8493 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8494 TemplateArgumentListInfo *ResInfo = nullptr;
8495 if (E->hasExplicitTemplateArgs()) {
8496 if (Error Err =
8498 return std::move(Err);
8499 ResInfo = &ToTAInfo;
8500 }
8501
8503 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8504 ToNameInfo, ResInfo);
8505}
8506
8509 Error Err = Error::success();
8510 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8511 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8512 auto ToType = importChecked(Err, E->getType());
8513 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8514 if (Err)
8515 return std::move(Err);
8516
8518 if (Error Err =
8519 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8520 return std::move(Err);
8521
8523 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8524 llvm::ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8525}
8526
8529 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8530 if (!ToNamingClassOrErr)
8531 return ToNamingClassOrErr.takeError();
8532
8533 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8534 if (!ToQualifierLocOrErr)
8535 return ToQualifierLocOrErr.takeError();
8536
8537 Error Err = Error::success();
8538 auto ToName = importChecked(Err, E->getName());
8539 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8540 if (Err)
8541 return std::move(Err);
8542 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8543
8544 // Import additional name location/type info.
8545 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8546 return std::move(Err);
8547
8548 UnresolvedSet<8> ToDecls;
8549 for (auto *D : E->decls())
8550 if (auto ToDOrErr = import(D))
8551 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8552 else
8553 return ToDOrErr.takeError();
8554
8555 if (E->hasExplicitTemplateArgs()) {
8556 TemplateArgumentListInfo ToTAInfo;
8557 if (Error Err = ImportTemplateArgumentListInfo(
8559 ToTAInfo))
8560 return std::move(Err);
8561
8562 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8563 if (!ToTemplateKeywordLocOrErr)
8564 return ToTemplateKeywordLocOrErr.takeError();
8565
8566 const bool KnownDependent =
8567 (E->getDependence() & ExprDependence::TypeValue) ==
8568 ExprDependence::TypeValue;
8570 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8571 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8572 ToDecls.begin(), ToDecls.end(), KnownDependent);
8573 }
8574
8576 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8577 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8578 /*KnownDependent=*/E->isTypeDependent());
8579}
8580
8583 Error Err = Error::success();
8584 auto ToType = importChecked(Err, E->getType());
8585 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8586 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8587 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8588 auto ToName = importChecked(Err, E->getName());
8589 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8590 if (Err)
8591 return std::move(Err);
8592
8593 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8594 // Import additional name location/type info.
8595 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8596 return std::move(Err);
8597
8598 UnresolvedSet<8> ToDecls;
8599 for (Decl *D : E->decls())
8600 if (auto ToDOrErr = import(D))
8601 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8602 else
8603 return ToDOrErr.takeError();
8604
8605 TemplateArgumentListInfo ToTAInfo;
8606 TemplateArgumentListInfo *ResInfo = nullptr;
8607 if (E->hasExplicitTemplateArgs()) {
8608 TemplateArgumentListInfo FromTAInfo;
8609 E->copyTemplateArgumentsInto(FromTAInfo);
8610 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8611 return std::move(Err);
8612 ResInfo = &ToTAInfo;
8613 }
8614
8615 Expr *ToBase = nullptr;
8616 if (!E->isImplicitAccess()) {
8617 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8618 ToBase = *ToBaseOrErr;
8619 else
8620 return ToBaseOrErr.takeError();
8621 }
8622
8624 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8625 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8626 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8627}
8628
8630 Error Err = Error::success();
8631 auto ToCallee = importChecked(Err, E->getCallee());
8632 auto ToType = importChecked(Err, E->getType());
8633 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8634 if (Err)
8635 return std::move(Err);
8636
8637 unsigned NumArgs = E->getNumArgs();
8638 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8639 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8640 return std::move(Err);
8641
8642 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8644 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8645 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8646 OCE->getADLCallKind());
8647 }
8648
8649 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8650 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8651 /*MinNumArgs=*/0, E->getADLCallKind());
8652}
8653
8655 CXXRecordDecl *FromClass = E->getLambdaClass();
8656 auto ToClassOrErr = import(FromClass);
8657 if (!ToClassOrErr)
8658 return ToClassOrErr.takeError();
8659 CXXRecordDecl *ToClass = *ToClassOrErr;
8660
8661 auto ToCallOpOrErr = import(E->getCallOperator());
8662 if (!ToCallOpOrErr)
8663 return ToCallOpOrErr.takeError();
8664
8665 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8666 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8667 return std::move(Err);
8668
8669 Error Err = Error::success();
8670 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8671 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8672 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8673 if (Err)
8674 return std::move(Err);
8675
8676 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8677 E->getCaptureDefault(), ToCaptureDefaultLoc,
8679 E->hasExplicitResultType(), ToCaptureInits,
8680 ToEndLoc, E->containsUnexpandedParameterPack());
8681}
8682
8683
8685 Error Err = Error::success();
8686 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8687 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8688 auto ToType = importChecked(Err, E->getType());
8689 if (Err)
8690 return std::move(Err);
8691
8692 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8693 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8694 return std::move(Err);
8695
8696 ASTContext &ToCtx = Importer.getToContext();
8697 InitListExpr *To = new (ToCtx) InitListExpr(
8698 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8699 To->setType(ToType);
8700
8701 if (E->hasArrayFiller()) {
8702 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8703 To->setArrayFiller(*ToFillerOrErr);
8704 else
8705 return ToFillerOrErr.takeError();
8706 }
8707
8708 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
8709 if (auto ToFDOrErr = import(FromFD))
8710 To->setInitializedFieldInUnion(*ToFDOrErr);
8711 else
8712 return ToFDOrErr.takeError();
8713 }
8714
8715 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
8716 if (auto ToSyntFormOrErr = import(SyntForm))
8717 To->setSyntacticForm(*ToSyntFormOrErr);
8718 else
8719 return ToSyntFormOrErr.takeError();
8720 }
8721
8722 // Copy InitListExprBitfields, which are not handled in the ctor of
8723 // InitListExpr.
8725
8726 return To;
8727}
8728
8731 ExpectedType ToTypeOrErr = import(E->getType());
8732 if (!ToTypeOrErr)
8733 return ToTypeOrErr.takeError();
8734
8735 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8736 if (!ToSubExprOrErr)
8737 return ToSubExprOrErr.takeError();
8738
8739 return new (Importer.getToContext()) CXXStdInitializerListExpr(
8740 *ToTypeOrErr, *ToSubExprOrErr);
8741}
8742
8745 Error Err = Error::success();
8746 auto ToLocation = importChecked(Err, E->getLocation());
8747 auto ToType = importChecked(Err, E->getType());
8748 auto ToConstructor = importChecked(Err, E->getConstructor());
8749 if (Err)
8750 return std::move(Err);
8751
8752 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
8753 ToLocation, ToType, ToConstructor, E->constructsVBase(),
8754 E->inheritedFromVBase());
8755}
8756
8758 Error Err = Error::success();
8759 auto ToType = importChecked(Err, E->getType());
8760 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
8761 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8762 if (Err)
8763 return std::move(Err);
8764
8765 return new (Importer.getToContext()) ArrayInitLoopExpr(
8766 ToType, ToCommonExpr, ToSubExpr);
8767}
8768
8770 ExpectedType ToTypeOrErr = import(E->getType());
8771 if (!ToTypeOrErr)
8772 return ToTypeOrErr.takeError();
8773 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
8774}
8775
8777 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
8778 if (!ToBeginLocOrErr)
8779 return ToBeginLocOrErr.takeError();
8780
8781 auto ToFieldOrErr = import(E->getField());
8782 if (!ToFieldOrErr)
8783 return ToFieldOrErr.takeError();
8784
8785 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8786 if (!UsedContextOrErr)
8787 return UsedContextOrErr.takeError();
8788
8789 FieldDecl *ToField = *ToFieldOrErr;
8790 assert(ToField->hasInClassInitializer() &&
8791 "Field should have in-class initializer if there is a default init "
8792 "expression that uses it.");
8793 if (!ToField->getInClassInitializer()) {
8794 // The in-class initializer may be not yet set in "To" AST even if the
8795 // field is already there. This must be set here to make construction of
8796 // CXXDefaultInitExpr work.
8797 auto ToInClassInitializerOrErr =
8798 import(E->getField()->getInClassInitializer());
8799 if (!ToInClassInitializerOrErr)
8800 return ToInClassInitializerOrErr.takeError();
8801 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
8802 }
8803
8804 Expr *RewrittenInit = nullptr;
8805 if (E->hasRewrittenInit()) {
8806 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8807 if (!ExprOrErr)
8808 return ExprOrErr.takeError();
8809 RewrittenInit = ExprOrErr.get();
8810 }
8811
8812 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
8813 ToField, *UsedContextOrErr, RewrittenInit);
8814}
8815
8817 Error Err = Error::success();
8818 auto ToType = importChecked(Err, E->getType());
8819 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8820 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8821 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8822 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8823 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
8824 if (Err)
8825 return std::move(Err);
8826
8827 ExprValueKind VK = E->getValueKind();
8828 CastKind CK = E->getCastKind();
8829 auto ToBasePathOrErr = ImportCastPath(E);
8830 if (!ToBasePathOrErr)
8831 return ToBasePathOrErr.takeError();
8832
8833 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
8835 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8836 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
8837 ToAngleBrackets);
8838 } else if (isa<CXXDynamicCastExpr>(E)) {
8840 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8841 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8842 } else if (isa<CXXReinterpretCastExpr>(E)) {
8844 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8845 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8846 } else if (isa<CXXConstCastExpr>(E)) {
8848 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
8849 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8850 } else {
8851 llvm_unreachable("Unknown cast type");
8852 return make_error<ASTImportError>();
8853 }
8854}
8855
8858 Error Err = Error::success();
8859 auto ToType = importChecked(Err, E->getType());
8860 auto ToExprLoc = importChecked(Err, E->getExprLoc());
8861 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
8862 auto ToReplacement = importChecked(Err, E->getReplacement());
8863 if (Err)
8864 return std::move(Err);
8865
8866 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
8867 ToType, E->getValueKind(), ToExprLoc, ToReplacement, ToAssociatedDecl,
8868 E->getIndex(), E->getPackIndex(), E->isReferenceParameter());
8869}
8870
8872 Error Err = Error::success();
8873 auto ToType = importChecked(Err, E->getType());
8874 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8875 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8876 if (Err)
8877 return std::move(Err);
8878
8880 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
8881 return std::move(Err);
8882
8883 // According to Sema::BuildTypeTrait(), if E is value-dependent,
8884 // Value is always false.
8885 bool ToValue = (E->isValueDependent() ? false : E->getValue());
8886
8887 return TypeTraitExpr::Create(
8888 Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs,
8889 ToEndLoc, ToValue);
8890}
8891
8893 ExpectedType ToTypeOrErr = import(E->getType());
8894 if (!ToTypeOrErr)
8895 return ToTypeOrErr.takeError();
8896
8897 auto ToSourceRangeOrErr = import(E->getSourceRange());
8898 if (!ToSourceRangeOrErr)
8899 return ToSourceRangeOrErr.takeError();
8900
8901 if (E->isTypeOperand()) {
8902 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
8903 return new (Importer.getToContext()) CXXTypeidExpr(
8904 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
8905 else
8906 return ToTSIOrErr.takeError();
8907 }
8908
8909 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
8910 if (!ToExprOperandOrErr)
8911 return ToExprOperandOrErr.takeError();
8912
8913 return new (Importer.getToContext()) CXXTypeidExpr(
8914 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
8915}
8916
8918 Error Err = Error::success();
8919
8920 QualType ToType = importChecked(Err, E->getType());
8921 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
8922 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
8923 Expr *ToLHS = importChecked(Err, E->getLHS());
8924 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8925 Expr *ToRHS = importChecked(Err, E->getRHS());
8926 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
8927
8928 if (Err)
8929 return std::move(Err);
8930
8931 return new (Importer.getToContext())
8932 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
8933 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
8934}
8935
8937 CXXMethodDecl *FromMethod) {
8938 Error ImportErrors = Error::success();
8939 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
8940 if (auto ImportedOrErr = import(FromOverriddenMethod))
8941 ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
8942 (*ImportedOrErr)->getCanonicalDecl()));
8943 else
8944 ImportErrors =
8945 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
8946 }
8947 return ImportErrors;
8948}
8949
8951 ASTContext &FromContext, FileManager &FromFileManager,
8952 bool MinimalImport,
8953 std::shared_ptr<ASTImporterSharedState> SharedState)
8954 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
8955 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
8956 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
8957
8958 // Create a default state without the lookup table: LLDB case.
8959 if (!SharedState) {
8960 this->SharedState = std::make_shared<ASTImporterSharedState>();
8961 }
8962
8963 ImportedDecls[FromContext.getTranslationUnitDecl()] =
8964 ToContext.getTranslationUnitDecl();
8965}
8966
8967ASTImporter::~ASTImporter() = default;
8968
8969std::optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
8970 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
8971 "Try to get field index for non-field.");
8972
8973 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
8974 if (!Owner)
8975 return std::nullopt;
8976
8977 unsigned Index = 0;
8978 for (const auto *D : Owner->decls()) {
8979 if (D == F)
8980 return Index;
8981
8982 if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
8983 ++Index;
8984 }
8985
8986 llvm_unreachable("Field was not found in its parent context.");
8987
8988 return std::nullopt;
8989}
8990
8992ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
8993 // We search in the redecl context because of transparent contexts.
8994 // E.g. a simple C language enum is a transparent context:
8995 // enum E { A, B };
8996 // Now if we had a global variable in the TU
8997 // int A;
8998 // then the enum constant 'A' and the variable 'A' violates ODR.
8999 // We can diagnose this only if we search in the redecl context.
9000 DeclContext *ReDC = DC->getRedeclContext();
9001 if (SharedState->getLookupTable()) {
9003 SharedState->getLookupTable()->lookup(ReDC, Name);
9004 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9005 } else {
9006 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9007 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9008 // We must search by the slow case of localUncachedLookup because that is
9009 // working even if there is no LookupPtr for the DC. We could use
9010 // DC::buildLookup() to create the LookupPtr, but that would load external
9011 // decls again, we must avoid that case.
9012 // Also, even if we had the LookupPtr, we must find Decls which are not
9013 // in the LookupPtr, so we need the slow case.
9014 // These cases are handled in ASTImporterLookupTable, but we cannot use
9015 // that with LLDB since that traverses through the AST which initiates the
9016 // load of external decls again via DC::decls(). And again, we must avoid
9017 // loading external decls during the import.
9018 if (Result.empty())
9019 ReDC->localUncachedLookup(Name, Result);
9020 return Result;
9021 }
9022}
9023
9024void ASTImporter::AddToLookupTable(Decl *ToD) {
9025 SharedState->addDeclToLookup(ToD);
9026}
9027
9029 // Import the decl using ASTNodeImporter.
9030 ASTNodeImporter Importer(*this);
9031 return Importer.Visit(FromD);
9032}
9033
9035 MapImported(FromD, ToD);
9036}
9037
9040 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9041 if (Expected<Expr *> R = Import(CLE))
9042 return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
9043 }
9044
9045 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9046 // ASTNodeImporter.
9047 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9048}
9049
9051 if (!FromT)
9052 return FromT;
9053
9054 // Check whether we've already imported this type.
9055 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9056 ImportedTypes.find(FromT);
9057 if (Pos != ImportedTypes.end())
9058 return Pos->second;
9059
9060 // Import the type.
9061 ASTNodeImporter Importer(*this);
9062 ExpectedType ToTOrErr = Importer.Visit(FromT);
9063 if (!ToTOrErr)
9064 return ToTOrErr.takeError();
9065
9066 // Record the imported type.
9067 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9068
9069 return ToTOrErr->getTypePtr();
9070}
9071
9073 if (FromT.isNull())
9074 return QualType{};
9075
9076 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9077 if (!ToTyOrErr)
9078 return ToTyOrErr.takeError();
9079
9080 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9081}
9082
9084 if (!FromTSI)
9085 return FromTSI;
9086
9087 // FIXME: For now we just create a "trivial" type source info based
9088 // on the type and a single location. Implement a real version of this.
9089 ExpectedType TOrErr = Import(FromTSI->getType());
9090 if (!TOrErr)
9091 return TOrErr.takeError();
9092 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9093 if (!BeginLocOrErr)
9094 return BeginLocOrErr.takeError();
9095
9096 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9097}
9098
9099namespace {
9100// To use this object, it should be created before the new attribute is created,
9101// and destructed after it is created. The construction already performs the
9102// import of the data.
9103template <typename T> struct AttrArgImporter {
9104 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9105 AttrArgImporter(AttrArgImporter<T> &&) = default;
9106 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9107 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9108
9109 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9110 : To(I.importChecked(Err, From)) {}
9111
9112 const T &value() { return To; }
9113
9114private:
9115 T To;
9116};
9117
9118// To use this object, it should be created before the new attribute is created,
9119// and destructed after it is created. The construction already performs the
9120// import of the data. The array data is accessible in a pointer form, this form
9121// is used by the attribute classes. This object should be created once for the
9122// array data to be imported (the array size is not imported, just copied).
9123template <typename T> struct AttrArgArrayImporter {
9124 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9125 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9126 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9127 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9128
9129 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9130 const llvm::iterator_range<T *> &From,
9131 unsigned ArraySize) {
9132 if (Err)
9133 return;
9134 To.reserve(ArraySize);
9135 Err = I.ImportContainerChecked(From, To);
9136 }
9137
9138 T *value() { return To.data(); }
9139
9140private:
9142};
9143
9144class AttrImporter {
9145 Error Err{Error::success()};
9146 Attr *ToAttr = nullptr;
9147 ASTImporter &Importer;
9148 ASTNodeImporter NImporter;
9149
9150public:
9151 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9152
9153 // Useful for accessing the imported attribute.
9154 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9155 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9156
9157 // Create an "importer" for an attribute parameter.
9158 // Result of the 'value()' of that object is to be passed to the function
9159 // 'importAttr', in the order that is expected by the attribute class.
9160 template <class T> AttrArgImporter<T> importArg(const T &From) {
9161 return AttrArgImporter<T>(NImporter, Err, From);
9162 }
9163
9164 // Create an "importer" for an attribute parameter that has array type.
9165 // Result of the 'value()' of that object is to be passed to the function
9166 // 'importAttr', then the size of the array as next argument.
9167 template <typename T>
9168 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9169 unsigned ArraySize) {
9170 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9171 }
9172
9173 // Create an attribute object with the specified arguments.
9174 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9175 // should be values that are passed to the 'Create' function of the attribute.
9176 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9177 // used here.) As much data is copied or imported from the old attribute
9178 // as possible. The passed arguments should be already imported.
9179 // If an import error happens, the internal error is set to it, and any
9180 // further import attempt is ignored.
9181 template <typename T, typename... Arg>
9182 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9183 static_assert(std::is_base_of<Attr, T>::value,
9184 "T should be subclass of Attr.");
9185 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9186
9187 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9188 const IdentifierInfo *ToScopeName =
9189 Importer.Import(FromAttr->getScopeName());
9190 SourceRange ToAttrRange =
9191 NImporter.importChecked(Err, FromAttr->getRange());
9192 SourceLocation ToScopeLoc =
9193 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9194
9195 if (Err)
9196 return;
9197
9198 AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
9199 FromAttr->getParsedKind(), FromAttr->getForm());
9200 // The "SemanticSpelling" is not needed to be passed to the constructor.
9201 // That value is recalculated from the SpellingListIndex if needed.
9202 ToAttr = T::Create(Importer.getToContext(),
9203 std::forward<Arg>(ImportedArg)..., ToI);
9204
9205 ToAttr->setImplicit(FromAttr->isImplicit());
9206 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9207 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9208 ToInheritableAttr->setInherited(FromAttr->isInherited());
9209 }
9210
9211 // Create a clone of the 'FromAttr' and import its source range only.
9212 // This causes objects with invalid references to be created if the 'FromAttr'
9213 // contains other data that should be imported.
9214 void cloneAttr(const Attr *FromAttr) {
9215 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9216
9217 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9218 if (Err)
9219 return;
9220
9221 ToAttr = FromAttr->clone(Importer.getToContext());
9222 ToAttr->setRange(ToRange);
9223 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9224 }
9225
9226 // Get the result of the previous import attempt (can be used only once).
9227 llvm::Expected<Attr *> getResult() && {
9228 if (Err)
9229 return std::move(Err);
9230 assert(ToAttr && "Attribute should be created.");
9231 return ToAttr;
9232 }
9233};
9234} // namespace
9235
9237 AttrImporter AI(*this);
9238
9239 // FIXME: Is there some kind of AttrVisitor to use here?
9240 switch (FromAttr->getKind()) {
9241 case attr::Aligned: {
9242 auto *From = cast<AlignedAttr>(FromAttr);
9243 if (From->isAlignmentExpr())
9244 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9245 else
9246 AI.importAttr(From, false,
9247 AI.importArg(From->getAlignmentType()).value());
9248 break;
9249 }
9250
9251 case attr::AlignValue: {
9252 auto *From = cast<AlignValueAttr>(FromAttr);
9253 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9254 break;
9255 }
9256
9257 case attr::Format: {
9258 const auto *From = cast<FormatAttr>(FromAttr);
9259 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9260 From->getFirstArg());
9261 break;
9262 }
9263
9264 case attr::EnableIf: {
9265 const auto *From = cast<EnableIfAttr>(FromAttr);
9266 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9267 From->getMessage());
9268 break;
9269 }
9270
9271 case attr::AssertCapability: {
9272 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9273 AI.importAttr(From,
9274 AI.importArrayArg(From->args(), From->args_size()).value(),
9275 From->args_size());
9276 break;
9277 }
9278 case attr::AcquireCapability: {
9279 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9280 AI.importAttr(From,
9281 AI.importArrayArg(From->args(), From->args_size()).value(),
9282 From->args_size());
9283 break;
9284 }
9285 case attr::TryAcquireCapability: {
9286 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9287 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9288 AI.importArrayArg(From->args(), From->args_size()).value(),
9289 From->args_size());
9290 break;
9291 }
9292 case attr::ReleaseCapability: {
9293 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9294 AI.importAttr(From,
9295 AI.importArrayArg(From->args(), From->args_size()).value(),
9296 From->args_size());
9297 break;
9298 }
9299 case attr::RequiresCapability: {
9300 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9301 AI.importAttr(From,
9302 AI.importArrayArg(From->args(), From->args_size()).value(),
9303 From->args_size());
9304 break;
9305 }
9306 case attr::GuardedBy: {
9307 const auto *From = cast<GuardedByAttr>(FromAttr);
9308 AI.importAttr(From, AI.importArg(From->getArg()).value());
9309 break;
9310 }
9311 case attr::PtGuardedBy: {
9312 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9313 AI.importAttr(From, AI.importArg(From->getArg()).value());
9314 break;
9315 }
9316 case attr::AcquiredAfter: {
9317 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9318 AI.importAttr(From,
9319 AI.importArrayArg(From->args(), From->args_size()).value(),
9320 From->args_size());
9321 break;
9322 }
9323 case attr::AcquiredBefore: {
9324 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9325 AI.importAttr(From,
9326 AI.importArrayArg(From->args(), From->args_size()).value(),
9327 From->args_size());
9328 break;
9329 }
9330 case attr::AssertExclusiveLock: {
9331 const auto *From = cast<AssertExclusiveLockAttr>(FromAttr);
9332 AI.importAttr(From,
9333 AI.importArrayArg(From->args(), From->args_size()).value(),
9334 From->args_size());
9335 break;
9336 }
9337 case attr::AssertSharedLock: {
9338 const auto *From = cast<AssertSharedLockAttr>(FromAttr);
9339 AI.importAttr(From,
9340 AI.importArrayArg(From->args(), From->args_size()).value(),
9341 From->args_size());
9342 break;
9343 }
9344 case attr::ExclusiveTrylockFunction: {
9345 const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr);
9346 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9347 AI.importArrayArg(From->args(), From->args_size()).value(),
9348 From->args_size());
9349 break;
9350 }
9351 case attr::SharedTrylockFunction: {
9352 const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr);
9353 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9354 AI.importArrayArg(From->args(), From->args_size()).value(),
9355 From->args_size());
9356 break;
9357 }
9358 case attr::LockReturned: {
9359 const auto *From = cast<LockReturnedAttr>(FromAttr);
9360 AI.importAttr(From, AI.importArg(From->getArg()).value());
9361 break;
9362 }
9363 case attr::LocksExcluded: {
9364 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9365 AI.importAttr(From,
9366 AI.importArrayArg(From->args(), From->args_size()).value(),
9367 From->args_size());
9368 break;
9369 }
9370 default: {
9371 // The default branch works for attributes that have no arguments to import.
9372 // FIXME: Handle every attribute type that has arguments of type to import
9373 // (most often Expr* or Decl* or type) in the switch above.
9374 AI.cloneAttr(FromAttr);
9375 break;
9376 }
9377 }
9378
9379 return std::move(AI).getResult();
9380}
9381
9383 return ImportedDecls.lookup(FromD);
9384}
9385
9387 auto FromDPos = ImportedFromDecls.find(ToD);
9388 if (FromDPos == ImportedFromDecls.end())
9389 return nullptr;
9390 return FromDPos->second->getTranslationUnitDecl();
9391}
9392
9393Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
9394 if (!FromD->hasAttrs() || ToD->hasAttrs())
9395 return Error::success();
9396 for (const Attr *FromAttr : FromD->getAttrs()) {
9397 auto ToAttrOrErr = Import(FromAttr);
9398 if (ToAttrOrErr)
9399 ToD->addAttr(*ToAttrOrErr);
9400 else
9401 return ToAttrOrErr.takeError();
9402 }
9403 return Error::success();
9404}
9405
9407 if (!FromD)
9408 return nullptr;
9409
9410 // Push FromD to the stack, and remove that when we return.
9411 ImportPath.push(FromD);
9412 auto ImportPathBuilder =
9413 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9414
9415 // Check whether there was a previous failed import.
9416 // If yes return the existing error.
9417 if (auto Error = getImportDeclErrorIfAny(FromD))
9418 return make_error<ASTImportError>(*Error);
9419
9420 // Check whether we've already imported this declaration.
9421 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9422 if (ToD) {
9423 // Already imported (possibly from another TU) and with an error.
9424 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9425 setImportDeclError(FromD, *Error);
9426 return make_error<ASTImportError>(*Error);
9427 }
9428
9429 // If FromD has some updated flags after last import, apply it.
9430 updateFlags(FromD, ToD);
9431 // If we encounter a cycle during an import then we save the relevant part
9432 // of the import path associated to the Decl.
9433 if (ImportPath.hasCycleAtBack())
9434 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9435 return ToD;
9436 }
9437
9438 // Import the declaration.
9439 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9440 if (!ToDOrErr) {
9441 // Failed to import.
9442
9443 auto Pos = ImportedDecls.find(FromD);
9444 if (Pos != ImportedDecls.end()) {
9445 // Import failed after the object was created.
9446 // Remove all references to it.
9447 auto *ToD = Pos->second;
9448 ImportedDecls.erase(Pos);
9449
9450 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9451 // (e.g. with namespaces) that several decls from the 'from' context are
9452 // mapped to the same decl in the 'to' context. If we removed entries
9453 // from the LookupTable here then we may end up removing them multiple
9454 // times.
9455
9456 // The Lookuptable contains decls only which are in the 'to' context.
9457 // Remove from the Lookuptable only if it is *imported* into the 'to'
9458 // context (and do not remove it if it was added during the initial
9459 // traverse of the 'to' context).
9460 auto PosF = ImportedFromDecls.find(ToD);
9461 if (PosF != ImportedFromDecls.end()) {
9462 // In the case of TypedefNameDecl we create the Decl first and only
9463 // then we import and set its DeclContext. So, the DC might not be set
9464 // when we reach here.
9465 if (ToD->getDeclContext())
9466 SharedState->removeDeclFromLookup(ToD);
9467 ImportedFromDecls.erase(PosF);
9468 }
9469
9470 // FIXME: AST may contain remaining references to the failed object.
9471 // However, the ImportDeclErrors in the shared state contains all the
9472 // failed objects together with their error.
9473 }
9474
9475 // Error encountered for the first time.
9476 // After takeError the error is not usable any more in ToDOrErr.
9477 // Get a copy of the error object (any more simple solution for this?).
9478 ASTImportError ErrOut;
9479 handleAllErrors(ToDOrErr.takeError(),
9480 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9481 setImportDeclError(FromD, ErrOut);
9482 // Set the error for the mapped to Decl, which is in the "to" context.
9483 if (Pos != ImportedDecls.end())
9484 SharedState->setImportDeclError(Pos->second, ErrOut);
9485
9486 // Set the error for all nodes which have been created before we
9487 // recognized the error.
9488 for (const auto &Path : SavedImportPaths[FromD]) {
9489 // The import path contains import-dependency nodes first.
9490 // Save the node that was imported as dependency of the current node.
9491 Decl *PrevFromDi = FromD;
9492 for (Decl *FromDi : Path) {
9493 // Begin and end of the path equals 'FromD', skip it.
9494 if (FromDi == FromD)
9495 continue;
9496 // We should not set import error on a node and all following nodes in
9497 // the path if child import errors are ignored.
9498 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9499 PrevFromDi))
9500 break;
9501 PrevFromDi = FromDi;
9502 setImportDeclError(FromDi, ErrOut);
9503 //FIXME Should we remove these Decls from ImportedDecls?
9504 // Set the error for the mapped to Decl, which is in the "to" context.
9505 auto Ii = ImportedDecls.find(FromDi);
9506 if (Ii != ImportedDecls.end())
9507 SharedState->setImportDeclError(Ii->second, ErrOut);
9508 // FIXME Should we remove these Decls from the LookupTable,
9509 // and from ImportedFromDecls?
9510 }
9511 }
9512 SavedImportPaths.erase(FromD);
9513
9514 // Do not return ToDOrErr, error was taken out of it.
9515 return make_error<ASTImportError>(ErrOut);
9516 }
9517
9518 ToD = *ToDOrErr;
9519
9520 // FIXME: Handle the "already imported with error" case. We can get here
9521 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9522 // previously failed create was requested).
9523 // Later GetImportedOrCreateDecl can be updated to return the error.
9524 if (!ToD) {
9525 auto Err = getImportDeclErrorIfAny(FromD);
9526 assert(Err);
9527 return make_error<ASTImportError>(*Err);
9528 }
9529
9530 // We could import from the current TU without error. But previously we
9531 // already had imported a Decl as `ToD` from another TU (with another
9532 // ASTImporter object) and with an error.
9533 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9534 setImportDeclError(FromD, *Error);
9535 return make_error<ASTImportError>(*Error);
9536 }
9537 // Make sure that ImportImpl registered the imported decl.
9538 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9539 if (auto Error = ImportAttrs(ToD, FromD))
9540 return std::move(Error);
9541
9542 // Notify subclasses.
9543 Imported(FromD, ToD);
9544
9545 updateFlags(FromD, ToD);
9546 SavedImportPaths.erase(FromD);
9547 return ToDOrErr;
9548}
9549
9552 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9553}
9554
9556 if (!FromDC)
9557 return FromDC;
9558
9559 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9560 if (!ToDCOrErr)
9561 return ToDCOrErr.takeError();
9562 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9563
9564 // When we're using a record/enum/Objective-C class/protocol as a context, we
9565 // need it to have a definition.
9566 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9567 auto *FromRecord = cast<RecordDecl>(FromDC);
9568 if (ToRecord->isCompleteDefinition())
9569 return ToDC;
9570
9571 // If FromRecord is not defined we need to force it to be.
9572 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9573 // it will start the definition but we never finish it.
9574 // If there are base classes they won't be imported and we will
9575 // be missing anything that we inherit from those bases.
9576 if (FromRecord->getASTContext().getExternalSource() &&
9577 !FromRecord->isCompleteDefinition())
9578 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9579
9580 if (FromRecord->isCompleteDefinition())
9581 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9582 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9583 return std::move(Err);
9584 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9585 auto *FromEnum = cast<EnumDecl>(FromDC);
9586 if (ToEnum->isCompleteDefinition()) {
9587 // Do nothing.
9588 } else if (FromEnum->isCompleteDefinition()) {
9589 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9590 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9591 return std::move(Err);
9592 } else {
9593 CompleteDecl(ToEnum);
9594 }
9595 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9596 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9597 if (ToClass->getDefinition()) {
9598 // Do nothing.
9599 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9600 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9601 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9602 return std::move(Err);
9603 } else {
9604 CompleteDecl(ToClass);
9605 }
9606 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9607 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9608 if (ToProto->getDefinition()) {
9609 // Do nothing.
9610 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9611 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9612 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9613 return std::move(Err);
9614 } else {
9615 CompleteDecl(ToProto);
9616 }
9617 }
9618
9619 return ToDC;
9620}
9621
9623 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9624 return cast_or_null<Expr>(*ToSOrErr);
9625 else
9626 return ToSOrErr.takeError();
9627}
9628
9630 if (!FromS)
9631 return nullptr;
9632
9633 // Check whether we've already imported this statement.
9634 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9635 if (Pos != ImportedStmts.end())
9636 return Pos->second;
9637
9638 // Import the statement.
9639 ASTNodeImporter Importer(*this);
9640 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9641 if (!ToSOrErr)
9642 return ToSOrErr;
9643
9644 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9645 auto *FromE = cast<Expr>(FromS);
9646 // Copy ExprBitfields, which may not be handled in Expr subclasses
9647 // constructors.
9648 ToE->setValueKind(FromE->getValueKind());
9649 ToE->setObjectKind(FromE->getObjectKind());
9650 ToE->setDependence(FromE->getDependence());
9651 }
9652
9653 // Record the imported statement object.
9654 ImportedStmts[FromS] = *ToSOrErr;
9655 return ToSOrErr;
9656}
9657
9660 if (!FromNNS)
9661 return nullptr;
9662
9663 NestedNameSpecifier *Prefix = nullptr;
9664 if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
9665 return std::move(Err);
9666
9667 switch (FromNNS->getKind()) {
9669 assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.");
9670 return NestedNameSpecifier::Create(ToContext, Prefix,
9671 Import(FromNNS->getAsIdentifier()));
9672
9674 if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
9675 return NestedNameSpecifier::Create(ToContext, Prefix,
9676 cast<NamespaceDecl>(*NSOrErr));
9677 } else
9678 return NSOrErr.takeError();
9679
9681 if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
9682 return NestedNameSpecifier::Create(ToContext, Prefix,
9683 cast<NamespaceAliasDecl>(*NSADOrErr));
9684 else
9685 return NSADOrErr.takeError();
9686
9688 return NestedNameSpecifier::GlobalSpecifier(ToContext);
9689
9691 if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
9692 return NestedNameSpecifier::SuperSpecifier(ToContext,
9693 cast<CXXRecordDecl>(*RDOrErr));
9694 else
9695 return RDOrErr.takeError();
9696
9699 if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) {
9700 bool TSTemplate =
9702 return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
9703 *TyOrErr);
9704 } else {
9705 return TyOrErr.takeError();
9706 }
9707 }
9708
9709 llvm_unreachable("Invalid nested name specifier kind");
9710}
9711
9714 // Copied from NestedNameSpecifier mostly.
9716 NestedNameSpecifierLoc NNS = FromNNS;
9717
9718 // Push each of the nested-name-specifiers's onto a stack for
9719 // serialization in reverse order.
9720 while (NNS) {
9721 NestedNames.push_back(NNS);
9722 NNS = NNS.getPrefix();
9723 }
9724
9726
9727 while (!NestedNames.empty()) {
9728 NNS = NestedNames.pop_back_val();
9729 NestedNameSpecifier *Spec = nullptr;
9730 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
9731 return std::move(Err);
9732
9734
9735 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
9736 if (Kind != NestedNameSpecifier::Super) {
9737 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
9738 return std::move(Err);
9739
9740 if (Kind != NestedNameSpecifier::Global)
9741 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
9742 return std::move(Err);
9743 }
9744
9745 switch (Kind) {
9747 Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc,
9748 ToLocalEndLoc);
9749 break;
9750
9752 Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc,
9753 ToLocalEndLoc);
9754 break;
9755
9757 Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(),
9758 ToLocalBeginLoc, ToLocalEndLoc);
9759 break;
9760
9763 SourceLocation ToTLoc;
9764 if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
9765 return std::move(Err);
9767 QualType(Spec->getAsType(), 0), ToTLoc);
9769 // ToLocalBeginLoc is here the location of the 'template' keyword.
9770 Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
9771 ToLocalEndLoc);
9772 else
9773 // No location for 'template' keyword here.
9774 Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(),
9775 ToLocalEndLoc);
9776 break;
9777 }
9778
9780 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
9781 break;
9782
9784 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
9785 if (!ToSourceRangeOrErr)
9786 return ToSourceRangeOrErr.takeError();
9787
9788 Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(),
9789 ToSourceRangeOrErr->getBegin(),
9790 ToSourceRangeOrErr->getEnd());
9791 }
9792 }
9793 }
9794
9795 return Builder.getWithLocInContext(getToContext());
9796}
9797
9799 switch (From.getKind()) {
9801 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
9802 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
9803 else
9804 return ToTemplateOrErr.takeError();
9805
9808 UnresolvedSet<2> ToTemplates;
9809 for (auto *I : *FromStorage) {
9810 if (auto ToOrErr = Import(I))
9811 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
9812 else
9813 return ToOrErr.takeError();
9814 }
9815 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
9816 ToTemplates.end());
9817 }
9818
9821 auto DeclNameOrErr = Import(FromStorage->getDeclName());
9822 if (!DeclNameOrErr)
9823 return DeclNameOrErr.takeError();
9824 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
9825 }
9826
9829 auto QualifierOrErr = Import(QTN->getQualifier());
9830 if (!QualifierOrErr)
9831 return QualifierOrErr.takeError();
9832 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
9833 if (!TNOrErr)
9834 return TNOrErr.takeError();
9835 return ToContext.getQualifiedTemplateName(
9836 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
9837 }
9838
9841 auto QualifierOrErr = Import(DTN->getQualifier());
9842 if (!QualifierOrErr)
9843 return QualifierOrErr.takeError();
9844
9845 if (DTN->isIdentifier()) {
9846 return ToContext.getDependentTemplateName(*QualifierOrErr,
9847 Import(DTN->getIdentifier()));
9848 }
9849
9850 return ToContext.getDependentTemplateName(*QualifierOrErr,
9851 DTN->getOperator());
9852 }
9853
9857 auto ReplacementOrErr = Import(Subst->getReplacement());
9858 if (!ReplacementOrErr)
9859 return ReplacementOrErr.takeError();
9860
9861 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
9862 if (!AssociatedDeclOrErr)
9863 return AssociatedDeclOrErr.takeError();
9864
9865 return ToContext.getSubstTemplateTemplateParm(
9866 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
9867 Subst->getPackIndex());
9868 }
9869
9873 ASTNodeImporter Importer(*this);
9874 auto ArgPackOrErr =
9875 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
9876 if (!ArgPackOrErr)
9877 return ArgPackOrErr.takeError();
9878
9879 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
9880 if (!AssociatedDeclOrErr)
9881 return AssociatedDeclOrErr.takeError();
9882
9883 return ToContext.getSubstTemplateTemplateParmPack(
9884 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
9885 SubstPack->getFinal());
9886 }
9888 auto UsingOrError = Import(From.getAsUsingShadowDecl());
9889 if (!UsingOrError)
9890 return UsingOrError.takeError();
9891 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
9892 }
9893 }
9894
9895 llvm_unreachable("Invalid template name kind");
9896}
9897
9899 if (FromLoc.isInvalid())
9900 return SourceLocation{};
9901
9902 SourceManager &FromSM = FromContext.getSourceManager();
9903 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
9904
9905 std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
9906 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
9907 if (!ToFileIDOrErr)
9908 return ToFileIDOrErr.takeError();
9909 SourceManager &ToSM = ToContext.getSourceManager();
9910 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
9911}
9912
9914 SourceLocation ToBegin, ToEnd;
9915 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
9916 return std::move(Err);
9917 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
9918 return std::move(Err);
9919
9920 return SourceRange(ToBegin, ToEnd);
9921}
9922
9924 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
9925 if (Pos != ImportedFileIDs.end())
9926 return Pos->second;
9927
9928 SourceManager &FromSM = FromContext.getSourceManager();
9929 SourceManager &ToSM = ToContext.getSourceManager();
9930 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
9931
9932 // Map the FromID to the "to" source manager.
9933 FileID ToID;
9934 if (FromSLoc.isExpansion()) {
9935 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
9936 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
9937 if (!ToSpLoc)
9938 return ToSpLoc.takeError();
9939 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
9940 if (!ToExLocS)
9941 return ToExLocS.takeError();
9942 unsigned ExLength = FromSM.getFileIDSize(FromID);
9943 SourceLocation MLoc;
9944 if (FromEx.isMacroArgExpansion()) {
9945 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
9946 } else {
9947 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
9948 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
9949 FromEx.isExpansionTokenRange());
9950 else
9951 return ToExLocE.takeError();
9952 }
9953 ToID = ToSM.getFileID(MLoc);
9954 } else {
9955 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
9956
9957 if (!IsBuiltin && !Cache->BufferOverridden) {
9958 // Include location of this file.
9959 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
9960 if (!ToIncludeLoc)
9961 return ToIncludeLoc.takeError();
9962
9963 // Every FileID that is not the main FileID needs to have a valid include
9964 // location so that the include chain points to the main FileID. When
9965 // importing the main FileID (which has no include location), we need to
9966 // create a fake include location in the main file to keep this property
9967 // intact.
9968 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
9969 if (FromID == FromSM.getMainFileID())
9970 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
9971
9972 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
9973 // FIXME: We probably want to use getVirtualFile(), so we don't hit the
9974 // disk again
9975 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
9976 // than mmap the files several times.
9977 auto Entry =
9978 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
9979 // FIXME: The filename may be a virtual name that does probably not
9980 // point to a valid file and we get no Entry here. In this case try with
9981 // the memory buffer below.
9982 if (Entry)
9983 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
9984 FromSLoc.getFile().getFileCharacteristic());
9985 }
9986 }
9987
9988 if (ToID.isInvalid() || IsBuiltin) {
9989 // FIXME: We want to re-use the existing MemoryBuffer!
9990 std::optional<llvm::MemoryBufferRef> FromBuf =
9991 Cache->getBufferOrNone(FromContext.getDiagnostics(),
9992 FromSM.getFileManager(), SourceLocation{});
9993 if (!FromBuf)
9994 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
9995
9996 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
9997 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
9998 FromBuf->getBufferIdentifier());
9999 ToID = ToSM.createFileID(std::move(ToBuf),
10000 FromSLoc.getFile().getFileCharacteristic());
10001 }
10002 }
10003
10004 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10005
10006 ImportedFileIDs[FromID] = ToID;
10007 return ToID;
10008}
10009
10011 ExpectedExpr ToExprOrErr = Import(From->getInit());
10012 if (!ToExprOrErr)
10013 return ToExprOrErr.takeError();
10014
10015 auto LParenLocOrErr = Import(From->getLParenLoc());
10016 if (!LParenLocOrErr)
10017 return LParenLocOrErr.takeError();
10018
10019 auto RParenLocOrErr = Import(From->getRParenLoc());
10020 if (!RParenLocOrErr)
10021 return RParenLocOrErr.takeError();
10022
10023 if (From->isBaseInitializer()) {
10024 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10025 if (!ToTInfoOrErr)
10026 return ToTInfoOrErr.takeError();
10027
10028 SourceLocation EllipsisLoc;
10029 if (From->isPackExpansion())
10030 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10031 return std::move(Err);
10032
10033 return new (ToContext) CXXCtorInitializer(
10034 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10035 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10036 } else if (From->isMemberInitializer()) {
10037 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10038 if (!ToFieldOrErr)
10039 return ToFieldOrErr.takeError();
10040
10041 auto MemberLocOrErr = Import(From->getMemberLocation());
10042 if (!MemberLocOrErr)
10043 return MemberLocOrErr.takeError();
10044
10045 return new (ToContext) CXXCtorInitializer(
10046 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10047 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10048 } else if (From->isIndirectMemberInitializer()) {
10049 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10050 if (!ToIFieldOrErr)
10051 return ToIFieldOrErr.takeError();
10052
10053 auto MemberLocOrErr = Import(From->getMemberLocation());
10054 if (!MemberLocOrErr)
10055 return MemberLocOrErr.takeError();
10056
10057 return new (ToContext) CXXCtorInitializer(
10058 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10059 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10060 } else if (From->isDelegatingInitializer()) {
10061 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10062 if (!ToTInfoOrErr)
10063 return ToTInfoOrErr.takeError();
10064
10065 return new (ToContext)
10066 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10067 *ToExprOrErr, *RParenLocOrErr);
10068 } else {
10069 // FIXME: assert?
10070 return make_error<ASTImportError>();
10071 }
10072}
10073
10076 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10077 if (Pos != ImportedCXXBaseSpecifiers.end())
10078 return Pos->second;
10079
10080 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10081 if (!ToSourceRange)
10082 return ToSourceRange.takeError();
10084 if (!ToTSI)
10085 return ToTSI.takeError();
10086 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10087 if (!ToEllipsisLoc)
10088 return ToEllipsisLoc.takeError();
10089 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10090 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10091 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10092 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10093 return Imported;
10094}
10095
10097 ASTNodeImporter Importer(*this);
10098 return Importer.ImportAPValue(FromValue);
10099}
10100
10102 ExpectedDecl ToOrErr = Import(From);
10103 if (!ToOrErr)
10104 return ToOrErr.takeError();
10105 Decl *To = *ToOrErr;
10106
10107 auto *FromDC = cast<DeclContext>(From);
10108 ASTNodeImporter Importer(*this);
10109
10110 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10111 if (!ToRecord->getDefinition()) {
10112 return Importer.ImportDefinition(
10113 cast<RecordDecl>(FromDC), ToRecord,
10115 }
10116 }
10117
10118 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10119 if (!ToEnum->getDefinition()) {
10120 return Importer.ImportDefinition(
10121 cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10122 }
10123 }
10124
10125 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10126 if (!ToIFace->getDefinition()) {
10127 return Importer.ImportDefinition(
10128 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10130 }
10131 }
10132
10133 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10134 if (!ToProto->getDefinition()) {
10135 return Importer.ImportDefinition(
10136 cast<ObjCProtocolDecl>(FromDC), ToProto,
10138 }
10139 }
10140
10141 return Importer.ImportDeclContext(FromDC, true);
10142}
10143
10145 if (!FromName)
10146 return DeclarationName{};
10147
10148 switch (FromName.getNameKind()) {
10150 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10151
10155 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10156 return DeclarationName(*ToSelOrErr);
10157 else
10158 return ToSelOrErr.takeError();
10159
10161 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10162 return ToContext.DeclarationNames.getCXXConstructorName(
10163 ToContext.getCanonicalType(*ToTyOrErr));
10164 else
10165 return ToTyOrErr.takeError();
10166 }
10167
10169 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10170 return ToContext.DeclarationNames.getCXXDestructorName(
10171 ToContext.getCanonicalType(*ToTyOrErr));
10172 else
10173 return ToTyOrErr.takeError();
10174 }
10175
10177 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10179 cast<TemplateDecl>(*ToTemplateOrErr));
10180 else
10181 return ToTemplateOrErr.takeError();
10182 }
10183
10185 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10187 ToContext.getCanonicalType(*ToTyOrErr));
10188 else
10189 return ToTyOrErr.takeError();
10190 }
10191
10193 return ToContext.DeclarationNames.getCXXOperatorName(
10194 FromName.getCXXOverloadedOperator());
10195
10198 Import(FromName.getCXXLiteralIdentifier()));
10199
10201 // FIXME: STATICS!
10203 }
10204
10205 llvm_unreachable("Invalid DeclarationName Kind!");
10206}
10207
10209 if (!FromId)
10210 return nullptr;
10211
10212 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10213
10214 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10215 ToId->setBuiltinID(FromId->getBuiltinID());
10216
10217 return ToId;
10218}
10219
10221 if (FromSel.isNull())
10222 return Selector{};
10223
10225 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10226 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10227 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10228 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10229}
10230
10234 llvm::Error Err = llvm::Error::success();
10235 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10236 for (unsigned Idx = 0; Idx < Size; Idx++) {
10237 APValue Tmp = importChecked(Err, From[Idx]);
10238 To[Idx] = Tmp;
10239 }
10240 };
10241 switch (FromValue.getKind()) {
10242 case APValue::None:
10244 case APValue::Int:
10245 case APValue::Float:
10249 Result = FromValue;
10250 break;
10251 case APValue::Vector: {
10252 Result.MakeVector();
10254 Result.setVectorUninit(FromValue.getVectorLength());
10255 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10256 Elts.data(), FromValue.getVectorLength());
10257 break;
10258 }
10259 case APValue::Array:
10260 Result.MakeArray(FromValue.getArrayInitializedElts(),
10261 FromValue.getArraySize());
10262 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10263 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10264 FromValue.getArrayInitializedElts());
10265 break;
10266 case APValue::Struct:
10267 Result.MakeStruct(FromValue.getStructNumBases(),
10268 FromValue.getStructNumFields());
10269 ImportLoop(
10270 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10271 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10272 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10273 break;
10274 case APValue::Union: {
10275 Result.MakeUnion();
10276 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10277 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10278 if (Err)
10279 return std::move(Err);
10280 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10281 break;
10282 }
10284 Result.MakeAddrLabelDiff();
10285 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10286 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10287 if (Err)
10288 return std::move(Err);
10289 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10290 cast<AddrLabelExpr>(ImpRHS));
10291 break;
10292 }
10294 const Decl *ImpMemPtrDecl =
10295 importChecked(Err, FromValue.getMemberPointerDecl());
10296 if (Err)
10297 return std::move(Err);
10299 Result.setMemberPointerUninit(
10300 cast<const ValueDecl>(ImpMemPtrDecl),
10302 FromValue.getMemberPointerPath().size());
10304 Result.getMemberPointerPath();
10305 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10306 Idx++) {
10307 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10308 if (Err)
10309 return std::move(Err);
10310 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10311 }
10312 break;
10313 }
10314 case APValue::LValue:
10316 QualType FromElemTy;
10317 if (FromValue.getLValueBase()) {
10318 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10319 "in C++20 dynamic allocation are transient so they shouldn't "
10320 "appear in the AST");
10321 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10322 if (const auto *E =
10323 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10324 FromElemTy = E->getType();
10325 const Expr *ImpExpr = importChecked(Err, E);
10326 if (Err)
10327 return std::move(Err);
10328 Base = APValue::LValueBase(ImpExpr,
10329 FromValue.getLValueBase().getCallIndex(),
10330 FromValue.getLValueBase().getVersion());
10331 } else {
10332 FromElemTy =
10333 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10334 const Decl *ImpDecl = importChecked(
10335 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10336 if (Err)
10337 return std::move(Err);
10338 Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10339 FromValue.getLValueBase().getCallIndex(),
10340 FromValue.getLValueBase().getVersion());
10341 }
10342 } else {
10343 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10344 const Type *ImpTypeInfo = importChecked(
10345 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10346 QualType ImpType =
10347 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10348 if (Err)
10349 return std::move(Err);
10351 ImpType);
10352 }
10353 }
10354 CharUnits Offset = FromValue.getLValueOffset();
10355 unsigned PathLength = FromValue.getLValuePath().size();
10356 Result.MakeLValue();
10357 if (FromValue.hasLValuePath()) {
10358 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10359 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10360 FromValue.isNullPointer());
10362 FromValue.getLValuePath();
10363 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10364 if (FromElemTy->isRecordType()) {
10365 const Decl *FromDecl =
10366 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10367 const Decl *ImpDecl = importChecked(Err, FromDecl);
10368 if (Err)
10369 return std::move(Err);
10370 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10371 FromElemTy = Importer.FromContext.getRecordType(RD);
10372 else
10373 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10375 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10376 } else {
10377 FromElemTy =
10378 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10379 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10380 FromPath[LoopIdx].getAsArrayIndex());
10381 }
10382 }
10383 } else
10384 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10385 FromValue.isNullPointer());
10386 }
10387 if (Err)
10388 return std::move(Err);
10389 return Result;
10390}
10391
10393 DeclContext *DC,
10394 unsigned IDNS,
10395 NamedDecl **Decls,
10396 unsigned NumDecls) {
10397 if (ODRHandling == ODRHandlingType::Conservative)
10398 // Report error at any name conflict.
10399 return make_error<ASTImportError>(ASTImportError::NameConflict);
10400 else
10401 // Allow to create the new Decl with the same name.
10402 return Name;
10403}
10404
10406 if (LastDiagFromFrom)
10408 FromContext.getDiagnostics());
10409 LastDiagFromFrom = false;
10410 return ToContext.getDiagnostics().Report(Loc, DiagID);
10411}
10412
10414 if (!LastDiagFromFrom)
10416 ToContext.getDiagnostics());
10417 LastDiagFromFrom = true;
10418 return FromContext.getDiagnostics().Report(Loc, DiagID);
10419}
10420
10422 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10423 if (!ID->getDefinition())
10424 ID->startDefinition();
10425 }
10426 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10427 if (!PD->getDefinition())
10428 PD->startDefinition();
10429 }
10430 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10431 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10432 TD->startDefinition();
10433 TD->setCompleteDefinition(true);
10434 }
10435 }
10436 else {
10437 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10438 }
10439}
10440
10442 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
10443 assert((Pos == ImportedDecls.end() || Pos->second == To) &&
10444 "Try to import an already imported Decl");
10445 if (Pos != ImportedDecls.end())
10446 return Pos->second;
10447 ImportedDecls[From] = To;
10448 // This mapping should be maintained only in this function. Therefore do not
10449 // check for additional consistency.
10450 ImportedFromDecls[To] = From;
10451 // In the case of TypedefNameDecl we create the Decl first and only then we
10452 // import and set its DeclContext. So, the DC is still not set when we reach
10453 // here from GetImportedOrCreateDecl.
10454 if (To->getDeclContext())
10455 AddToLookupTable(To);
10456 return To;
10457}
10458
10459std::optional<ASTImportError>
10461 auto Pos = ImportDeclErrors.find(FromD);
10462 if (Pos != ImportDeclErrors.end())
10463 return Pos->second;
10464 else
10465 return std::nullopt;
10466}
10467
10469 auto InsertRes = ImportDeclErrors.insert({From, Error});
10470 (void)InsertRes;
10471 // Either we set the error for the first time, or we already had set one and
10472 // now we want to set the same error.
10473 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10474}
10475
10477 bool Complain) {
10478 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10479 ImportedTypes.find(From.getTypePtr());
10480 if (Pos != ImportedTypes.end()) {
10481 if (ExpectedType ToFromOrErr = Import(From)) {
10482 if (ToContext.hasSameType(*ToFromOrErr, To))
10483 return true;
10484 } else {
10485 llvm::consumeError(ToFromOrErr.takeError());
10486 }
10487 }
10488
10489 StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
10490 getStructuralEquivalenceKind(*this), false,
10491 Complain);
10492 return Ctx.IsEquivalent(From, To);
10493}
Defines the clang::ASTContext interface.
ASTImporterLookupTable & LT
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static auto getTemplateDefinition(T *D) -> T *
static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D)
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
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.
int Category
Definition: Format.cpp:2974
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
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.
const NamedDecl * FromDecl
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:974
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:994
const FieldDecl * getUnionField() const
Definition: APValue.h:563
unsigned getStructNumFields() const
Definition: APValue.h:542
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:395
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:979
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1064
unsigned getArrayInitializedElts() const
Definition: APValue.h:529
unsigned getStructNumBases() const
Definition: APValue.h:538
bool hasLValuePath() const
Definition: APValue.cpp:989
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1057
APValue & getUnionValue()
Definition: APValue.h:567
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:583
CharUnits & getLValueOffset()
Definition: APValue.cpp:984
unsigned getVectorLength() const
Definition: APValue.h:505
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1071
unsigned getArraySize() const
Definition: APValue.h:533
@ 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:1010
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:579
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
SourceManager & getSourceManager()
Definition: ASTContext.h:705
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1073
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType getParenType(QualType NamedType) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) const
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:648
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
QualType getRecordType(const RecordDecl *Decl) const
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes, bool OrNull, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2574
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2590
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1590
IdentifierTable & Idents
Definition: ASTContext.h:644
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:775
SelectorTable & Selectors
Definition: ASTContext.h:645
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingEnumDecl *Pattern)
Remember that the using enum decl Inst is an instantiation of the using enum decl Pattern of a class ...
UsingEnumDecl * getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst)
If the given using-enum decl Inst is an instantiation of another using-enum decl, return it.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl, unsigned Index, bool Final, const TemplateArgument &ArgPack)
Retrieve a.
CanQualType CharTy
Definition: ASTContext.h:1093
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2156
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
CanQualType SignedCharTy
Definition: ASTContext.h:1100
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
CanQualType VoidTy
Definition: ASTContext.h:1091
CanQualType UnsignedCharTy
Definition: ASTContext.h:1101
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1568
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< QualType > Expansions={}, int Index=-1) const
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
DiagnosticsEngine & getDiagnostics() const
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1188
BuiltinTemplateDecl * getTypePackElementDecl() const
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
CanQualType WCharTy
Definition: ASTContext.h:1094
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
Retrieve a substitution-result type.
unsigned char getFixedPointScale(QualType Ty) const
QualType getIncompleteArrayType(QualType EltTy, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type.
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
QualType getTypeOfExprType(Expr *E, TypeOfKind Kind) const
C23 feature and GCC extension.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
std::string toString() const
Definition: ASTImporter.cpp:86
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
void update(NamedDecl *ND, DeclContext *OldDC)
void updateForced(NamedDecl *ND, DeclContext *OldDC)
bool hasCycleAtBack() const
Returns true if the last element can be found earlier in the path.
Definition: ASTImporter.h:164
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Definition: ASTImporter.h:178
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.
Definition: ASTImporter.h:523
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:538
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:520
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.
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.
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
Definition: ASTImporter.h:270
std::optional< DeclT * > getImportedFromDecl(const DeclT *ToD) const
Return the declaration in the "from" context from which the declaration in the "to" context was impor...
Definition: ASTImporter.h:371
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
static std::optional< unsigned > getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
Definition: ASTImporter.h:308
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:563
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
Definition: ASTImporter.h:548
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
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...
Definition: ASTImporter.h:298
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)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
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)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
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 VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
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)
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)
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)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *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)
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)
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)
bool hasReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the given function has a return type that contains a reference (in any way) t...
ASTNodeImporter(ASTImporter &Importer)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
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 ImportTemplateParameterLists(const DeclaratorDecl *FromD, DeclaratorDecl *ToD)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
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)
ExpectedStmt VisitBreakStmt(BreakStmt *S)
SourceLocation getColonLoc() const
Definition: Expr.h:4169
SourceLocation getQuestionLoc() const
Definition: Expr.h:4168
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:4338
SourceLocation getAmpAmpLoc() const
Definition: Expr.h:4353
SourceLocation getLabelLoc() const
Definition: Expr.h:4355
LabelDecl * getLabel() const
Definition: Expr.h:4361
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3294
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5564
Represents a loop initializing the elements of an array.
Definition: Expr.h:5511
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition: Expr.h:5526
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition: Expr.h:5531
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3684
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2664
SourceLocation getRBracketLoc() const
Definition: Expr.h:2712
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
Definition: Expr.h:2693
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2846
uint64_t getValue() const
Definition: ExprCXX.h:2892
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2884
ArrayTypeTrait getTrait() const
Definition: ExprCXX.h:2886
Expr * getDimensionExpression() const
Definition: ExprCXX.h:2894
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition: ExprCXX.h:2890
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2883
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3514
QualType getElementType() const
Definition: Type.h:3526
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:6437
Expr ** getSubExprs()
Definition: Expr.h:6514
SourceLocation getRParenLoc() const
Definition: Expr.h:6542
static unsigned getNumSubExprs(AtomicOp Op)
Determine the number of arguments the specified atomic builtin should have.
Definition: Expr.cpp:4953
AtomicOp getOp() const
Definition: Expr.h:6501
SourceLocation getBuiltinLoc() const
Definition: Expr.h:6541
Attr - This represents one attribute.
Definition: Attr.h:42
attr::Kind getKind() const
Definition: Attr.h:88
void setPackExpansion(bool PE)
Definition: Attr.h:104
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition: Attr.h:102
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2080
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:425
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5600
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5977
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3417
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3142
shadow_range shadows() const
Definition: DeclCXX.h:3483
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4241
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
Definition: Expr.h:4295
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Definition: Expr.h:4279
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
Definition: Expr.h:4283
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression which will be evaluated if the condition evaluates to true; th...
Definition: Expr.h:4288
Expr * getCommon() const
getCommon - Return the common expression, written to the left of the condition.
Definition: Expr.h:4276
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3840
Expr * getLHS() const
Definition: Expr.h:3889
SourceLocation getOperatorLoc() const
Definition: Expr.h:3881
Expr * getRHS() const
Definition: Expr.h:3891
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:4781
Opcode getOpcode() const
Definition: Expr.h:3884
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:4046
A binding in a decomposition declaration.
Definition: DeclCXX.h:4107
ValueDecl * getDecomposedDecl() const
Get the decomposition declaration that this binding represents a decomposition of.
Definition: DeclCXX.h:4135
Expr * getBinding() const
Get the expression to which this declaration is bound.
Definition: DeclCXX.h:4131
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:4144
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4150
A fixed int type of a specified bitwidth.
Definition: Type.h:7238
Pointer to a block type.
Definition: Type.h:3345
BreakStmt - This represents a break.
Definition: Stmt.h:2980
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5258
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: Type.h:2977
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:2105
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:1485
CXXTemporary * getTemporary()
Definition: ExprCXX.h:1503
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1048
const Expr * getSubExpr() const
Definition: ExprCXX.h:1507
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition: ExprCXX.h:732
bool getValue() const
Definition: ExprCXX.h:737
SourceLocation getLocation() const
Definition: ExprCXX.h:743
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:826
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1540
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1708
void setIsImmediateEscalating(bool Set)
Definition: ExprCXX.h:1702
bool isElidable() const
Whether this construction is elidable.
Definition: ExprCXX.h:1609
bool hadMultipleCandidates() const
Whether the referred constructor was resolved from an overloaded set having size greater than 1.
Definition: ExprCXX.h:1614
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:1110
arg_range arguments()
Definition: ExprCXX.h:1664
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1633
bool isImmediateEscalating() const
Definition: ExprCXX.h:1698
bool requiresZeroInitialization() const
Whether this construction first requires zero-initialization before the initializer is called.
Definition: ExprCXX.h:1642
SourceLocation getLocation() const
Definition: ExprCXX.h:1605
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1603
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1622
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1680
CXXConstructionKind getConstructionKind() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1651
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2862
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2300
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2440
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2400
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2502
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2499
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2410
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2498
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2405
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2434
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2378
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2372
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2384
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2460
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2454
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2426
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1952
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1264
SourceLocation getUsedLocation() const
Retrieve the location where this default argument was actually used.
Definition: ExprCXX.h:1338
const ParmVarDecl * getParam() const
Definition: ExprCXX.h:1306
const DeclContext * getUsedContext() const
Definition: ExprCXX.h:1334
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:969
bool hasRewrittenInit() const
Definition: ExprCXX.h:1309
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1371
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:1023
const DeclContext * getUsedContext() const
Definition: ExprCXX.h:1428
const Expr * getRewrittenExpr() const
Retrieve the initializing expression with evaluated immediate calls, if any.
Definition: ExprCXX.h:1416
bool hasRewrittenInit() const
Definition: ExprCXX.h:1400
FieldDecl * getField()
Get the field whose initializer will be used.
Definition: ExprCXX.h:1405
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:1435
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2491
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2530
bool isArrayForm() const
Definition: ExprCXX.h:2517
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:2541
bool isGlobalDelete() const
Definition: ExprCXX.h:2516
Expr * getArgument()
Definition: ExprCXX.h:2532
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2526
bool isArrayFormAsWritten() const
Definition: ExprCXX.h:2518
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3652
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition: ExprCXX.h:3755
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition: ExprCXX.h:3758
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:1484
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3810
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: ExprCXX.h:3802
const DeclarationNameInfo & getMemberNameInfo() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3789
bool hasExplicitTemplateArgs() const
Determines whether this member expression actually had a C++ template argument list explicitly specif...
Definition: ExprCXX.h:3829
SourceLocation getMemberLoc() const
Definition: ExprCXX.h:3798
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3818
DeclarationName getMember() const
Retrieve the name of the member that this expression refers to.
Definition: ExprCXX.h:3794
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:3782
Expr * getBase() const
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3746
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the member name, with source location information.
Definition: ExprCXX.h:3769
bool isImplicitAccess() const
True if this is an implicit access, i.e.
Definition: ExprCXX.h:3738
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3857
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:2870
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:738
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4798
UnresolvedLookupExpr * getCallee() const
Definition: ExprCXX.h:4829
std::optional< unsigned > getNumExpansions() const
Definition: ExprCXX.h:4854
Expr * getRHS() const
Definition: ExprCXX.h:4833
SourceLocation getLParenLoc() const
Definition: ExprCXX.h:4849
SourceLocation getEllipsisLoc() const
Definition: ExprCXX.h:4851
Expr * getLHS() const
Definition: ExprCXX.h:4832
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:4850
BinaryOperatorKind getOperator() const
Definition: ExprCXX.h:4852
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:135
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:852
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1731
bool constructsVBase() const
Determine whether this constructor is actually constructing a base class (rather than a complete obje...
Definition: ExprCXX.h:1772
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition: ExprCXX.h:1768
SourceLocation getLocation() const LLVM_READONLY
Definition: ExprCXX.h:1784
bool inheritedFromVBase() const
Determine whether the inherited constructor is inherited from a virtual base of the object we constru...
Definition: ExprCXX.h:1782
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
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:626
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2509
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2534
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2156
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:403
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:410
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:406
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2234
SourceRange getDirectInitRange() const
Definition: ExprCXX.h:2474
llvm::iterator_range< arg_iterator > placement_arguments()
Definition: ExprCXX.h:2437
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:2347
CXXNewInitializationStyle getInitializationStyle() const
The kind of initializer this new-expression has.
Definition: ExprCXX.h:2401
bool passAlignment() const
Indicates whether the required alignment should be implicitly passed to the allocation function.
Definition: ExprCXX.h:2425
FunctionDecl * getOperatorDelete() const
Definition: ExprCXX.h:2339
unsigned getNumPlacementArgs() const
Definition: ExprCXX.h:2372
TypeSourceInfo * getAllocatedTypeSourceInfo() const
Definition: ExprCXX.h:2316
SourceRange getSourceRange() const
Definition: ExprCXX.h:2475
SourceRange getTypeIdParens() const
Definition: ExprCXX.h:2390
bool doesUsualArrayDeleteWantSize() const
Answers whether the usual array deallocation function for the allocated type expects the size of the ...
Definition: ExprCXX.h:2430
FunctionDecl * getOperatorNew() const
Definition: ExprCXX.h:2337
bool isGlobalNew() const
Definition: ExprCXX.h:2395
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, 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:245
Expr * getInitializer()
The initializer of this new-expression.
Definition: ExprCXX.h:2407
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4095
bool getValue() const
Definition: ExprCXX.h:4118
SourceLocation getEndLoc() const
Definition: ExprCXX.h:4115
Expr * getOperand() const
Definition: ExprCXX.h:4112
SourceLocation getBeginLoc() const
Definition: ExprCXX.h:4114
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
SourceLocation getLocation() const
Definition: ExprCXX.h:779
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:562
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2610
TypeSourceInfo * getDestroyedTypeInfo() const
Retrieve the source location information for the type being destroyed.
Definition: ExprCXX.h:2704
bool isArrow() const
Determine whether this pseudo-destructor expression was written using an '->' (otherwise,...
Definition: ExprCXX.h:2674
TypeSourceInfo * getScopeTypeInfo() const
Retrieve the scope type in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2688
SourceLocation getTildeLoc() const
Retrieve the location of the '~'.
Definition: ExprCXX.h:2695
NestedNameSpecifierLoc getQualifierLoc() const
Retrieves the nested-name-specifier that qualifies the type name, with source-location information.
Definition: ExprCXX.h:2663
SourceLocation getDestroyedTypeLoc() const
Retrieve the starting location of the type being destroyed.
Definition: ExprCXX.h:2719
SourceLocation getColonColonLoc() const
Retrieve the location of the '::' in a qualified pseudo-destructor expression.
Definition: ExprCXX.h:2692
SourceLocation getOperatorLoc() const
Retrieve the location of the '.' or '->' operator.
Definition: ExprCXX.h:2677
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:2711
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:540
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition: DeclCXX.cpp:1876
method_range methods() const
Definition: DeclCXX.h:661
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:564
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:148
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Definition: DeclCXX.cpp:1905
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1888
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1901
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1691
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1883
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1916
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:531
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:803
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition: ExprCXX.h:301
bool isReversed() const
Determine whether this expression was rewritten in reverse form.
Definition: ExprCXX.h:319
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2175
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2194
SourceLocation getRParenLoc() const
Definition: ExprCXX.h:2198
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:712
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1879
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:1076
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:1908
Represents a C++ temporary.
Definition: ExprCXX.h:1453
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1464
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1043
Represents the this expression in C++.
Definition: ExprCXX.h:1148
bool isImplicit() const
Definition: ExprCXX.h:1171
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1519
SourceLocation getLocation() const
Definition: ExprCXX.h:1165
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1202
const Expr * getSubExpr() const
Definition: ExprCXX.h:1222
SourceLocation getThrowLoc() const
Definition: ExprCXX.h:1225
bool isThrownVariableInScope() const
Determines whether the variable thrown by this expression (if any!) is within the innermost try block...
Definition: ExprCXX.h:1232
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:25
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:845
bool isTypeOperand() const
Definition: ExprCXX.h:881
TypeSourceInfo * getTypeOperandSourceInfo() const
Retrieve source information for the type operand.
Definition: ExprCXX.h:888
Expr * getExprOperand() const
Definition: ExprCXX.h:892
SourceRange getSourceRange() const LLVM_READONLY
Definition: ExprCXX.h:899
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3526
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition: ExprCXX.h:3570
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition: ExprCXX.h:3581
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1422
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition: ExprCXX.h:3564
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition: ExprCXX.h:3575
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition: ExprCXX.h:3584
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2820
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:1494
ADLCallKind getADLCallKind() const
Definition: Expr.h:2974
Expr * getCallee()
Definition: Expr.h:2970
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3102
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2998
arg_range arguments()
Definition: Expr.h:3059
SourceLocation getRParenLoc() const
Definition: Expr.h:3130
CaseStmt - Represent a case statement.
Definition: Stmt.h:1801
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1220
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3483
path_iterator path_begin()
Definition: Expr.h:3553
CastKind getCastKind() const
Definition: Expr.h:3527
path_iterator path_end()
Definition: Expr.h:3554
FPOptionsOverride getFPFeatures() const
Definition: Expr.h:3598
Expr * getSubExpr()
Definition: Expr.h:3533
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
SourceLocation getLocation() const
Definition: Expr.h:1602
unsigned getValue() const
Definition: Expr.h:1610
CharacterLiteralKind getKind() const
Definition: Expr.h:1603
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:4558
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4605
Expr * getLHS() const
Definition: Expr.h:4600
bool isConditionDependent() const
Definition: Expr.h:4588
bool isConditionTrue() const
isConditionTrue - Return whether the condition is true (i.e.
Definition: Expr.h:4581
Expr * getRHS() const
Definition: Expr.h:4602
SourceLocation getRParenLoc() const
Definition: Expr.h:4608
Expr * getCond() const
Definition: Expr.h:4598
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Get the template arguments as written.
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.
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
SourceLocation getExternLoc() const
Gets the location of the extern keyword, if present.
void setTypeAsWritten(TypeSourceInfo *T)
Sets the type of this specialization as it was written by the user.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
SourceLocation getTemplateKeywordLoc() const
Gets the location of the template keyword, if present.
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 setExternLoc(SourceLocation Loc)
Sets the location of the extern keyword.
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,...
Complex values, per C99 6.2.5p11.
Definition: Type.h:3082
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4088
QualType getComputationLHSType() const
Definition: Expr.h:4122
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:4803
QualType getComputationResultType() const
Definition: Expr.h:4125
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3413
SourceLocation getLParenLoc() const
Definition: Expr.h:3443
bool isFileScope() const
Definition: Expr.h:3440
const Expr * getInitializer() const
Definition: Expr.h:3436
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:3446
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:383
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:128
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:167
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:199
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:171
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:203
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:93
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:207
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:177
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4179
Expr * getLHS() const
Definition: Expr.h:4213
Expr * getCond() const
getCond - Return the expression representing the condition for the ?: operator.
Definition: Expr.h:4202
Expr * getRHS() const
Definition: Expr.h:4214
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3552
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1072
APValue getAPValueResult() const
Definition: Expr.cpp:413
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:350
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4163
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3598
ContinueStmt - This represents a continue.
Definition: Stmt.h:2950
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4499
SourceLocation getRParenLoc() const
getRParenLoc - Return the location of final right parenthesis.
Definition: Expr.h:4533
SourceLocation getBuiltinLoc() const
getBuiltinLoc - Return the location of the __builtin_convertvector token.
Definition: Expr.h:4530
TypeSourceInfo * getTypeSourceInfo() const
getTypeSourceInfo - Return the destination type.
Definition: Expr.h:4522
Expr * getSrcExpr() const
getSrcExpr - Return the Expr to be converted.
Definition: Expr.h:4519
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3243
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3328
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:1369
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2066
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1975
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1264
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1784
bool isRecord() const
Definition: DeclBase.h:2146
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1920
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1706
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1572
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1617
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1849
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1567
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2637
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2322
bool isFunctionOrMethod() const
Definition: DeclBase.h:2118
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Definition: DeclBase.cpp:1881
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:68
iterator begin()
Definition: DeclGroup.h:99
iterator end()
Definition: DeclGroup.h:105
bool isNull() const
Definition: DeclGroup.h:79
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
NamedDecl * getFoundDecl()
Get the NamedDecl through which this reference occurred.
Definition: Expr.h:1365
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition: Expr.h:1409
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Definition: Expr.h:1458
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: Expr.h:1381
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:488
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:1389
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition: Expr.h:1347
ValueDecl * getDecl()
Definition: Expr.h:1328
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:1435
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
Definition: Expr.h:1452
bool hadMultipleCandidates() const
Returns true if this expression refers to a function that was resolved from an overloaded set having ...
Definition: Expr.h:1441
SourceLocation getLocation() const
Definition: Expr.h:1336
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:1397
bool isImmediateEscalating() const
Definition: Expr.h:1462
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1497
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:441
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1216
bool hasAttrs() const
Definition: DeclBase.h:524
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
void addAttr(Attr *A)
Definition: DeclBase.cpp:975
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:599
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:883
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1207
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:1170
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:508
SourceLocation getLocation() const
Definition: DeclBase.h:445
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
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:600
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:614
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:530
DeclContext * getDeclContext()
Definition: DeclBase.h:454
AccessSpecifier getAccess() const
Definition: DeclBase.h:513
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:393
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:437
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:486
AttrVec & getAttrs()
Definition: DeclBase.h:530
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:336
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:908
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:340
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
Returns the name of a C++ conversion function for the given Type.
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II)
Get the name of the literal operator function with II as the identifier.
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.
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:770
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:813
TemplateParameterList * getTemplateParameterList(unsigned index) const
Definition: Decl.h:862
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:822
unsigned getNumTemplateParameterLists() const
Definition: Decl.h:858
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:805
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1997
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:836
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition: Decl.h:846
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:799
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Definition: Decl.cpp:2031
Represents the type decltype(expr) (C++11).
Definition: Type.h:5354
A decomposition declaration.
Definition: DeclCXX.h:4166
Represents a C++17 deduced template specialization type.
Definition: Type.h:6025
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3855
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:6448
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3292
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:482
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3366
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition: ExprCXX.h:3340
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3358
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3400
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:3376
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3350
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3331
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3328
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3797
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3895
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4222
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:488
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:560
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:547
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:544
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:550
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6500
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4017
Represents a single C99 designator.
Definition: Expr.h:5135
unsigned getArrayIndex() const
Definition: Expr.h:5273
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5262
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5216
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5252
SourceLocation getFieldLoc() const
Definition: Expr.h:5243
SourceLocation getRBracketLoc() const
Definition: Expr.h:5291
const IdentifierInfo * getFieldName() const
Definition: Expr.cpp:4540
SourceLocation getEllipsisLoc() const
Definition: Expr.h:5285
SourceLocation getDotLoc() const
Definition: Expr.h:5238
SourceLocation getLBracketLoc() const
Definition: Expr.h:5279
Represents a C99 designated initializer expression.
Definition: Expr.h:5092
Expr * getSubExpr(unsigned Idx) const
Definition: Expr.h:5374
llvm::MutableArrayRef< Designator > designators()
Definition: Expr.h:5325
bool usesGNUSyntax() const
Determines whether this designated initializer used the deprecated GNU syntax for designated initiali...
Definition: Expr.h:5356
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4582
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:5360
unsigned size() const
Returns the number of designators in this initializer.
Definition: Expr.h:5322
SourceLocation getEqualOrColonLoc() const
Retrieve the location of the '=' that precedes the initializer value itself, if present.
Definition: Expr.h:5347
unsigned getNumSubExprs() const
Retrieve the total number of subexpressions in this designated initializer expression,...
Definition: Expr.h:5372
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1271
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
void notePriorDiagnosticFrom(const DiagnosticsEngine &Other)
Note that the prior diagnostic was emitted by some other DiagnosticsEngine, and we may be attaching a...
Definition: Diagnostic.h:896
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2725
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6367
Represents an empty-declaration.
Definition: Decl.h:4926
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3298
llvm::APSInt getInitVal() const
Definition: Decl.h:3318
const Expr * getInitExpr() const
Definition: Decl.h:3316
Represents an enum.
Definition: Decl.h:3868
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4127
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4073
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4065
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition: Decl.h:4076
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4037
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3964
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition: Decl.h:4082
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4880
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition: Decl.h:4028
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4940
EnumDecl * getDefinition() const
Definition: Decl.h:3971
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4054
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:4020
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5571
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3730
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3752
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1897
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1905
const Expr * getExpr() const
Definition: DeclCXX.h:1906
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3443
bool cleanupsHaveSideEffects() const
Definition: ExprCXX.h:3478
ArrayRef< CleanupObject > getObjects() const
Definition: ExprCXX.h:3467
unsigned getNumObjects() const
Definition: ExprCXX.h:3471
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3449
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1397
This represents one expression.
Definition: Expr.h:110
void setType(QualType t)
Definition: Expr.h:143
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:437
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition: Expr.h:239
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
An expression trait intrinsic.
Definition: ExprCXX.h:2917
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2951
Expr * getQueriedExpression() const
Definition: ExprCXX.h:2956
ExpressionTrait getTrait() const
Definition: ExprCXX.h:2954
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2952
ExtVectorType - Extended vector type.
Definition: Type.h:4057
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents difference between two FPOptions values.
Definition: LangOptions.h:915
Represents a member of a struct/union/class.
Definition: Decl.h:3058
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition: Decl.h:3146
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4572
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3219
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition: Decl.h:3213
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4582
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition: Decl.h:3162
const VariableArrayType * getCapturedVLAType() const
Get the captured variable length array type.
Definition: Decl.h:3259
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4677
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:53
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:240
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1562
SourceLocation getLocation() const
Definition: Expr.h:1688
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1078
llvm::APFloat getValue() const
Definition: Expr.h:1647
bool isExact() const
Definition: Expr.h:1680
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2781
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:58
SourceLocation getFriendLoc() const
Retrieves the location of the 'friend' keyword.
Definition: DeclFriend.h:142
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition: DeclFriend.h:137
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:122
const Expr * getSubExpr() const
Definition: Expr.h:1052
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition: Decl.cpp:3096
Represents a function declaration or definition.
Definition: Decl.h:1971
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3236
ConstexprSpecKind getConstexprKind() const
Definition: Decl.h:2439
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4047
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4042
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3255
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition: Decl.cpp:3117
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2612
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition: Decl.h:2668
bool UsesFPIntrin() const
Determine whether the function was declared in source context that requires constrained FP intrinsics...
Definition: Decl.h:2819
SourceLocation getDefaultLoc() const
Definition: Decl.h:2361
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2684
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition: Decl.h:2352
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2340
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition: Decl.h:2411
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4021
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4172
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2365
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2296
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4239
@ TK_MemberSpecialization
Definition: Decl.h:1983
@ TK_DependentNonTemplate
Definition: Decl.h:1992
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1987
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1990
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:2798
void setTrivial(bool IT)
Definition: Decl.h:2341
bool FriendConstraintRefersToEnclosingTemplate() const
Definition: Decl.h:2618
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:3993
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4060
bool isDeletedAsWritten() const
Definition: Decl.h:2507
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:4228
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition: Decl.h:2323
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2319
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition: Decl.h:2252
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2190
bool isDefaulted() const
Whether this function is defaulted.
Definition: Decl.h:2348
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4066
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4268
void setDefaulted(bool D=true)
Definition: Decl.h:2349
void setBody(Stmt *B)
Definition: Decl.cpp:3248
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition: Decl.h:2314
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition: Decl.cpp:3126
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2357
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4014
DeclarationNameInfo getNameInfo() const
Definition: Decl.h:2183
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3156
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition: Decl.h:2809
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4607
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4652
QualType desugar() const
Definition: Type.h:5119
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4896
ArrayRef< QualType > exceptions() const
Definition: Type.h:5054
ArrayRef< QualType > param_types() const
Definition: Type.h:5040
Declaration of a template function.
Definition: DeclTemplate.h:958
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
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: Type.h:4581
QualType getReturnType() const
Definition: Type.h:4569
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3259
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4633
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4650
Represents a C11 generic selection.
Definition: Expr.h:5725
TypeSourceInfo * getControllingType()
Return the controlling type of this generic selection expression.
Definition: Expr.h:6000
ArrayRef< Expr * > getAssocExprs() const
Definition: Expr.h:6020
bool isExprPredicate() const
Whether this generic selection uses an expression as its controlling argument.
Definition: Expr.h:5981
SourceLocation getGenericLoc() const
Definition: Expr.h:6078
SourceLocation getRParenLoc() const
Definition: Expr.h:6082
unsigned getResultIndex() const
The zero-based index of the result expression's generic association in the generic selection's associ...
Definition: Expr.h:5970
SourceLocation getDefaultLoc() const
Definition: Expr.h:6081
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:4470
bool isResultDependent() const
Whether this generic selection is result-dependent.
Definition: Expr.h:5977
Expr * getControllingExpr()
Return the controlling expression of this generic selection expression.
Definition: Expr.h:5988
ArrayRef< TypeSourceInfo * > getAssocTypeSourceInfos() const
Definition: Expr.h:6025
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2862
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.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IfStmt - This represents an if/then/else.
Definition: Stmt.h:2138
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:958
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1712
const Expr * getSubExpr() const
Definition: Expr.h:1724
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3655
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2074
ImplicitParamKind getParameterKind() const
Returns the implicit parameter kind.
Definition: Decl.h:1751
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5600
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4800
Represents a C array with an unspecified size.
Definition: Type.h:3699
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3342
unsigned getChainingSize() const
Definition: Decl.h:3370
ArrayRef< NamedDecl * > chain() const
Definition: Decl.h:3364
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2901
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2506
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2519
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2518
Describes an C or C++ initializer list.
Definition: Expr.h:4847
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:4951
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5017
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:4966
unsigned getNumInits() const
Definition: Expr.h:4877
SourceLocation getLBraceLoc() const
Definition: Expr.h:5001
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2408
InitListExpr * getSyntacticForm() const
Definition: Expr.h:5013
bool hadArrayRangeDesignator() const
Definition: Expr.h:5024
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:4941
SourceLocation getRBraceLoc() const
Definition: Expr.h:5003
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:4972
ArrayRef< Expr * > inits()
Definition: Expr.h:4887
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5027
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6217
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:977
SourceLocation getLocation() const
Retrieve the location of the literal.
Definition: Expr.h:1520
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3420
Represents the declaration of a label.
Definition: Decl.h:499
bool isGnuLocal() const
Definition: Decl.h:526
LabelStmt * getStmt() const
Definition: Decl.h:523
void setStmt(LabelStmt *T)
Definition: Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2031
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:88
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:1196
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:1948
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:1244
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2166
bool hasExplicitParameters() const
Determine whether this lambda has an explicit parameter list vs.
Definition: ExprCXX.h:2151
SourceRange getIntroducerRange() const
Retrieve the source range covering the lambda introducer, which contains the explicit capture list su...
Definition: ExprCXX.h:2099
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition: ExprCXX.h:2029
CXXMethodDecl * getCallOperator() const
Retrieve the function call operator associated with this lambda expression.
Definition: ExprCXX.cpp:1336
bool hasExplicitResultType() const
Whether this lambda had its result type explicitly specified.
Definition: ExprCXX.h:2154
SourceLocation getCaptureDefaultLoc() const
Retrieve the location of this lambda's capture-default, if any.
Definition: ExprCXX.h:2006
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
Definition: ExprCXX.h:2063
LambdaCaptureDefault getCaptureDefault() const
Determine the default capture kind for this lambda.
Definition: ExprCXX.h:2001
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition: ExprCXX.cpp:1332
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3229
unsigned getManglingNumber() const
Definition: DeclCXX.h:3278
Expr * getTemporaryExpr()
Retrieve the expression to which the temporary materialization conversion was applied.
Definition: DeclCXX.h:3275
Represents a linkage specification.
Definition: DeclCXX.h:2934
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2976
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition: DeclCXX.h:2957
SourceLocation getExternLoc() const
Definition: DeclCXX.h:2973
SourceLocation getRBraceLoc() const
Definition: DeclCXX.h:2974
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition: DeclCXX.h:2968
Represents the results of name lookup.
Definition: Lookup.h:46
iterator end() const
Definition: Lookup.h:359
iterator begin() const
Definition: Lookup.h:358
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5238
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4686
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition: ExprCXX.h:4703
bool isBoundToLvalueReference() const
Determine whether this materialized temporary is bound to an lvalue reference; otherwise,...
Definition: ExprCXX.h:4755
LifetimeExtendedTemporaryDecl * getLifetimeExtendedTemporaryDecl()
Definition: ExprCXX.h:4726
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3172
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: Expr.h:3344
SourceLocation getOperatorLoc() const
Definition: Expr.h:3354
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding the member name, if any.
Definition: Expr.h:3289
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition: Expr.h:3274
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
Definition: Expr.h:3255
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:3316
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why? This is only meaningful if the named memb...
Definition: Expr.h:3396
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:1754
Expr * getBase() const
Definition: Expr.h:3249
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:3305
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: Expr.h:3297
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:3349
bool isArrow() const
Definition: Expr.h:3356
DeclAccessPair getFoundDecl() const
Retrieves the declaration found by lookup.
Definition: Expr.h:3259
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3456
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:616
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:656
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:661
This represents a decl that may have a name.
Definition: Decl.h:249
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1169
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
Represents a C++ namespace alias.
Definition: DeclCXX.h:3120
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3183
SourceLocation getAliasLoc() const
Returns the location of the alias name, i.e.
Definition: DeclCXX.h:3205
SourceLocation getNamespaceLoc() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3208
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Definition: DeclCXX.h:3211
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3192
Represent a C++ namespace.
Definition: Decl.h:547
SourceLocation getRBraceLoc() const
Definition: Decl.h:686
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:685
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:610
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace nested inside this namespace, if any.
Definition: Decl.h:665
bool isNested() const
Returns true if this is a nested namespace declaration.
Definition: Decl.h:627
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:688
Class that aids in the construction of nested-name-specifiers along with source-location information ...
A C++ nested-name-specifier augmented with source location information.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning 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.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
SpecifierKind
The kind of specifier that completes this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
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.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
void setDefaultArgument(Expr *DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
unsigned getDepth() const
Get the nesting depth of the template parameter.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1569
Represents Objective-C's @catch statement.
Definition: StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:167
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:45
Represents Objective-C's @autoreleasepool Statement.
Definition: StmtObjC.h:394
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition: ExprObjC.h:1636
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2326
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2167
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:2388
ObjCCategoryImplDecl * getImplementation() const
Definition: DeclObjC.cpp:2158
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.h:2369
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition: DeclObjC.h:2374
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2408
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2461
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2463
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2418
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2404
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2163
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2397
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2457
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2542
SourceLocation getCategoryNameLoc() const
Definition: DeclObjC.h:2569
ObjCCategoryDecl * getCategoryDecl() const
Definition: DeclObjC.cpp:2199
SourceLocation getAtStartLoc() const
Definition: DeclObjC.h:1095
Represents Objective-C's collection statement.
Definition: StmtObjC.h:23
const ObjCInterfaceDecl * getClassInterface() const
Definition: DeclObjC.h:2483
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2594
SourceLocation getIvarRBraceLoc() const
Definition: DeclObjC.h:2741
SourceLocation getSuperClassLoc() const
Definition: DeclObjC.h:2734
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2732
SourceLocation getIvarLBraceLoc() const
Definition: DeclObjC.h:2739
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
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:1484
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node.
Definition: DeclObjC.h:1891
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition: DeclObjC.h:1302
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1748
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1391
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1642
known_categories_range known_categories() const
Definition: DeclObjC.h:1686
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1587
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1373
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:372
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition: DeclObjC.h:1522
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:343
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1355
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1629
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1362
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:616
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1913
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:352
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1541
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1572
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6948
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1950
AccessControl getAccessControl() const
Definition: DeclObjC.h:1998
bool getSynthesize() const
Definition: DeclObjC.h:2005
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:418
ArrayRef< ParmVarDecl * > parameters() const
Definition: DeclObjC.h:373
unsigned param_size() const
Definition: DeclObjC.h:347
bool isPropertyAccessor() const
Definition: DeclObjC.h:436
param_const_iterator param_end() const
Definition: DeclObjC.h:358
param_const_iterator param_begin() const
Definition: DeclObjC.h:354
bool isVariadic() const
Definition: DeclObjC.h:431
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclObjC.cpp:1047
TypeSourceInfo * getReturnTypeSourceInfo() const
Definition: DeclObjC.h:343
bool isSynthesizedAccessorStub() const
Definition: DeclObjC.h:444
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type.
Definition: DeclObjC.h:256
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs=std::nullopt)
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:944
bool isInstanceMethod() const
Definition: DeclObjC.h:426
bool isDefined() const
Definition: DeclObjC.h:452
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1190
QualType getReturnType() const
Definition: DeclObjC.h:329
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCImplementationControl getImplementationControl() const
Definition: DeclObjC.h:500
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1211
void getSelectorLocs(SmallVectorImpl< SourceLocation > &SelLocs) const
Definition: DeclObjC.cpp:938
Represents a pointer to an Objective C object.
Definition: Type.h:7004
Represents a class type in Objective C.
Definition: Type.h:6750
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:895
SourceLocation getGetterNameLoc() const
Definition: DeclObjC.h:885
ObjCMethodDecl * getGetterMethodDecl() const
Definition: DeclObjC.h:900
bool isInstanceProperty() const
Definition: DeclObjC.h:853
ObjCMethodDecl * getSetterMethodDecl() const
Definition: DeclObjC.h:903
SourceLocation getSetterNameLoc() const
Definition: DeclObjC.h:893
SourceLocation getAtLoc() const
Definition: DeclObjC.h:795
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:818
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:923
Selector getSetterName() const
Definition: DeclObjC.h:892
TypeSourceInfo * getTypeSourceInfo() const
Definition: DeclObjC.h:801
QualType getType() const
Definition: DeclObjC.h:803
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:830
Selector getGetterName() const
Definition: DeclObjC.h:884
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:919
SourceLocation getLParenLoc() const
Definition: DeclObjC.h:798
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:904
ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const
Definition: DeclObjC.h:826
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:814
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:887
PropertyControl getPropertyImplementation() const
Definition: DeclObjC.h:911
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:901
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2802
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2876
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2879
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2872
ObjCPropertyDecl * getPropertyDecl() const
Definition: DeclObjC.h:2867
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclObjC.h:2864
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition: DeclObjC.h:2258
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:2206
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2247
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:2023
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2155
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2162
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2169
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2183
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
unsigned getIndex() const
Retrieve the index into its type parameter list.
Definition: DeclObjC.h:636
SourceLocation getColonLoc() const
Retrieve the location of the ':' separating the type parameter name from the explicitly-specified bou...
Definition: DeclObjC.h:644
ObjCTypeParamVariance getVariance() const
Determine the variance of this type parameter.
Definition: DeclObjC.h:623
SourceLocation getVarianceLoc() const
Retrieve the location of the variance keyword.
Definition: DeclObjC.h:633
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:659
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:710
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1520
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:709
Represents a type parameter type in Objective C.
Definition: Type.h:6676
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2465
Expr * getIndexExpr(unsigned Idx)
Definition: Expr.h:2526
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2498
const OffsetOfNode & getComponent(unsigned Idx) const
Definition: Expr.h:2512
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1657
TypeSourceInfo * getTypeSourceInfo() const
Definition: Expr.h:2505
unsigned getNumExpressions() const
Definition: Expr.h:2541
SourceLocation getRParenLoc() const
Return the location of the right parentheses.
Definition: Expr.h:2502
unsigned getNumComponents() const
Definition: Expr.h:2522
Helper class for OffsetOfExpr.
Definition: Expr.h:2359
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2417
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2423
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1692
@ Array
An index into an array.
Definition: Expr.h:2364
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2368
@ Field
A field.
Definition: Expr.h:2366
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2371
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2445
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2413
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2446
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2433
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1218
SourceLocation getLocation() const
Retrieve the location of this expression.
Definition: Expr.h:1190
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:3127
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3109
const DeclarationNameInfo & getNameInfo() const
Gets the full name info.
Definition: ExprCXX.h:3082
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:3088
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3101
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:3097
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:3074
void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const
Copies the template arguments into the given structure.
Definition: ExprCXX.h:3147
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:3085
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3117
ArrayRef< TemplateArgumentLoc > template_arguments() const
Definition: ExprCXX.h:3142
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:108
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4149
Expr * getPattern()
Retrieve the pattern of the pack expansion.
Definition: ExprCXX.h:4178
std::optional< unsigned > getNumExpansions() const
Determine the number of expansions that will be produced when this pack expansion is instantiated,...
Definition: ExprCXX.h:4189
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis that describes this pack expansion.
Definition: ExprCXX.h:4185
Represents a pack expansion of types.
Definition: Type.h:6565
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2130
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2153
const Expr * getSubExpr() const
Definition: Expr.h:2145
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2157
ArrayRef< Expr * > exprs()
Definition: Expr.h:5668
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4723
unsigned getNumExprs() const
Return the number of expressions in this paren list.
Definition: Expr.h:5653
SourceLocation getLParenLoc() const
Definition: Expr.h:5670
SourceLocation getRParenLoc() const
Definition: Expr.h:5671
Sugar for parentheses used when specifying types.
Definition: Type.h:3109
Represents a parameter to a function.
Definition: Decl.h:1761
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1842
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1821
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1829
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2980
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1857
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1902
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1890
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3005
bool isObjCMethodParameter() const
Definition: Decl.h:1804
ObjCDeclQualifier getObjCDeclQualifier() const
Definition: Decl.h:1825
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1794
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1894
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1789
bool hasInheritedDefaultArg() const
Definition: Decl.h:1906
void setKNRPromoted(bool promoted)
Definition: Decl.h:1845
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1853
Expr * getDefaultArg()
Definition: Decl.cpp:2968
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3010
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3016
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1811
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1910
PipeType - OpenCL20.
Definition: Type.h:7204
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3135
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1986
SourceLocation getBeginLoc() const
Definition: Expr.h:2051
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:638
bool isTransparent() const
Definition: Expr.h:2025
PredefinedIdentKind getIdentKind() const
Definition: Expr.h:2021
StringLiteral * getFunctionName()
Definition: Expr.h:2030
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2559
A (possibly-)qualified type.
Definition: Type.h:940
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1007
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7355
QualType getCanonicalType() const
Definition: Type.h:7407
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7387
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:431
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:466
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:459
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:463
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3438
Represents a struct/union/class.
Definition: Decl.h:4169
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5042
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4225
field_range fields() const
Definition: Decl.h:4375
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4195
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5083
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4360
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Definition: Decl.h:4221
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5545
RecordDecl * getDecl() const
Definition: Type.h:5555
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:216
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:204
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:226
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4995
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3376
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3019
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1204
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
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:4431
Expr ** getSubExprs()
Retrieve the array of expressions.
Definition: Expr.h:4468
unsigned getNumSubExprs() const
getNumSubExprs - Return the size of the SubExprs array.
Definition: Expr.h:4465
SourceLocation getRParenLoc() const
Definition: Expr.h:4452
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4455
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4227
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition: ExprCXX.h:4290
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition: ExprCXX.h:4313
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition: ExprCXX.h:4318
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs=std::nullopt)
Definition: ExprCXX.cpp:1644
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition: ExprCXX.h:4287
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition: ExprCXX.h:4293
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition: ExprCXX.h:4296
unsigned getPackLength() const
Retrieve the length of the parameter pack.
Definition: ExprCXX.h:4302
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4727
SourceLocation getBeginLoc() const
Definition: Expr.h:4772
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition: Expr.h:4768
SourceLocation getEndLoc() const
Definition: Expr.h:4773
SourceLocIdentKind getIdentKind() const
Definition: Expr.h:4747
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.
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.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
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:4058
bool isFailed() const
Definition: DeclCXX.h:4087
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:4089
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4383
CompoundStmt * getSubStmt()
Definition: Expr.h:4400
unsigned getTemplateDepth() const
Definition: Expr.h:4412
SourceLocation getRParenLoc() const
Definition: Expr.h:4409
SourceLocation getLParenLoc() const
Definition: Expr.h:4407
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:185
Stmt - This represents one statement.
Definition: Stmt.h:84
child_iterator child_begin()
Definition: Stmt.h:1457
StmtClass getStmtClass() const
Definition: Stmt.h:1358
child_iterator child_end()
Definition: Stmt.h:1458
const char * getStmtClassName() const
Definition: Stmt.cpp:79
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
bool isPascal() const
Definition: Expr.h:1903
tokloc_iterator tokloc_begin() const
Definition: Expr.h:1946
tokloc_iterator tokloc_end() const
Definition: Expr.h:1950
StringLiteralKind getKind() const
Definition: Expr.h:1893
StringRef getBytes() const
Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral(...
Definition: Expr.h:1858
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumConcatenated)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
Definition: Expr.cpp:1191
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition: Expr.h:1921
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4442
std::optional< unsigned > getPackIndex() const
Definition: ExprCXX.h:4490
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: ExprCXX.h:4484
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: ExprCXX.h:4488
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:141
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.
Definition: TemplateName.h:156
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:373
std::optional< unsigned > getPackIndex() const
Definition: TemplateName.h:397
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:395
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:391
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5885
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5815
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1776
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2388
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1081
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3585
SourceRange getBraceRange() const
Definition: Decl.h:3664
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3708
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Definition: Decl.h:3683
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3688
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Definition: Decl.h:3830
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3813
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4739
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4730
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4785
TagKind getTagKind() const
Definition: Decl.h:3780
void setBraceRange(SourceRange R)
Definition: Decl.h:3665
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3691
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:648
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:647
A template argument list.
Definition: DeclTemplate.h:244
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.
Definition: DeclTemplate.h:280
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Definition: DeclTemplate.h:274
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:576
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Represents a template argument.
Definition: TemplateBase.h:61
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:444
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:331
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
std::optional< unsigned > 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.
Definition: TemplateBase.h:319
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:337
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:377
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:393
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:350
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:247
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:222
@ Template
A single template declaration.
Definition: TemplateName.h:219
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:234
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:238
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:243
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:230
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:226
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.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:144
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.
Definition: DeclTemplate.h:180
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:201
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:200
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:199
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6085
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
bool wasDeclaredWithTypename() const
Whether this template template parameter was declared with the 'typename' keyword.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
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.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
unsigned getDepth() const
Get the nesting depth of the template parameter.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
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.
bool hasTypeConstraint() const
Determine whether this template parameter has a type-constraint.
TypeSourceInfo * getDefaultArgumentInfo() const
Retrieves the default argument's source information, if any.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
void setDefaultArgument(TypeSourceInfo *DefArg)
Set the default argument for this template parameter.
bool isParameterPack() const
Returns whether this is a parameter pack.
unsigned getDepth() const
Retrieve the depth of the template parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3556
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3574
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:231
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3416
const Type * getTypeForDecl() const
Definition: Decl.h:3415
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:3418
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:192
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:5270
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5318
The type-property cache.
Definition: Type.cpp:4353
A container of type source information.
Definition: Type.h:7326
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7337
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2761
ArrayRef< TypeSourceInfo * > getArgs() const
Retrieve the argument types.
Definition: ExprCXX.h:2817
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:1828
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2822
unsigned getNumArgs() const
Determine the number of arguments to this type trait.
Definition: ExprCXX.h:2808
bool getValue() const
Definition: ExprCXX.h:2802
TypeTrait getTrait() const
Determine which type trait this expression uses.
Definition: ExprCXX.h:2798
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2821
An operation on a type.
Definition: TypeVisitor.h:64
ExpectedType Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:68
The base class of the type hierarchy.
Definition: Type.h:1813
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8076
bool isArrayType() const
Definition: Type.h:7674
bool isPointerType() const
Definition: Type.h:7608
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:694
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2649
QualType getCanonicalTypeInternal() const
Definition: Type.h:2932
const char * getTypeClassName() const
Definition: Type.cpp:3261
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:8069
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2350
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2326
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8119
bool isRecordType() const
Definition: Type.h:7702
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1874
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3535
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3433
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:3483
QualType getUnderlyingType() const
Definition: Decl.h:3488
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2568
SourceLocation getRParenLoc() const
Definition: Expr.h:2644
SourceLocation getOperatorLoc() const
Definition: Expr.h:2641
bool isArgumentType() const
Definition: Expr.h:2610
TypeSourceInfo * getArgumentTypeInfo() const
Definition: Expr.h:2614
UnaryExprOrTypeTrait getKind() const
Definition: Expr.h:2600
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2183
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2232
Expr * getSubExpr() const
Definition: Expr.h:2228
Opcode getOpcode() const
Definition: Expr.h:2223
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition: Expr.h:2324
FPOptionsOverride getStoredFPFeatures() const
Get FPFeatures from trailing storage.
Definition: Expr.h:2327
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4817
bool canOverflow() const
Returns true if the unary operator can cause an overflow.
Definition: Expr.h:2241
A unary type transform, which is a type constructed from another.
Definition: Type.h:5462
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3173
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent)
Definition: ExprCXX.cpp:372
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3246
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3241
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3912
bool isArrow() const
Determine whether this member expression used the '->' operator; otherwise, it used the '.
Definition: ExprCXX.h:4004
SourceLocation getOperatorLoc() const
Retrieve the location of the '->' or '.' operator.
Definition: ExprCXX.h:4007
bool hasUnresolvedUsing() const
Determine whether the lookup results contain an unresolved using declaration.
Definition: ExprCXX.h:3998
Expr * getBase()
Retrieve the base object of this member expressions, e.g., the x in x.m.
Definition: ExprCXX.h:3985
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:1586
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:1579
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:91
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5140
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3959
SourceLocation getTypenameLoc() const
Returns the source location of the 'typename' keyword.
Definition: DeclCXX.h:3989
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3993
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition: DeclCXX.h:3986
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:4010
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3862
SourceLocation getUsingLoc() const
Returns the source location of the 'using' keyword.
Definition: DeclCXX.h:3893
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3903
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3910
SourceLocation getEllipsisLoc() const
Get the location of the ellipsis if this is a pack expansion.
Definition: DeclCXX.h:3920
Represents a C++ using-declaration.
Definition: DeclCXX.h:3512
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition: DeclCXX.h:3561
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Definition: DeclCXX.h:3546
DeclarationNameInfo getNameInfo() const
Definition: DeclCXX.h:3553
SourceLocation getUsingLoc() const
Return the source location of the 'using' keyword.
Definition: DeclCXX.h:3539
Represents C++ using-directive.
Definition: DeclCXX.h:3015
SourceLocation getUsingLoc() const
Return the location of the using keyword.
Definition: DeclCXX.h:3086
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Definition: DeclCXX.cpp:2958
DeclContext * getCommonAncestor()
Returns the common ancestor context of this using-directive and its nominated namespace.
Definition: DeclCXX.h:3082
SourceLocation getNamespaceKeyLocation() const
Returns the location of the namespace keyword.
Definition: DeclCXX.h:3090
SourceLocation getIdentLocation() const
Returns the location of this using declaration's identifier.
Definition: DeclCXX.h:3093
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Definition: DeclCXX.h:3060
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3713
SourceLocation getEnumLoc() const
The source location of the 'enum' keyword.
Definition: DeclCXX.h:3737
TypeSourceInfo * getEnumType() const
Definition: DeclCXX.h:3751
SourceLocation getUsingLoc() const
The source location of the 'using' keyword.
Definition: DeclCXX.h:3733
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3794
NamedDecl * getInstantiatedFromUsingDecl() const
Get the using declaration from which this was instantiated.
Definition: DeclCXX.h:3824
ArrayRef< NamedDecl * > expansions() const
Get the set of using declarations that this pack expanded into.
Definition: DeclCXX.h:3828
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3320
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3384
BaseUsingDecl * getIntroducer() const
Gets the (written or instantiated) using declaration that introduced this declaration.
Definition: DeclCXX.cpp:3113
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4667
TypeSourceInfo * getWrittenTypeInfo() const
Definition: Expr.h:4691
SourceLocation getBuiltinLoc() const
Definition: Expr.h:4694
SourceLocation getRParenLoc() const
Definition: Expr.h:4697
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
Definition: Expr.h:4688
const Expr * getSubExpr() const
Definition: Expr.h:4683
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
void setType(QualType newType)
Definition: Decl.h:718
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
VarTemplateDecl * getDescribedVarTemplate() const
Retrieves the variable template that is described by this variable declaration.
Definition: Decl.cpp:2787
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition: Decl.h:1549
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2904
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
Definition: Decl.cpp:2257
bool isInlineSpecified() const
Definition: Decl.h:1534
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2363
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2547
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2533
void setInlineSpecified()
Definition: Decl.h:1538
VarDecl * getInstantiatedFromStaticDataMember() const
If this variable is an instantiated static data member of a class template specialization,...
Definition: Decl.cpp:2749
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition: Decl.h:1329
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1160
bool isInline() const
Whether this variable is (C++1z) inline.
Definition: Decl.h:1531
ThreadStorageClassSpecifier getTSCSpec() const
Definition: Decl.h:1164
const Expr * getInit() const
Definition: Decl.h:1355
void setConstexpr(bool IC)
Definition: Decl.h:1552
void setInit(Expr *I)
Definition: Decl.cpp:2454
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2792
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1155
void setImplicitlyInline()
Definition: Decl.h:1543
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1345
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2867
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary variable pattern.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
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 setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateArgsInfo(const TemplateArgumentListInfo &ArgsInfo)
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.
const ASTTemplateArgumentListInfo * getTemplateArgsInfo() const
VarTemplateSpecializationDecl * getMostRecentDecl()
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3743
Represents a GCC generic vector type.
Definition: Type.h:3965
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2584
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:1143
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:294
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
CanThrowResult
Possible results from evaluation of a noexcept expression.
void updateFlags(const Decl *From, Decl *To)
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:146
@ Property
The type of a property.
@ Result
The result type of a method or function.
@ BTK__type_pack_element
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:307
@ BTK__make_integer_seq
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:304
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:129
const FunctionProtoType * T
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1275
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:185
#define false
Definition: stdbool.h:22
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Information about how a lambda is numbered within its context.
Definition: DeclCXX.h:1798
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
getNamedTypeInfo - Returns the source type info associated to the name.
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:883
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:901
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:894
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:4715
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:4719
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4705
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4708
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:4711
Extra information about a function prototype.
Definition: Type.h:4731
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4738
FunctionType::ExtInfo ExtInfo
Definition: Type.h:4732
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Location information for a TemplateArgument.
Definition: TemplateBase.h:472
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:507
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:501
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513