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