clang 22.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
122 return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
123 if (auto *VD = dyn_cast<VarDecl>(D))
124 return getCanonicalForwardRedeclChain<VarDecl>(VD);
125 if (auto *TD = dyn_cast<TagDecl>(D))
126 return getCanonicalForwardRedeclChain<TagDecl>(TD);
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 // Use this to import pointers of specific type.
189 template <typename ImportT>
190 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
191 auto ToOrErr = Importer.Import(From);
192 if (ToOrErr)
193 To = cast_or_null<ImportT>(*ToOrErr);
194 return ToOrErr.takeError();
195 }
196
197 // Call the import function of ASTImporter for a baseclass of type `T` and
198 // cast the return value to `T`.
199 template <typename T>
200 auto import(T *From)
201 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203 auto ToOrErr = Importer.Import(From);
204 if (!ToOrErr)
205 return ToOrErr.takeError();
206 return cast_or_null<T>(*ToOrErr);
207 }
208
209 template <typename T>
210 auto import(const T *From) {
211 return import(const_cast<T *>(From));
212 }
213
214 // Call the import function of ASTImporter for type `T`.
215 template <typename T>
216 Expected<T> import(const T &From) {
217 return Importer.Import(From);
218 }
219
220 // Import an std::optional<T> by importing the contained T, if any.
221 template <typename T>
222 Expected<std::optional<T>> import(std::optional<T> From) {
223 if (!From)
224 return std::nullopt;
225 return import(*From);
226 }
227
228 ExplicitSpecifier importExplicitSpecifier(Error &Err,
229 ExplicitSpecifier ESpec);
230
231 // Wrapper for an overload set.
232 template <typename ToDeclT> struct CallOverloadedCreateFun {
233 template <typename... Args> decltype(auto) operator()(Args &&... args) {
234 return ToDeclT::Create(std::forward<Args>(args)...);
235 }
236 };
237
238 // Always use these functions to create a Decl during import. There are
239 // certain tasks which must be done after the Decl was created, e.g. we
240 // must immediately register that as an imported Decl. The parameter `ToD`
241 // will be set to the newly created Decl or if had been imported before
242 // then to the already imported Decl. Returns a bool value set to true if
243 // the `FromD` had been imported before.
244 template <typename ToDeclT, typename FromDeclT, typename... Args>
245 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
246 Args &&...args) {
247 // There may be several overloads of ToDeclT::Create. We must make sure
248 // to call the one which would be chosen by the arguments, thus we use a
249 // wrapper for the overload set.
250 CallOverloadedCreateFun<ToDeclT> OC;
251 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
252 std::forward<Args>(args)...);
253 }
254 // Use this overload if a special Type is needed to be created. E.g if we
255 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
256 // then:
257 // TypedefNameDecl *ToTypedef;
258 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
259 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
260 typename... Args>
261 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
262 Args &&...args) {
263 CallOverloadedCreateFun<NewDeclT> OC;
264 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
265 std::forward<Args>(args)...);
266 }
267 // Use this version if a special create function must be
268 // used, e.g. CXXRecordDecl::CreateLambda .
269 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
270 typename... Args>
271 [[nodiscard]] bool
272 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
273 FromDeclT *FromD, Args &&...args) {
274 if (Importer.getImportDeclErrorIfAny(FromD)) {
275 ToD = nullptr;
276 return true; // Already imported but with error.
277 }
278 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
279 if (ToD)
280 return true; // Already imported.
281 ToD = CreateFun(std::forward<Args>(args)...);
282 // Keep track of imported Decls.
283 Importer.RegisterImportedDecl(FromD, ToD);
284 Importer.SharedState->markAsNewDecl(ToD);
285 InitializeImportedDecl(FromD, ToD);
286 return false; // A new Decl is created.
287 }
288
289 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
290 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
291 if (FromD->isUsed())
292 ToD->setIsUsed();
293 if (FromD->isImplicit())
294 ToD->setImplicit();
295 }
296
297 // Check if we have found an existing definition. Returns with that
298 // definition if yes, otherwise returns null.
299 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
300 const FunctionDecl *Definition = nullptr;
301 if (D->doesThisDeclarationHaveABody() &&
302 FoundFunction->hasBody(Definition))
303 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
304 return nullptr;
305 }
306
307 void addDeclToContexts(Decl *FromD, Decl *ToD) {
308 if (Importer.isMinimalImport()) {
309 // In minimal import case the decl must be added even if it is not
310 // contained in original context, for LLDB compatibility.
311 // FIXME: Check if a better solution is possible.
312 if (!FromD->getDescribedTemplate() &&
313 FromD->getFriendObjectKind() == Decl::FOK_None)
315 return;
316 }
317
318 DeclContext *FromDC = FromD->getDeclContext();
319 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
320 DeclContext *ToDC = ToD->getDeclContext();
321 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
322
323 bool Visible = false;
324 if (FromDC->containsDeclAndLoad(FromD)) {
325 ToDC->addDeclInternal(ToD);
326 Visible = true;
327 }
328 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
329 ToLexicalDC->addDeclInternal(ToD);
330 Visible = true;
331 }
332
333 // If the Decl was added to any context, it was made already visible.
334 // Otherwise it is still possible that it should be visible.
335 if (!Visible) {
336 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
337 auto *ToNamed = cast<NamedDecl>(ToD);
338 DeclContextLookupResult FromLookup =
339 FromDC->lookup(FromNamed->getDeclName());
340 if (llvm::is_contained(FromLookup, FromNamed))
341 ToDC->makeDeclVisibleInContext(ToNamed);
342 }
343 }
344 }
345
346 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
347 DeclContext *OldDC) {
348 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
349 if (!LT)
350 return;
351
352 for (NamedDecl *TP : Params)
353 LT->update(TP, OldDC);
354 }
355
356 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
357 updateLookupTableForTemplateParameters(
358 Params, Importer.getToContext().getTranslationUnitDecl());
359 }
360
361 template <typename TemplateParmDeclT>
362 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
363 TemplateParmDeclT *ToD) {
364 if (D->hasDefaultArgument()) {
365 if (D->defaultArgumentWasInherited()) {
366 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
367 import(D->getDefaultArgStorage().getInheritedFrom());
368 if (!ToInheritedFromOrErr)
369 return ToInheritedFromOrErr.takeError();
370 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
371 if (!ToInheritedFrom->hasDefaultArgument()) {
372 // Resolve possible circular dependency between default value of the
373 // template argument and the template declaration.
374 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
375 import(D->getDefaultArgStorage()
376 .getInheritedFrom()
377 ->getDefaultArgument());
378 if (!ToInheritedDefaultArgOrErr)
379 return ToInheritedDefaultArgOrErr.takeError();
380 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
381 *ToInheritedDefaultArgOrErr);
382 }
383 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
384 ToInheritedFrom);
385 } else {
386 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
387 import(D->getDefaultArgument());
388 if (!ToDefaultArgOrErr)
389 return ToDefaultArgOrErr.takeError();
390 // Default argument could have been set in the
391 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
392 if (!ToD->hasDefaultArgument())
393 ToD->setDefaultArgument(Importer.getToContext(),
394 *ToDefaultArgOrErr);
395 }
396 }
397 return Error::success();
398 }
399
400 public:
401 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
402
406
407 // Importing types
409#define TYPE(Class, Base) \
410 ExpectedType Visit##Class##Type(const Class##Type *T);
411#include "clang/AST/TypeNodes.inc"
412
413 // Importing declarations
416 Error ImportDeclParts(
417 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
419 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
422 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
423 Error ImportDeclContext(
424 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
425 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
426
427 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
429 Expected<APValue> ImportAPValue(const APValue &FromValue);
430
432
433 /// What we should import from the definition.
435 /// Import the default subset of the definition, which might be
436 /// nothing (if minimal import is set) or might be everything (if minimal
437 /// import is not set).
439 /// Import everything.
441 /// Import only the bare bones needed to establish a valid
442 /// DeclContext.
444 };
445
447 return IDK == IDK_Everything ||
448 (IDK == IDK_Default && !Importer.isMinimalImport());
449 }
450
451 Error ImportInitializer(VarDecl *From, VarDecl *To);
452 Error ImportDefinition(
453 RecordDecl *From, RecordDecl *To,
455 Error ImportDefinition(
456 EnumDecl *From, EnumDecl *To,
458 Error ImportDefinition(
461 Error ImportDefinition(
468
469 template <typename InContainerTy>
471 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
472
473 template<typename InContainerTy>
475 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
476 const InContainerTy &Container, TemplateArgumentListInfo &Result);
477
480 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
483 FunctionDecl *FromFD);
484
485 template <typename DeclTy>
486 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
487
489
491
492 Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
493 ParmVarDecl *ToParam);
494
497
498 // Use for allocating string for newly imported object.
499 StringRef ImportASTStringRef(StringRef FromStr);
508
509 template <typename T>
511
512 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
513 bool IgnoreTemplateParmDepth = false);
560
563
581
582 // Importing statements
602 // FIXME: MSAsmStmt
603 // FIXME: SEHExceptStmt
604 // FIXME: SEHFinallyStmt
605 // FIXME: SEHTryStmt
606 // FIXME: SEHLeaveStmt
607 // FIXME: CapturedStmt
611 // FIXME: MSDependentExistsStmt
619
620 // Importing expressions
699
700 // Helper for chaining together multiple imports. If an error is detected,
701 // subsequent imports will return default constructed nodes, so that failure
702 // can be detected with a single conditional branch after a sequence of
703 // imports.
704 template <typename T> T importChecked(Error &Err, const T &From) {
705 // Don't attempt to import nodes if we hit an error earlier.
706 if (Err)
707 return T{};
708 Expected<T> MaybeVal = import(From);
709 if (!MaybeVal) {
710 Err = MaybeVal.takeError();
711 return T{};
712 }
713 return *MaybeVal;
714 }
715
716 template<typename IIter, typename OIter>
717 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
718 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
719 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
720 Expected<ItemT> ToOrErr = import(*Ibegin);
721 if (!ToOrErr)
722 return ToOrErr.takeError();
723 *Obegin = *ToOrErr;
724 }
725 return Error::success();
726 }
727
728 // Import every item from a container structure into an output container.
729 // If error occurs, stops at first error and returns the error.
730 // The output container should have space for all needed elements (it is not
731 // expanded, new items are put into from the beginning).
732 template<typename InContainerTy, typename OutContainerTy>
734 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
735 return ImportArrayChecked(
736 InContainer.begin(), InContainer.end(), OutContainer.begin());
737 }
738
739 template<typename InContainerTy, typename OIter>
740 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
741 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
742 }
743
745 CXXMethodDecl *FromMethod);
746
748 FunctionDecl *FromFD);
749
750 // Returns true if the given function has a placeholder return type and
751 // that type is declared inside the body of the function.
752 // E.g. auto f() { struct X{}; return X(); }
754 };
755
756template <typename InContainerTy>
758 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
759 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
760 auto ToLAngleLocOrErr = import(FromLAngleLoc);
761 if (!ToLAngleLocOrErr)
762 return ToLAngleLocOrErr.takeError();
763 auto ToRAngleLocOrErr = import(FromRAngleLoc);
764 if (!ToRAngleLocOrErr)
765 return ToRAngleLocOrErr.takeError();
766
767 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
768 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
769 return Err;
770 Result = ToTAInfo;
771 return Error::success();
772}
773
774template <>
775Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
778 From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
779}
780
781template <>
784 const ASTTemplateArgumentListInfo &From,
786 return ImportTemplateArgumentListInfo(
787 From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
788}
789
792 FunctionDecl *FromFD) {
793 assert(FromFD->getTemplatedKind() ==
795
797
798 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
799 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
800 return std::move(Err);
801
802 // Import template arguments.
803 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
804 std::get<1>(Result)))
805 return std::move(Err);
806
807 return Result;
808}
809
810template <>
812ASTNodeImporter::import(TemplateParameterList *From) {
814 if (Error Err = ImportContainerChecked(*From, To))
815 return std::move(Err);
816
817 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
818 if (!ToRequiresClause)
819 return ToRequiresClause.takeError();
820
821 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
822 if (!ToTemplateLocOrErr)
823 return ToTemplateLocOrErr.takeError();
824 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
825 if (!ToLAngleLocOrErr)
826 return ToLAngleLocOrErr.takeError();
827 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
828 if (!ToRAngleLocOrErr)
829 return ToRAngleLocOrErr.takeError();
830
832 Importer.getToContext(),
833 *ToTemplateLocOrErr,
834 *ToLAngleLocOrErr,
835 To,
836 *ToRAngleLocOrErr,
837 *ToRequiresClause);
838}
839
840template <>
842ASTNodeImporter::import(const TemplateArgument &From) {
843 switch (From.getKind()) {
845 return TemplateArgument();
846
848 ExpectedType ToTypeOrErr = import(From.getAsType());
849 if (!ToTypeOrErr)
850 return ToTypeOrErr.takeError();
851 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
852 From.getIsDefaulted());
853 }
854
856 ExpectedType ToTypeOrErr = import(From.getIntegralType());
857 if (!ToTypeOrErr)
858 return ToTypeOrErr.takeError();
859 return TemplateArgument(From, *ToTypeOrErr);
860 }
861
863 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
864 if (!ToOrErr)
865 return ToOrErr.takeError();
866 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
867 if (!ToTypeOrErr)
868 return ToTypeOrErr.takeError();
869 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
870 *ToTypeOrErr, From.getIsDefaulted());
871 }
872
874 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
875 if (!ToTypeOrErr)
876 return ToTypeOrErr.takeError();
877 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
878 From.getIsDefaulted());
879 }
880
882 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
883 if (!ToTypeOrErr)
884 return ToTypeOrErr.takeError();
885 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
886 if (!ToValueOrErr)
887 return ToValueOrErr.takeError();
888 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
889 *ToValueOrErr);
890 }
891
893 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
894 if (!ToTemplateOrErr)
895 return ToTemplateOrErr.takeError();
896
897 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
898 }
899
901 Expected<TemplateName> ToTemplateOrErr =
902 import(From.getAsTemplateOrTemplatePattern());
903 if (!ToTemplateOrErr)
904 return ToTemplateOrErr.takeError();
905
906 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
907 From.getIsDefaulted());
908 }
909
911 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
912 return TemplateArgument(*ToExpr, From.isCanonicalExpr(),
913 From.getIsDefaulted());
914 else
915 return ToExpr.takeError();
916
919 ToPack.reserve(From.pack_size());
920 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
921 return std::move(Err);
922
923 return TemplateArgument(ArrayRef(ToPack).copy(Importer.getToContext()));
924 }
925 }
926
927 llvm_unreachable("Invalid template argument kind");
928}
929
930template <>
932ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
933 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
934 if (!ArgOrErr)
935 return ArgOrErr.takeError();
936 TemplateArgument Arg = *ArgOrErr;
937
938 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
939
942 ExpectedExpr E = import(FromInfo.getAsExpr());
943 if (!E)
944 return E.takeError();
945 ToInfo = TemplateArgumentLocInfo(*E);
946 } else if (Arg.getKind() == TemplateArgument::Type) {
947 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
948 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
949 else
950 return TSIOrErr.takeError();
951 } else {
952 auto ToTemplateKWLocOrErr = import(FromInfo.getTemplateKwLoc());
953 if (!ToTemplateKWLocOrErr)
954 return ToTemplateKWLocOrErr.takeError();
955 auto ToTemplateQualifierLocOrErr = import(TALoc.getTemplateQualifierLoc());
956 if (!ToTemplateQualifierLocOrErr)
957 return ToTemplateQualifierLocOrErr.takeError();
958 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
959 if (!ToTemplateNameLocOrErr)
960 return ToTemplateNameLocOrErr.takeError();
961 auto ToTemplateEllipsisLocOrErr =
962 import(FromInfo.getTemplateEllipsisLoc());
963 if (!ToTemplateEllipsisLocOrErr)
964 return ToTemplateEllipsisLocOrErr.takeError();
966 Importer.getToContext(), *ToTemplateKWLocOrErr,
967 *ToTemplateQualifierLocOrErr, *ToTemplateNameLocOrErr,
968 *ToTemplateEllipsisLocOrErr);
969 }
970
971 return TemplateArgumentLoc(Arg, ToInfo);
972}
973
974template <>
975Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
976 if (DG.isNull())
977 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
978 size_t NumDecls = DG.end() - DG.begin();
980 ToDecls.reserve(NumDecls);
981 for (Decl *FromD : DG) {
982 if (auto ToDOrErr = import(FromD))
983 ToDecls.push_back(*ToDOrErr);
984 else
985 return ToDOrErr.takeError();
986 }
987 return DeclGroupRef::Create(Importer.getToContext(),
988 ToDecls.begin(),
989 NumDecls);
990}
991
992template <>
994ASTNodeImporter::import(const Designator &D) {
995 if (D.isFieldDesignator()) {
996 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
997
998 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
999 if (!ToDotLocOrErr)
1000 return ToDotLocOrErr.takeError();
1001
1002 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
1003 if (!ToFieldLocOrErr)
1004 return ToFieldLocOrErr.takeError();
1005
1007 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
1008 }
1009
1010 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1011 if (!ToLBracketLocOrErr)
1012 return ToLBracketLocOrErr.takeError();
1013
1014 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1015 if (!ToRBracketLocOrErr)
1016 return ToRBracketLocOrErr.takeError();
1017
1018 if (D.isArrayDesignator())
1019 return Designator::CreateArrayDesignator(D.getArrayIndex(),
1020 *ToLBracketLocOrErr,
1021 *ToRBracketLocOrErr);
1022
1023 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1024 if (!ToEllipsisLocOrErr)
1025 return ToEllipsisLocOrErr.takeError();
1026
1027 assert(D.isArrayRangeDesignator());
1029 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1030 *ToRBracketLocOrErr);
1031}
1032
1033template <>
1034Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1035 Error Err = Error::success();
1036 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1037 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1038 auto ToConceptNameLoc =
1039 importChecked(Err, From->getConceptNameInfo().getLoc());
1040 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1041 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1042 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1043 if (Err)
1044 return std::move(Err);
1045 TemplateArgumentListInfo ToTAInfo;
1046 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1047 if (ASTTemplateArgs)
1048 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1049 return std::move(Err);
1050 auto *ConceptRef = ConceptReference::Create(
1051 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1052 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1053 ToNamedConcept,
1054 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1055 Importer.getToContext(), ToTAInfo)
1056 : nullptr);
1057 return ConceptRef;
1058}
1059
1060StringRef ASTNodeImporter::ImportASTStringRef(StringRef FromStr) {
1061 char *ToStore = new (Importer.getToContext()) char[FromStr.size()];
1062 std::copy(FromStr.begin(), FromStr.end(), ToStore);
1063 return StringRef(ToStore, FromStr.size());
1064}
1065
1067 const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat) {
1068 ToSat.IsSatisfied = FromSat.IsSatisfied;
1069 ToSat.ContainsErrors = FromSat.ContainsErrors;
1070 if (!ToSat.IsSatisfied) {
1071 for (auto Record = FromSat.begin(); Record != FromSat.end(); ++Record) {
1072 if (Expr *E = Record->dyn_cast<Expr *>()) {
1073 ExpectedExpr ToSecondExpr = import(E);
1074 if (!ToSecondExpr)
1075 return ToSecondExpr.takeError();
1076 ToSat.Details.emplace_back(ToSecondExpr.get());
1077 } else {
1078 auto Pair = Record->dyn_cast<std::pair<SourceLocation, StringRef> *>();
1079
1080 ExpectedSLoc ToPairFirst = import(Pair->first);
1081 if (!ToPairFirst)
1082 return ToPairFirst.takeError();
1083 StringRef ToPairSecond = ImportASTStringRef(Pair->second);
1084 ToSat.Details.emplace_back(
1085 new (Importer.getToContext())
1087 ToPairFirst.get(), ToPairSecond});
1088 }
1089 }
1090 }
1091 return Error::success();
1092}
1093
1094template <>
1096ASTNodeImporter::import(
1098 StringRef ToEntity = ImportASTStringRef(FromDiag->SubstitutedEntity);
1099 ExpectedSLoc ToLoc = import(FromDiag->DiagLoc);
1100 if (!ToLoc)
1101 return ToLoc.takeError();
1102 StringRef ToDiagMessage = ImportASTStringRef(FromDiag->DiagMessage);
1103 return new (Importer.getToContext())
1105 ToDiagMessage};
1106}
1107
1110 using namespace concepts;
1111
1112 if (From->isSubstitutionFailure()) {
1113 auto DiagOrErr = import(From->getSubstitutionDiagnostic());
1114 if (!DiagOrErr)
1115 return DiagOrErr.takeError();
1116 return new (Importer.getToContext()) TypeRequirement(*DiagOrErr);
1117 } else {
1118 Expected<TypeSourceInfo *> ToType = import(From->getType());
1119 if (!ToType)
1120 return ToType.takeError();
1121 return new (Importer.getToContext()) TypeRequirement(*ToType);
1122 }
1123}
1124
1127 using namespace concepts;
1128
1129 bool IsRKSimple = From->getKind() == Requirement::RK_Simple;
1130 ExprRequirement::SatisfactionStatus Status = From->getSatisfactionStatus();
1131
1132 std::optional<ExprRequirement::ReturnTypeRequirement> Req;
1133 ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
1134
1135 if (IsRKSimple) {
1136 Req.emplace();
1137 } else {
1138 const ExprRequirement::ReturnTypeRequirement &FromTypeRequirement =
1140
1141 if (FromTypeRequirement.isTypeConstraint()) {
1142 const bool IsDependent = FromTypeRequirement.isDependent();
1143 auto ParamsOrErr =
1144 import(FromTypeRequirement.getTypeConstraintTemplateParameterList());
1145 if (!ParamsOrErr)
1146 return ParamsOrErr.takeError();
1147 if (Status >= ExprRequirement::SS_ConstraintsNotSatisfied) {
1148 auto SubstConstraintExprOrErr =
1150 if (!SubstConstraintExprOrErr)
1151 return SubstConstraintExprOrErr.takeError();
1152 SubstitutedConstraintExpr = SubstConstraintExprOrErr.get();
1153 }
1154 Req.emplace(ParamsOrErr.get(), IsDependent);
1155 } else if (FromTypeRequirement.isSubstitutionFailure()) {
1156 auto DiagOrErr = import(FromTypeRequirement.getSubstitutionDiagnostic());
1157 if (!DiagOrErr)
1158 return DiagOrErr.takeError();
1159 Req.emplace(DiagOrErr.get());
1160 } else {
1161 Req.emplace();
1162 }
1163 }
1164
1165 ExpectedSLoc NoexceptLocOrErr = import(From->getNoexceptLoc());
1166 if (!NoexceptLocOrErr)
1167 return NoexceptLocOrErr.takeError();
1168
1169 if (Status == ExprRequirement::SS_ExprSubstitutionFailure) {
1170 auto DiagOrErr = import(From->getExprSubstitutionDiagnostic());
1171 if (!DiagOrErr)
1172 return DiagOrErr.takeError();
1173 return new (Importer.getToContext()) ExprRequirement(
1174 *DiagOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req));
1175 } else {
1176 Expected<Expr *> ExprOrErr = import(From->getExpr());
1177 if (!ExprOrErr)
1178 return ExprOrErr.takeError();
1179 return new (Importer.getToContext()) concepts::ExprRequirement(
1180 *ExprOrErr, IsRKSimple, *NoexceptLocOrErr, std::move(*Req), Status,
1181 SubstitutedConstraintExpr);
1182 }
1183}
1184
1187 using namespace concepts;
1188
1189 const ASTConstraintSatisfaction &FromSatisfaction =
1191 if (From->hasInvalidConstraint()) {
1192 StringRef ToEntity = ImportASTStringRef(From->getInvalidConstraintEntity());
1193 ASTConstraintSatisfaction *ToSatisfaction =
1195 FromSatisfaction);
1196 return new (Importer.getToContext())
1197 NestedRequirement(ToEntity, ToSatisfaction);
1198 } else {
1199 ExpectedExpr ToExpr = import(From->getConstraintExpr());
1200 if (!ToExpr)
1201 return ToExpr.takeError();
1202 if (ToExpr.get()->isInstantiationDependent()) {
1203 return new (Importer.getToContext()) NestedRequirement(ToExpr.get());
1204 } else {
1205 ConstraintSatisfaction Satisfaction;
1206 if (Error Err =
1207 ImportConstraintSatisfaction(FromSatisfaction, Satisfaction))
1208 return std::move(Err);
1209 return new (Importer.getToContext()) NestedRequirement(
1210 Importer.getToContext(), ToExpr.get(), Satisfaction);
1211 }
1212 }
1213}
1214
1215template <>
1217ASTNodeImporter::import(concepts::Requirement *FromRequire) {
1218 switch (FromRequire->getKind()) {
1220 return ImportTypeRequirement(cast<concepts::TypeRequirement>(FromRequire));
1223 return ImportExprRequirement(cast<concepts::ExprRequirement>(FromRequire));
1226 cast<concepts::NestedRequirement>(FromRequire));
1227 }
1228 llvm_unreachable("Unhandled requirement kind");
1229}
1230
1231template <>
1232Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1233 ValueDecl *Var = nullptr;
1234 if (From.capturesVariable()) {
1235 if (auto VarOrErr = import(From.getCapturedVar()))
1236 Var = *VarOrErr;
1237 else
1238 return VarOrErr.takeError();
1239 }
1240
1241 auto LocationOrErr = import(From.getLocation());
1242 if (!LocationOrErr)
1243 return LocationOrErr.takeError();
1244
1245 SourceLocation EllipsisLoc;
1246 if (From.isPackExpansion())
1247 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1248 return std::move(Err);
1249
1250 return LambdaCapture(
1251 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1252 EllipsisLoc);
1253}
1254
1255template <typename T>
1257 if (Found->getLinkageInternal() != From->getLinkageInternal())
1258 return false;
1259
1260 if (From->hasExternalFormalLinkage())
1261 return Found->hasExternalFormalLinkage();
1262 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1263 return false;
1264 if (From->isInAnonymousNamespace())
1265 return Found->isInAnonymousNamespace();
1266 else
1267 return !Found->isInAnonymousNamespace() &&
1268 !Found->hasExternalFormalLinkage();
1269}
1270
1271template <>
1273 TypedefNameDecl *From) {
1274 if (Found->getLinkageInternal() != From->getLinkageInternal())
1275 return false;
1276
1277 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1278 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1279 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1280}
1281
1282} // namespace clang
1283
1284//----------------------------------------------------------------------------
1285// Import Types
1286//----------------------------------------------------------------------------
1287
1288using namespace clang;
1289
1291 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1292 << T->getTypeClassName();
1293 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1294}
1295
1296ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1297 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1298 if (!UnderlyingTypeOrErr)
1299 return UnderlyingTypeOrErr.takeError();
1300
1301 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1302}
1303
1304ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1305 switch (T->getKind()) {
1306#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1307 case BuiltinType::Id: \
1308 return Importer.getToContext().SingletonId;
1309#include "clang/Basic/OpenCLImageTypes.def"
1310#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1311 case BuiltinType::Id: \
1312 return Importer.getToContext().Id##Ty;
1313#include "clang/Basic/OpenCLExtensionTypes.def"
1314#define SVE_TYPE(Name, Id, SingletonId) \
1315 case BuiltinType::Id: \
1316 return Importer.getToContext().SingletonId;
1317#include "clang/Basic/AArch64ACLETypes.def"
1318#define PPC_VECTOR_TYPE(Name, Id, Size) \
1319 case BuiltinType::Id: \
1320 return Importer.getToContext().Id##Ty;
1321#include "clang/Basic/PPCTypes.def"
1322#define RVV_TYPE(Name, Id, SingletonId) \
1323 case BuiltinType::Id: \
1324 return Importer.getToContext().SingletonId;
1325#include "clang/Basic/RISCVVTypes.def"
1326#define WASM_TYPE(Name, Id, SingletonId) \
1327 case BuiltinType::Id: \
1328 return Importer.getToContext().SingletonId;
1329#include "clang/Basic/WebAssemblyReferenceTypes.def"
1330#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1331 case BuiltinType::Id: \
1332 return Importer.getToContext().SingletonId;
1333#include "clang/Basic/AMDGPUTypes.def"
1334#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1335 case BuiltinType::Id: \
1336 return Importer.getToContext().SingletonId;
1337#include "clang/Basic/HLSLIntangibleTypes.def"
1338#define SHARED_SINGLETON_TYPE(Expansion)
1339#define BUILTIN_TYPE(Id, SingletonId) \
1340 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1341#include "clang/AST/BuiltinTypes.def"
1342
1343 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1344 // context supports C++.
1345
1346 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1347 // context supports ObjC.
1348
1349 case BuiltinType::Char_U:
1350 // The context we're importing from has an unsigned 'char'. If we're
1351 // importing into a context with a signed 'char', translate to
1352 // 'unsigned char' instead.
1353 if (Importer.getToContext().getLangOpts().CharIsSigned)
1354 return Importer.getToContext().UnsignedCharTy;
1355
1356 return Importer.getToContext().CharTy;
1357
1358 case BuiltinType::Char_S:
1359 // The context we're importing from has an unsigned 'char'. If we're
1360 // importing into a context with a signed 'char', translate to
1361 // 'unsigned char' instead.
1362 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1363 return Importer.getToContext().SignedCharTy;
1364
1365 return Importer.getToContext().CharTy;
1366
1367 case BuiltinType::WChar_S:
1368 case BuiltinType::WChar_U:
1369 // FIXME: If not in C++, shall we translate to the C equivalent of
1370 // wchar_t?
1371 return Importer.getToContext().WCharTy;
1372 }
1373
1374 llvm_unreachable("Invalid BuiltinType Kind!");
1375}
1376
1377ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1378 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1379 if (!ToOriginalTypeOrErr)
1380 return ToOriginalTypeOrErr.takeError();
1381
1382 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1383}
1384
1385ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1386 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1387 if (!ToElementTypeOrErr)
1388 return ToElementTypeOrErr.takeError();
1389
1390 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1391}
1392
1393ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1394 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1395 if (!ToPointeeTypeOrErr)
1396 return ToPointeeTypeOrErr.takeError();
1397
1398 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1399}
1400
1401ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1402 // FIXME: Check for blocks support in "to" context.
1403 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1404 if (!ToPointeeTypeOrErr)
1405 return ToPointeeTypeOrErr.takeError();
1406
1407 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1408}
1409
1411ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1412 // FIXME: Check for C++ support in "to" context.
1413 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1414 if (!ToPointeeTypeOrErr)
1415 return ToPointeeTypeOrErr.takeError();
1416
1417 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1418}
1419
1421ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1422 // FIXME: Check for C++0x support in "to" context.
1423 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1424 if (!ToPointeeTypeOrErr)
1425 return ToPointeeTypeOrErr.takeError();
1426
1427 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1428}
1429
1431ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1432 // FIXME: Check for C++ support in "to" context.
1433 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1434 if (!ToPointeeTypeOrErr)
1435 return ToPointeeTypeOrErr.takeError();
1436
1437 auto QualifierOrErr = import(T->getQualifier());
1438 if (!QualifierOrErr)
1439 return QualifierOrErr.takeError();
1440
1441 auto ClsOrErr = import(T->getMostRecentCXXRecordDecl());
1442 if (!ClsOrErr)
1443 return ClsOrErr.takeError();
1444
1445 return Importer.getToContext().getMemberPointerType(
1446 *ToPointeeTypeOrErr, *QualifierOrErr, *ClsOrErr);
1447}
1448
1450ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1451 Error Err = Error::success();
1452 auto ToElementType = importChecked(Err, T->getElementType());
1453 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1454 if (Err)
1455 return std::move(Err);
1456
1457 return Importer.getToContext().getConstantArrayType(
1458 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1459 T->getIndexTypeCVRQualifiers());
1460}
1461
1463ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1464 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1465 if (!ToArrayTypeOrErr)
1466 return ToArrayTypeOrErr.takeError();
1467
1468 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1469}
1470
1472ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1473 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1474 if (!ToElementTypeOrErr)
1475 return ToElementTypeOrErr.takeError();
1476
1477 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1478 T->getSizeModifier(),
1479 T->getIndexTypeCVRQualifiers());
1480}
1481
1483ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1484 Error Err = Error::success();
1485 QualType ToElementType = importChecked(Err, T->getElementType());
1486 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1487 if (Err)
1488 return std::move(Err);
1489 return Importer.getToContext().getVariableArrayType(
1490 ToElementType, ToSizeExpr, T->getSizeModifier(),
1491 T->getIndexTypeCVRQualifiers());
1492}
1493
1494ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1495 const DependentSizedArrayType *T) {
1496 Error Err = Error::success();
1497 QualType ToElementType = importChecked(Err, T->getElementType());
1498 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1499 if (Err)
1500 return std::move(Err);
1501 // SizeExpr may be null if size is not specified directly.
1502 // For example, 'int a[]'.
1503
1504 return Importer.getToContext().getDependentSizedArrayType(
1505 ToElementType, ToSizeExpr, T->getSizeModifier(),
1506 T->getIndexTypeCVRQualifiers());
1507}
1508
1509ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1511 Error Err = Error::success();
1512 QualType ToElementType = importChecked(Err, T->getElementType());
1513 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1514 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1515 if (Err)
1516 return std::move(Err);
1518 ToElementType, ToSizeExpr, ToAttrLoc);
1519}
1520
1521ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1522 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1523 if (!ToElementTypeOrErr)
1524 return ToElementTypeOrErr.takeError();
1525
1526 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1527 T->getNumElements(),
1528 T->getVectorKind());
1529}
1530
1531ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1532 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1533 if (!ToElementTypeOrErr)
1534 return ToElementTypeOrErr.takeError();
1535
1536 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1537 T->getNumElements());
1538}
1539
1541ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1542 // FIXME: What happens if we're importing a function without a prototype
1543 // into C++? Should we make it variadic?
1544 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1545 if (!ToReturnTypeOrErr)
1546 return ToReturnTypeOrErr.takeError();
1547
1548 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1549 T->getExtInfo());
1550}
1551
1553ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1554 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1555 if (!ToReturnTypeOrErr)
1556 return ToReturnTypeOrErr.takeError();
1557
1558 // Import argument types
1559 SmallVector<QualType, 4> ArgTypes;
1560 for (const auto &A : T->param_types()) {
1561 ExpectedType TyOrErr = import(A);
1562 if (!TyOrErr)
1563 return TyOrErr.takeError();
1564 ArgTypes.push_back(*TyOrErr);
1565 }
1566
1567 // Import exception types
1568 SmallVector<QualType, 4> ExceptionTypes;
1569 for (const auto &E : T->exceptions()) {
1570 ExpectedType TyOrErr = import(E);
1571 if (!TyOrErr)
1572 return TyOrErr.takeError();
1573 ExceptionTypes.push_back(*TyOrErr);
1574 }
1575
1577 Error Err = Error::success();
1579 ToEPI.ExtInfo = FromEPI.ExtInfo;
1580 ToEPI.Variadic = FromEPI.Variadic;
1581 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1582 ToEPI.TypeQuals = FromEPI.TypeQuals;
1583 ToEPI.RefQualifier = FromEPI.RefQualifier;
1584 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1591 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1592
1593 if (Err)
1594 return std::move(Err);
1595
1596 return Importer.getToContext().getFunctionType(
1597 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1598}
1599
1600ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1601 const UnresolvedUsingType *T) {
1602 Error Err = Error::success();
1603 auto ToQualifier = importChecked(Err, T->getQualifier());
1604 auto *ToD = importChecked(Err, T->getDecl());
1605 if (Err)
1606 return std::move(Err);
1607
1609 return Importer.getToContext().getCanonicalUnresolvedUsingType(ToD);
1610 return Importer.getToContext().getUnresolvedUsingType(T->getKeyword(),
1611 ToQualifier, ToD);
1612}
1613
1614ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1615 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1616 if (!ToInnerTypeOrErr)
1617 return ToInnerTypeOrErr.takeError();
1618
1619 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1620}
1621
1623ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1624
1625 ExpectedType Pattern = import(T->getPattern());
1626 if (!Pattern)
1627 return Pattern.takeError();
1628 ExpectedExpr Index = import(T->getIndexExpr());
1629 if (!Index)
1630 return Index.takeError();
1631 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1632}
1633
1634ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1635 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1636 if (!ToDeclOrErr)
1637 return ToDeclOrErr.takeError();
1638
1639 auto ToQualifierOrErr = import(T->getQualifier());
1640 if (!ToQualifierOrErr)
1641 return ToQualifierOrErr.takeError();
1642
1643 ExpectedType ToUnderlyingTypeOrErr =
1644 T->typeMatchesDecl() ? QualType() : import(T->desugar());
1645 if (!ToUnderlyingTypeOrErr)
1646 return ToUnderlyingTypeOrErr.takeError();
1647
1648 return Importer.getToContext().getTypedefType(
1649 T->getKeyword(), *ToQualifierOrErr, *ToDeclOrErr, *ToUnderlyingTypeOrErr);
1650}
1651
1652ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1653 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1654 if (!ToExprOrErr)
1655 return ToExprOrErr.takeError();
1656 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1657}
1658
1659ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1660 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1661 if (!ToUnderlyingTypeOrErr)
1662 return ToUnderlyingTypeOrErr.takeError();
1663 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1664 T->getKind());
1665}
1666
1667ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1668 Error Err = Error::success();
1669 auto ToQualifier = importChecked(Err, T->getQualifier());
1670 auto *ToD = importChecked(Err, T->getDecl());
1671 QualType ToT = importChecked(Err, T->desugar());
1672 if (Err)
1673 return std::move(Err);
1674 return Importer.getToContext().getUsingType(T->getKeyword(), ToQualifier, ToD,
1675 ToT);
1676}
1677
1678ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1679 // FIXME: Make sure that the "to" context supports C++0x!
1680 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1681 if (!ToExprOrErr)
1682 return ToExprOrErr.takeError();
1683
1684 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1685 if (!ToUnderlyingTypeOrErr)
1686 return ToUnderlyingTypeOrErr.takeError();
1687
1688 return Importer.getToContext().getDecltypeType(
1689 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1690}
1691
1693ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1694 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1695 if (!ToBaseTypeOrErr)
1696 return ToBaseTypeOrErr.takeError();
1697
1698 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1699 if (!ToUnderlyingTypeOrErr)
1700 return ToUnderlyingTypeOrErr.takeError();
1701
1702 return Importer.getToContext().getUnaryTransformType(
1703 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1704}
1705
1706ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1707 // FIXME: Make sure that the "to" context supports C++11!
1708 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1709 if (!ToDeducedTypeOrErr)
1710 return ToDeducedTypeOrErr.takeError();
1711
1712 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1713 if (!ToTypeConstraintConcept)
1714 return ToTypeConstraintConcept.takeError();
1715
1716 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1717 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1718 ToTemplateArgs))
1719 return std::move(Err);
1720
1721 return Importer.getToContext().getAutoType(
1722 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1723 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1724 ToTemplateArgs);
1725}
1726
1727ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1729 // FIXME: Make sure that the "to" context supports C++17!
1730 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1731 if (!ToTemplateNameOrErr)
1732 return ToTemplateNameOrErr.takeError();
1733 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1734 if (!ToDeducedTypeOrErr)
1735 return ToDeducedTypeOrErr.takeError();
1736
1738 T->getKeyword(), *ToTemplateNameOrErr, *ToDeducedTypeOrErr,
1739 T->isDependentType());
1740}
1741
1742ExpectedType ASTNodeImporter::VisitTagType(const TagType *T) {
1743 Expected<TagDecl *> ToDeclOrErr = import(T->getOriginalDecl());
1744 if (!ToDeclOrErr)
1745 return ToDeclOrErr.takeError();
1746
1748 return Importer.getToContext().getCanonicalTagType(*ToDeclOrErr);
1749
1750 auto ToQualifierOrErr = import(T->getQualifier());
1751 if (!ToQualifierOrErr)
1752 return ToQualifierOrErr.takeError();
1753
1754 return Importer.getToContext().getTagType(T->getKeyword(), *ToQualifierOrErr,
1755 *ToDeclOrErr, T->isTagOwned());
1756}
1757
1758ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1759 return VisitTagType(T);
1760}
1761
1762ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1763 return VisitTagType(T);
1764}
1765
1767ASTNodeImporter::VisitInjectedClassNameType(const InjectedClassNameType *T) {
1768 return VisitTagType(T);
1769}
1770
1771ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1772 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1773 if (!ToModifiedTypeOrErr)
1774 return ToModifiedTypeOrErr.takeError();
1775 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1776 if (!ToEquivalentTypeOrErr)
1777 return ToEquivalentTypeOrErr.takeError();
1778
1779 return Importer.getToContext().getAttributedType(
1780 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1781 T->getAttr());
1782}
1783
1785ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1786 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1787 if (!ToWrappedTypeOrErr)
1788 return ToWrappedTypeOrErr.takeError();
1789
1790 Error Err = Error::success();
1791 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1792
1794 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1795 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1796 if (!ToDeclOrErr)
1797 return ToDeclOrErr.takeError();
1798 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1799 }
1800
1801 return Importer.getToContext().getCountAttributedType(
1802 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1803 ArrayRef(CoupledDecls));
1804}
1805
1806ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1807 const TemplateTypeParmType *T) {
1808 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1809 if (!ToDeclOrErr)
1810 return ToDeclOrErr.takeError();
1811
1812 return Importer.getToContext().getTemplateTypeParmType(
1813 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1814}
1815
1816ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1818 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1819 if (!ReplacedOrErr)
1820 return ReplacedOrErr.takeError();
1821
1822 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1823 if (!ToReplacementTypeOrErr)
1824 return ToReplacementTypeOrErr.takeError();
1825
1827 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1828 T->getFinal());
1829}
1830
1831ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1833 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1834 if (!ReplacedOrErr)
1835 return ReplacedOrErr.takeError();
1836
1837 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1838 if (!ToArgumentPack)
1839 return ToArgumentPack.takeError();
1840
1842 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1843}
1844
1845ExpectedType ASTNodeImporter::VisitSubstBuiltinTemplatePackType(
1847 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1848 if (!ToArgumentPack)
1849 return ToArgumentPack.takeError();
1850 return Importer.getToContext().getSubstBuiltinTemplatePack(*ToArgumentPack);
1851}
1852
1853ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1855 auto ToTemplateOrErr = import(T->getTemplateName());
1856 if (!ToTemplateOrErr)
1857 return ToTemplateOrErr.takeError();
1858
1859 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1860 if (Error Err =
1861 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1862 return std::move(Err);
1863
1864 ExpectedType ToUnderlyingOrErr =
1865 T->isCanonicalUnqualified() ? QualType() : import(T->desugar());
1866 if (!ToUnderlyingOrErr)
1867 return ToUnderlyingOrErr.takeError();
1869 T->getKeyword(), *ToTemplateOrErr, ToTemplateArgs, {},
1870 *ToUnderlyingOrErr);
1871}
1872
1874ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1875 ExpectedType ToPatternOrErr = import(T->getPattern());
1876 if (!ToPatternOrErr)
1877 return ToPatternOrErr.takeError();
1878
1879 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1880 T->getNumExpansions(),
1881 /*ExpactPack=*/false);
1882}
1883
1884ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1886 const DependentTemplateStorage &DTN = T->getDependentTemplateName();
1887 auto QualifierOrErr = import(DTN.getQualifier());
1888 if (!QualifierOrErr)
1889 return QualifierOrErr.takeError();
1890
1892 ToPack.reserve(T->template_arguments().size());
1893 if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1894 return std::move(Err);
1895
1897 T->getKeyword(),
1898 {*QualifierOrErr, Importer.Import(DTN.getName()),
1899 DTN.hasTemplateKeyword()},
1900 ToPack);
1901}
1902
1904ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1905 auto ToQualifierOrErr = import(T->getQualifier());
1906 if (!ToQualifierOrErr)
1907 return ToQualifierOrErr.takeError();
1908
1909 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1910 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1911 *ToQualifierOrErr, Name);
1912}
1913
1915ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1916 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1917 if (!ToDeclOrErr)
1918 return ToDeclOrErr.takeError();
1919
1920 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1921}
1922
1923ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1924 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1925 if (!ToBaseTypeOrErr)
1926 return ToBaseTypeOrErr.takeError();
1927
1928 SmallVector<QualType, 4> TypeArgs;
1929 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1930 if (ExpectedType TyOrErr = import(TypeArg))
1931 TypeArgs.push_back(*TyOrErr);
1932 else
1933 return TyOrErr.takeError();
1934 }
1935
1937 for (auto *P : T->quals()) {
1938 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1939 Protocols.push_back(*ProtocolOrErr);
1940 else
1941 return ProtocolOrErr.takeError();
1942
1943 }
1944
1945 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1946 Protocols,
1947 T->isKindOfTypeAsWritten());
1948}
1949
1951ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1952 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1953 if (!ToPointeeTypeOrErr)
1954 return ToPointeeTypeOrErr.takeError();
1955
1956 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1957}
1958
1960ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1961 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1962 if (!ToUnderlyingTypeOrErr)
1963 return ToUnderlyingTypeOrErr.takeError();
1964
1965 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1966 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1967 ToIdentifier);
1968}
1969
1970ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1971 Error Err = Error::success();
1972 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1973 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1974 if (Err)
1975 return std::move(Err);
1976
1977 return Importer.getToContext().getAdjustedType(ToOriginalType,
1978 ToAdjustedType);
1979}
1980
1981ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1982 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1983 T->getNumBits());
1984}
1985
1986ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1988 Error Err = Error::success();
1989 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1990 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1991 if (Err)
1992 return std::move(Err);
1993
1994 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1995 ToWrappedType);
1996}
1997
1998ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
2000 Error Err = Error::success();
2001 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
2002 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
2003 QualType ToContainedType = importChecked(Err, T->getContainedType());
2004 if (Err)
2005 return std::move(Err);
2006
2007 return Importer.getToContext().getHLSLAttributedResourceType(
2008 ToWrappedType, ToContainedType, ToAttrs);
2009}
2010
2011ExpectedType clang::ASTNodeImporter::VisitHLSLInlineSpirvType(
2013 Error Err = Error::success();
2014
2015 uint32_t ToOpcode = T->getOpcode();
2016 uint32_t ToSize = T->getSize();
2017 uint32_t ToAlignment = T->getAlignment();
2018
2020
2021 for (auto &Operand : T->getOperands()) {
2022 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
2023
2024 switch (Operand.getKind()) {
2025 case SpirvOperandKind::ConstantId:
2026 ToOperands.push_back(SpirvOperand::createConstant(
2027 importChecked(Err, Operand.getResultType()), Operand.getValue()));
2028 break;
2029 case SpirvOperandKind::Literal:
2030 ToOperands.push_back(SpirvOperand::createLiteral(Operand.getValue()));
2031 break;
2032 case SpirvOperandKind::TypeId:
2033 ToOperands.push_back(SpirvOperand::createType(
2034 importChecked(Err, Operand.getResultType())));
2035 break;
2036 default:
2037 llvm_unreachable("Invalid SpirvOperand kind");
2038 }
2039
2040 if (Err)
2041 return std::move(Err);
2042 }
2043
2044 return Importer.getToContext().getHLSLInlineSpirvType(
2045 ToOpcode, ToSize, ToAlignment, ToOperands);
2046}
2047
2048ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
2050 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2051 if (!ToElementTypeOrErr)
2052 return ToElementTypeOrErr.takeError();
2053
2054 return Importer.getToContext().getConstantMatrixType(
2055 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
2056}
2057
2058ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
2060 Error Err = Error::success();
2061 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
2062 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
2063 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2064 if (Err)
2065 return std::move(Err);
2066
2067 return Importer.getToContext().getDependentAddressSpaceType(
2068 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
2069}
2070
2071ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
2073 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
2074 if (!ToNumBitsExprOrErr)
2075 return ToNumBitsExprOrErr.takeError();
2076 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
2077 *ToNumBitsExprOrErr);
2078}
2079
2080ExpectedType clang::ASTNodeImporter::VisitPredefinedSugarType(
2082 return Importer.getToContext().getPredefinedSugarType(T->getKind());
2083}
2084
2085ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
2087 Error Err = Error::success();
2088 QualType ToElementType = importChecked(Err, T->getElementType());
2089 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
2090 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
2091 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2092 if (Err)
2093 return std::move(Err);
2094
2095 return Importer.getToContext().getDependentSizedMatrixType(
2096 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
2097}
2098
2099ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
2101 Error Err = Error::success();
2102 QualType ToElementType = importChecked(Err, T->getElementType());
2103 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
2104 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
2105 if (Err)
2106 return std::move(Err);
2107
2108 return Importer.getToContext().getDependentVectorType(
2109 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
2110}
2111
2112ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
2113 const clang::ObjCTypeParamType *T) {
2114 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
2115 if (!ToDeclOrErr)
2116 return ToDeclOrErr.takeError();
2117
2119 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
2120 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
2121 if (!ToProtocolOrErr)
2122 return ToProtocolOrErr.takeError();
2123 ToProtocols.push_back(*ToProtocolOrErr);
2124 }
2125
2126 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
2127 ToProtocols);
2128}
2129
2130ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
2131 ExpectedType ToElementTypeOrErr = import(T->getElementType());
2132 if (!ToElementTypeOrErr)
2133 return ToElementTypeOrErr.takeError();
2134
2135 ASTContext &ToCtx = Importer.getToContext();
2136 if (T->isReadOnly())
2137 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
2138 else
2139 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
2140}
2141
2142//----------------------------------------------------------------------------
2143// Import Declarations
2144//----------------------------------------------------------------------------
2146 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
2148 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
2149 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
2150 // FIXME: We could support these constructs by importing a different type of
2151 // this parameter and by importing the original type of the parameter only
2152 // after the FunctionDecl is created. See
2153 // VisitFunctionDecl::UsedDifferentProtoType.
2154 DeclContext *OrigDC = D->getDeclContext();
2155 FunctionDecl *FunDecl;
2156 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
2157 FunDecl->hasBody()) {
2158 auto getLeafPointeeType = [](const Type *T) {
2159 while (T->isPointerType() || T->isArrayType()) {
2161 }
2162 return T;
2163 };
2164 for (const ParmVarDecl *P : FunDecl->parameters()) {
2165 const Type *LeafT =
2166 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
2167 auto *RT = dyn_cast<RecordType>(LeafT);
2168 if (RT && RT->getOriginalDecl() == D) {
2169 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2170 << D->getDeclKindName();
2171 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2172 }
2173 }
2174 }
2175
2176 // Import the context of this declaration.
2177 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2178 return Err;
2179
2180 // Import the name of this declaration.
2181 if (Error Err = importInto(Name, D->getDeclName()))
2182 return Err;
2183
2184 // Import the location of this declaration.
2185 if (Error Err = importInto(Loc, D->getLocation()))
2186 return Err;
2187
2188 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2189 if (ToD)
2190 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2191 return Err;
2192
2193 return Error::success();
2194}
2195
2197 NamedDecl *&ToD, SourceLocation &Loc) {
2198
2199 // Import the name of this declaration.
2200 if (Error Err = importInto(Name, D->getDeclName()))
2201 return Err;
2202
2203 // Import the location of this declaration.
2204 if (Error Err = importInto(Loc, D->getLocation()))
2205 return Err;
2206
2207 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
2208 if (ToD)
2209 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
2210 return Err;
2211
2212 return Error::success();
2213}
2214
2216 if (!FromD)
2217 return Error::success();
2218
2219 if (!ToD)
2220 if (Error Err = importInto(ToD, FromD))
2221 return Err;
2222
2223 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2224 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2225 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2226 !ToRecord->getDefinition()) {
2227 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2228 return Err;
2229 }
2230 }
2231 return Error::success();
2232 }
2233
2234 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2235 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2236 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2237 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2238 return Err;
2239 }
2240 }
2241 return Error::success();
2242 }
2243
2244 return Error::success();
2245}
2246
2247Error
2249 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2250 // NOTE: To.Name and To.Loc are already imported.
2251 // We only have to import To.LocInfo.
2252 switch (To.getName().getNameKind()) {
2259 return Error::success();
2260
2262 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2263 To.setCXXOperatorNameRange(*ToRangeOrErr);
2264 else
2265 return ToRangeOrErr.takeError();
2266 return Error::success();
2267 }
2269 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2270 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2271 else
2272 return LocOrErr.takeError();
2273 return Error::success();
2274 }
2278 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2279 To.setNamedTypeInfo(*ToTInfoOrErr);
2280 else
2281 return ToTInfoOrErr.takeError();
2282 return Error::success();
2283 }
2284 }
2285 llvm_unreachable("Unknown name kind.");
2286}
2287
2288Error
2290 if (Importer.isMinimalImport() && !ForceImport) {
2291 auto ToDCOrErr = Importer.ImportContext(FromDC);
2292 return ToDCOrErr.takeError();
2293 }
2294
2295 // We use strict error handling in case of records and enums, but not
2296 // with e.g. namespaces.
2297 //
2298 // FIXME Clients of the ASTImporter should be able to choose an
2299 // appropriate error handling strategy for their needs. For instance,
2300 // they may not want to mark an entire namespace as erroneous merely
2301 // because there is an ODR error with two typedefs. As another example,
2302 // the client may allow EnumConstantDecls with same names but with
2303 // different values in two distinct translation units.
2304 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2305
2306 auto MightNeedReordering = [](const Decl *D) {
2307 return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2308 };
2309
2310 // Import everything that might need reordering first.
2311 Error ChildErrors = Error::success();
2312 for (auto *From : FromDC->decls()) {
2313 if (!MightNeedReordering(From))
2314 continue;
2315
2316 ExpectedDecl ImportedOrErr = import(From);
2317
2318 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2319 // want to make sure that we are also completing each FieldDecl. There
2320 // are currently cases where this does not happen and this is correctness
2321 // fix since operations such as code generation will expect this to be so.
2322 if (!ImportedOrErr) {
2323 HandleChildErrors.handleChildImportResult(ChildErrors,
2324 ImportedOrErr.takeError());
2325 continue;
2326 }
2327 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2328 Decl *ImportedDecl = *ImportedOrErr;
2329 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2330 if (FieldFrom && FieldTo) {
2331 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2332 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2333 }
2334 }
2335
2336 // We reorder declarations in RecordDecls because they may have another order
2337 // in the "to" context than they have in the "from" context. This may happen
2338 // e.g when we import a class like this:
2339 // struct declToImport {
2340 // int a = c + b;
2341 // int b = 1;
2342 // int c = 2;
2343 // };
2344 // During the import of `a` we import first the dependencies in sequence,
2345 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2346 // first removing the already imported members and then adding them in the
2347 // order as they appear in the "from" context.
2348 //
2349 // Keeping field order is vital because it determines structure layout.
2350 //
2351 // Here and below, we cannot call field_begin() method and its callers on
2352 // ToDC if it has an external storage. Calling field_begin() will
2353 // automatically load all the fields by calling
2354 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2355 // call ASTImporter::Import(). This is because the ExternalASTSource
2356 // interface in LLDB is implemented by the means of the ASTImporter. However,
2357 // calling an import at this point would result in an uncontrolled import, we
2358 // must avoid that.
2359
2360 auto ToDCOrErr = Importer.ImportContext(FromDC);
2361 if (!ToDCOrErr) {
2362 consumeError(std::move(ChildErrors));
2363 return ToDCOrErr.takeError();
2364 }
2365
2366 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2367 DeclContext *ToDC = *ToDCOrErr;
2368 // Remove all declarations, which may be in wrong order in the
2369 // lexical DeclContext and then add them in the proper order.
2370 for (auto *D : FromRD->decls()) {
2371 if (!MightNeedReordering(D))
2372 continue;
2373
2374 assert(D && "DC contains a null decl");
2375 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2376 // Remove only the decls which we successfully imported.
2377 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2378 // Remove the decl from its wrong place in the linked list.
2379 ToDC->removeDecl(ToD);
2380 // Add the decl to the end of the linked list.
2381 // This time it will be at the proper place because the enclosing for
2382 // loop iterates in the original (good) order of the decls.
2383 ToDC->addDeclInternal(ToD);
2384 }
2385 }
2386 }
2387
2388 // Import everything else.
2389 for (auto *From : FromDC->decls()) {
2390 if (MightNeedReordering(From))
2391 continue;
2392
2393 ExpectedDecl ImportedOrErr = import(From);
2394 if (!ImportedOrErr)
2395 HandleChildErrors.handleChildImportResult(ChildErrors,
2396 ImportedOrErr.takeError());
2397 }
2398
2399 return ChildErrors;
2400}
2401
2403 const FieldDecl *To) {
2404 RecordDecl *FromRecordDecl = nullptr;
2405 RecordDecl *ToRecordDecl = nullptr;
2406 // If we have a field that is an ArrayType we need to check if the array
2407 // element is a RecordDecl and if so we need to import the definition.
2408 QualType FromType = From->getType();
2409 QualType ToType = To->getType();
2410 if (FromType->isArrayType()) {
2411 // getBaseElementTypeUnsafe(...) handles multi-dimensional arrays for us.
2412 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2413 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2414 }
2415
2416 if (!FromRecordDecl || !ToRecordDecl) {
2417 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2418 const RecordType *RecordTo = ToType->getAs<RecordType>();
2419
2420 if (RecordFrom && RecordTo) {
2421 FromRecordDecl = RecordFrom->getOriginalDecl();
2422 ToRecordDecl = RecordTo->getOriginalDecl();
2423 }
2424 }
2425
2426 if (FromRecordDecl && ToRecordDecl) {
2427 if (FromRecordDecl->isCompleteDefinition() &&
2428 !ToRecordDecl->isCompleteDefinition())
2429 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2430 }
2431
2432 return Error::success();
2433}
2434
2436 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2437 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2438 if (!ToDCOrErr)
2439 return ToDCOrErr.takeError();
2440 ToDC = *ToDCOrErr;
2441
2442 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2443 auto ToLexicalDCOrErr = Importer.ImportContext(
2444 FromD->getLexicalDeclContext());
2445 if (!ToLexicalDCOrErr)
2446 return ToLexicalDCOrErr.takeError();
2447 ToLexicalDC = *ToLexicalDCOrErr;
2448 } else
2449 ToLexicalDC = ToDC;
2450
2451 return Error::success();
2452}
2453
2455 const CXXRecordDecl *From, CXXRecordDecl *To) {
2456 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2457 "Import implicit methods to or from non-definition");
2458
2459 for (CXXMethodDecl *FromM : From->methods())
2460 if (FromM->isImplicit()) {
2461 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2462 if (!ToMOrErr)
2463 return ToMOrErr.takeError();
2464 }
2465
2466 return Error::success();
2467}
2468
2470 ASTImporter &Importer) {
2471 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2472 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2473 To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2474 else
2475 return ToTypedefOrErr.takeError();
2476 }
2477 return Error::success();
2478}
2479
2481 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2482 auto DefinitionCompleter = [To]() {
2483 // There are cases in LLDB when we first import a class without its
2484 // members. The class will have DefinitionData, but no members. Then,
2485 // importDefinition is called from LLDB, which tries to get the members, so
2486 // when we get here, the class already has the DefinitionData set, so we
2487 // must unset the CompleteDefinition here to be able to complete again the
2488 // definition.
2489 To->setCompleteDefinition(false);
2490 To->completeDefinition();
2491 };
2492
2493 if (To->getDefinition() || To->isBeingDefined()) {
2494 if (Kind == IDK_Everything ||
2495 // In case of lambdas, the class already has a definition ptr set, but
2496 // the contained decls are not imported yet. Also, isBeingDefined was
2497 // set in CXXRecordDecl::CreateLambda. We must import the contained
2498 // decls here and finish the definition.
2499 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2500 if (To->isLambda()) {
2501 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2503 ToCaptures.reserve(FromCXXRD->capture_size());
2504 for (const auto &FromCapture : FromCXXRD->captures()) {
2505 if (auto ToCaptureOrErr = import(FromCapture))
2506 ToCaptures.push_back(*ToCaptureOrErr);
2507 else
2508 return ToCaptureOrErr.takeError();
2509 }
2510 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2511 ToCaptures);
2512 }
2513
2514 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2515 // Finish the definition of the lambda, set isBeingDefined to false.
2516 if (To->isLambda())
2517 DefinitionCompleter();
2518 return Result;
2519 }
2520
2521 return Error::success();
2522 }
2523
2524 To->startDefinition();
2525 // Set the definition to complete even if it is really not complete during
2526 // import. Some AST constructs (expressions) require the record layout
2527 // to be calculated (see 'clang::computeDependence') at the time they are
2528 // constructed. Import of such AST node is possible during import of the
2529 // same record, there is no way to have a completely defined record (all
2530 // fields imported) at that time without multiple AST import passes.
2531 if (!Importer.isMinimalImport())
2532 To->setCompleteDefinition(true);
2533 // Complete the definition even if error is returned.
2534 // The RecordDecl may be already part of the AST so it is better to
2535 // have it in complete state even if something is wrong with it.
2536 auto DefinitionCompleterScopeExit =
2537 llvm::make_scope_exit(DefinitionCompleter);
2538
2539 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2540 return Err;
2541
2542 // Add base classes.
2543 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2544 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2545 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2546
2547 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2548 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2549
2550 #define FIELD(Name, Width, Merge) \
2551 ToData.Name = FromData.Name;
2552 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2553
2554 // Copy over the data stored in RecordDeclBits
2555 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2556
2558 for (const auto &Base1 : FromCXX->bases()) {
2559 ExpectedType TyOrErr = import(Base1.getType());
2560 if (!TyOrErr)
2561 return TyOrErr.takeError();
2562
2563 SourceLocation EllipsisLoc;
2564 if (Base1.isPackExpansion()) {
2565 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2566 EllipsisLoc = *LocOrErr;
2567 else
2568 return LocOrErr.takeError();
2569 }
2570
2571 // Ensure that we have a definition for the base.
2572 if (Error Err =
2573 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2574 return Err;
2575
2576 auto RangeOrErr = import(Base1.getSourceRange());
2577 if (!RangeOrErr)
2578 return RangeOrErr.takeError();
2579
2580 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2581 if (!TSIOrErr)
2582 return TSIOrErr.takeError();
2583
2584 Bases.push_back(
2585 new (Importer.getToContext()) CXXBaseSpecifier(
2586 *RangeOrErr,
2587 Base1.isVirtual(),
2588 Base1.isBaseOfClass(),
2589 Base1.getAccessSpecifierAsWritten(),
2590 *TSIOrErr,
2591 EllipsisLoc));
2592 }
2593 if (!Bases.empty())
2594 ToCXX->setBases(Bases.data(), Bases.size());
2595 }
2596
2598 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2599 return Err;
2600 }
2601
2602 return Error::success();
2603}
2604
2606 if (To->getAnyInitializer())
2607 return Error::success();
2608
2609 Expr *FromInit = From->getInit();
2610 if (!FromInit)
2611 return Error::success();
2612
2613 ExpectedExpr ToInitOrErr = import(FromInit);
2614 if (!ToInitOrErr)
2615 return ToInitOrErr.takeError();
2616
2617 To->setInit(*ToInitOrErr);
2618 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2619 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2620 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2621 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2622 // FIXME: Also import the initializer value.
2623 }
2624
2625 // FIXME: Other bits to merge?
2626 return Error::success();
2627}
2628
2631 if (To->getDefinition() || To->isBeingDefined()) {
2632 if (Kind == IDK_Everything)
2633 return ImportDeclContext(From, /*ForceImport=*/true);
2634 return Error::success();
2635 }
2636
2637 To->startDefinition();
2638
2639 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2640 return Err;
2641
2642 ExpectedType ToTypeOrErr =
2643 import(QualType(Importer.getFromContext().getCanonicalTagType(From)));
2644 if (!ToTypeOrErr)
2645 return ToTypeOrErr.takeError();
2646
2647 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2648 if (!ToPromotionTypeOrErr)
2649 return ToPromotionTypeOrErr.takeError();
2650
2652 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2653 return Err;
2654
2655 // FIXME: we might need to merge the number of positive or negative bits
2656 // if the enumerator lists don't match.
2657 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2658 From->getNumPositiveBits(),
2659 From->getNumNegativeBits());
2660 return Error::success();
2661}
2662
2666 for (const auto &Arg : FromArgs) {
2667 if (auto ToOrErr = import(Arg))
2668 ToArgs.push_back(*ToOrErr);
2669 else
2670 return ToOrErr.takeError();
2671 }
2672
2673 return Error::success();
2674}
2675
2676// FIXME: Do not forget to remove this and use only 'import'.
2679 return import(From);
2680}
2681
2682template <typename InContainerTy>
2684 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2685 for (const auto &FromLoc : Container) {
2686 if (auto ToLocOrErr = import(FromLoc))
2687 ToTAInfo.addArgument(*ToLocOrErr);
2688 else
2689 return ToLocOrErr.takeError();
2690 }
2691 return Error::success();
2692}
2693
2698}
2699
2700bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2701 bool IgnoreTemplateParmDepth) {
2702 // Eliminate a potential failure point where we attempt to re-import
2703 // something we're trying to import while completing ToRecord.
2704 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2705 if (ToOrigin) {
2706 To = ToOrigin;
2707 }
2708
2710 Importer.getToContext().getLangOpts(), Importer.getFromContext(),
2711 Importer.getToContext(), Importer.getNonEquivalentDecls(),
2713 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2714 IgnoreTemplateParmDepth);
2715 return Ctx.IsEquivalent(From, To);
2716}
2717
2719 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2720 << D->getDeclKindName();
2721 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2722}
2723
2725 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2726 << D->getDeclKindName();
2727 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2728}
2729
2731 // Import the context of this declaration.
2732 DeclContext *DC, *LexicalDC;
2733 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2734 return std::move(Err);
2735
2736 // Import the location of this declaration.
2737 ExpectedSLoc LocOrErr = import(D->getLocation());
2738 if (!LocOrErr)
2739 return LocOrErr.takeError();
2740
2741 EmptyDecl *ToD;
2742 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2743 return ToD;
2744
2745 ToD->setLexicalDeclContext(LexicalDC);
2746 LexicalDC->addDeclInternal(ToD);
2747 return ToD;
2748}
2749
2751 TranslationUnitDecl *ToD =
2753
2754 Importer.MapImported(D, ToD);
2755
2756 return ToD;
2757}
2758
2760 DeclContext *DC, *LexicalDC;
2761 DeclarationName Name;
2763 NamedDecl *ToND;
2764 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2765 return std::move(Err);
2766 if (ToND)
2767 return ToND;
2768
2769 BindingDecl *ToD;
2770 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2771 Name.getAsIdentifierInfo(), D->getType()))
2772 return ToD;
2773
2774 Error Err = Error::success();
2775 QualType ToType = importChecked(Err, D->getType());
2776 Expr *ToBinding = importChecked(Err, D->getBinding());
2777 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2778 if (Err)
2779 return std::move(Err);
2780
2781 ToD->setBinding(ToType, ToBinding);
2782 ToD->setDecomposedDecl(ToDecomposedDecl);
2783 addDeclToContexts(D, ToD);
2784
2785 return ToD;
2786}
2787
2789 ExpectedSLoc LocOrErr = import(D->getLocation());
2790 if (!LocOrErr)
2791 return LocOrErr.takeError();
2792 auto ColonLocOrErr = import(D->getColonLoc());
2793 if (!ColonLocOrErr)
2794 return ColonLocOrErr.takeError();
2795
2796 // Import the context of this declaration.
2797 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2798 if (!DCOrErr)
2799 return DCOrErr.takeError();
2800 DeclContext *DC = *DCOrErr;
2801
2802 AccessSpecDecl *ToD;
2803 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2804 DC, *LocOrErr, *ColonLocOrErr))
2805 return ToD;
2806
2807 // Lexical DeclContext and Semantic DeclContext
2808 // is always the same for the accessSpec.
2809 ToD->setLexicalDeclContext(DC);
2810 DC->addDeclInternal(ToD);
2811
2812 return ToD;
2813}
2814
2816 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2817 if (!DCOrErr)
2818 return DCOrErr.takeError();
2819 DeclContext *DC = *DCOrErr;
2820 DeclContext *LexicalDC = DC;
2821
2822 Error Err = Error::success();
2823 auto ToLocation = importChecked(Err, D->getLocation());
2824 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2825 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2826 auto ToMessage = importChecked(Err, D->getMessage());
2827 if (Err)
2828 return std::move(Err);
2829
2830 StaticAssertDecl *ToD;
2831 if (GetImportedOrCreateDecl(
2832 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2833 ToRParenLoc, D->isFailed()))
2834 return ToD;
2835
2836 ToD->setLexicalDeclContext(LexicalDC);
2837 LexicalDC->addDeclInternal(ToD);
2838 return ToD;
2839}
2840
2842 // Import the major distinguishing characteristics of this namespace.
2843 DeclContext *DC, *LexicalDC;
2844 DeclarationName Name;
2846 NamedDecl *ToD;
2847 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2848 return std::move(Err);
2849 if (ToD)
2850 return ToD;
2851
2852 NamespaceDecl *MergeWithNamespace = nullptr;
2853 if (!Name) {
2854 // This is an anonymous namespace. Adopt an existing anonymous
2855 // namespace if we can.
2856 DeclContext *EnclosingDC = DC->getEnclosingNamespaceContext();
2857 if (auto *TU = dyn_cast<TranslationUnitDecl>(EnclosingDC))
2858 MergeWithNamespace = TU->getAnonymousNamespace();
2859 else
2860 MergeWithNamespace =
2861 cast<NamespaceDecl>(EnclosingDC)->getAnonymousNamespace();
2862 } else {
2863 SmallVector<NamedDecl *, 4> ConflictingDecls;
2864 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2865 for (auto *FoundDecl : FoundDecls) {
2867 continue;
2868
2869 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2870 MergeWithNamespace = FoundNS;
2871 ConflictingDecls.clear();
2872 break;
2873 }
2874
2875 ConflictingDecls.push_back(FoundDecl);
2876 }
2877
2878 if (!ConflictingDecls.empty()) {
2879 ExpectedName NameOrErr = Importer.HandleNameConflict(
2880 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2881 ConflictingDecls.size());
2882 if (NameOrErr)
2883 Name = NameOrErr.get();
2884 else
2885 return NameOrErr.takeError();
2886 }
2887 }
2888
2889 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2890 if (!BeginLocOrErr)
2891 return BeginLocOrErr.takeError();
2892 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2893 if (!RBraceLocOrErr)
2894 return RBraceLocOrErr.takeError();
2895
2896 // Create the "to" namespace, if needed.
2897 NamespaceDecl *ToNamespace = MergeWithNamespace;
2898 if (!ToNamespace) {
2899 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2900 D->isInline(), *BeginLocOrErr, Loc,
2901 Name.getAsIdentifierInfo(),
2902 /*PrevDecl=*/nullptr, D->isNested()))
2903 return ToNamespace;
2904 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2905 ToNamespace->setLexicalDeclContext(LexicalDC);
2906 LexicalDC->addDeclInternal(ToNamespace);
2907
2908 // If this is an anonymous namespace, register it as the anonymous
2909 // namespace within its context.
2910 if (!Name) {
2911 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2912 TU->setAnonymousNamespace(ToNamespace);
2913 else
2914 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2915 }
2916 }
2917 Importer.MapImported(D, ToNamespace);
2918
2919 if (Error Err = ImportDeclContext(D))
2920 return std::move(Err);
2921
2922 return ToNamespace;
2923}
2924
2926 // Import the major distinguishing characteristics of this namespace.
2927 DeclContext *DC, *LexicalDC;
2928 DeclarationName Name;
2930 NamedDecl *LookupD;
2931 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2932 return std::move(Err);
2933 if (LookupD)
2934 return LookupD;
2935
2936 // NOTE: No conflict resolution is done for namespace aliases now.
2937
2938 Error Err = Error::success();
2939 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2940 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2941 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2942 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2943 auto ToNamespace = importChecked(Err, D->getNamespace());
2944 if (Err)
2945 return std::move(Err);
2946
2947 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2948
2949 NamespaceAliasDecl *ToD;
2950 if (GetImportedOrCreateDecl(
2951 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2952 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2953 return ToD;
2954
2955 ToD->setLexicalDeclContext(LexicalDC);
2956 LexicalDC->addDeclInternal(ToD);
2957
2958 return ToD;
2959}
2960
2963 // Import the major distinguishing characteristics of this typedef.
2964 DeclarationName Name;
2966 NamedDecl *ToD;
2967 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2968 // is created.
2969 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2970 return std::move(Err);
2971 if (ToD)
2972 return ToD;
2973
2974 DeclContext *DC = cast_or_null<DeclContext>(
2975 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2976 DeclContext *LexicalDC =
2977 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2978 cast<Decl>(D->getLexicalDeclContext())));
2979
2980 // If this typedef is not in block scope, determine whether we've
2981 // seen a typedef with the same name (that we can merge with) or any
2982 // other entity by that name (which name lookup could conflict with).
2983 // Note: Repeated typedefs are not valid in C99:
2984 // 'typedef int T; typedef int T;' is invalid
2985 // We do not care about this now.
2986 if (DC && !DC->isFunctionOrMethod()) {
2987 SmallVector<NamedDecl *, 4> ConflictingDecls;
2988 unsigned IDNS = Decl::IDNS_Ordinary;
2989 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2990 for (auto *FoundDecl : FoundDecls) {
2991 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2992 continue;
2993 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2994 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2995 continue;
2996
2997 QualType FromUT = D->getUnderlyingType();
2998 QualType FoundUT = FoundTypedef->getUnderlyingType();
2999 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
3000 // If the underlying declarations are unnamed records these can be
3001 // imported as different types. We should create a distinct typedef
3002 // node in this case.
3003 // If we found an existing underlying type with a record in a
3004 // different context (than the imported), this is already reason for
3005 // having distinct typedef nodes for these.
3006 // Again this can create situation like
3007 // 'typedef int T; typedef int T;' but this is hard to avoid without
3008 // a rename strategy at import.
3009 if (!FromUT.isNull() && !FoundUT.isNull()) {
3010 RecordDecl *FromR = FromUT->getAsRecordDecl();
3011 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
3012 if (FromR && FoundR &&
3013 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
3014 continue;
3015 }
3016 // If the "From" context has a complete underlying type but we
3017 // already have a complete underlying type then return with that.
3018 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
3019 return Importer.MapImported(D, FoundTypedef);
3020 // FIXME Handle redecl chain. When you do that make consistent changes
3021 // in ASTImporterLookupTable too.
3022 } else {
3023 ConflictingDecls.push_back(FoundDecl);
3024 }
3025 }
3026 }
3027
3028 if (!ConflictingDecls.empty()) {
3029 ExpectedName NameOrErr = Importer.HandleNameConflict(
3030 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3031 if (NameOrErr)
3032 Name = NameOrErr.get();
3033 else
3034 return NameOrErr.takeError();
3035 }
3036 }
3037
3038 Error Err = Error::success();
3039 auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType());
3040 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
3041 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3042 if (Err)
3043 return std::move(Err);
3044
3045 // Create the new typedef node.
3046 // FIXME: ToUnderlyingType is not used.
3047 (void)ToUnderlyingType;
3048 TypedefNameDecl *ToTypedef;
3049 if (IsAlias) {
3050 if (GetImportedOrCreateDecl<TypeAliasDecl>(
3051 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3052 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3053 return ToTypedef;
3054 } else if (GetImportedOrCreateDecl<TypedefDecl>(
3055 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
3056 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
3057 return ToTypedef;
3058
3059 // Import the DeclContext and set it to the Typedef.
3060 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
3061 return std::move(Err);
3062 ToTypedef->setDeclContext(DC);
3063 ToTypedef->setLexicalDeclContext(LexicalDC);
3064 // Add to the lookupTable because we could not do that in MapImported.
3065 Importer.AddToLookupTable(ToTypedef);
3066
3067 ToTypedef->setAccess(D->getAccess());
3068
3069 // Templated declarations should not appear in DeclContext.
3070 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
3071 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
3072 LexicalDC->addDeclInternal(ToTypedef);
3073
3074 return ToTypedef;
3075}
3076
3078 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
3079}
3080
3082 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
3083}
3084
3087 // Import the major distinguishing characteristics of this typedef.
3088 DeclContext *DC, *LexicalDC;
3089 DeclarationName Name;
3091 NamedDecl *FoundD;
3092 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
3093 return std::move(Err);
3094 if (FoundD)
3095 return FoundD;
3096
3097 // If this typedef is not in block scope, determine whether we've
3098 // seen a typedef with the same name (that we can merge with) or any
3099 // other entity by that name (which name lookup could conflict with).
3100 if (!DC->isFunctionOrMethod()) {
3101 SmallVector<NamedDecl *, 4> ConflictingDecls;
3102 unsigned IDNS = Decl::IDNS_Ordinary;
3103 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3104 for (auto *FoundDecl : FoundDecls) {
3105 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3106 continue;
3107 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
3108 if (IsStructuralMatch(D, FoundAlias))
3109 return Importer.MapImported(D, FoundAlias);
3110 ConflictingDecls.push_back(FoundDecl);
3111 }
3112 }
3113
3114 if (!ConflictingDecls.empty()) {
3115 ExpectedName NameOrErr = Importer.HandleNameConflict(
3116 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3117 if (NameOrErr)
3118 Name = NameOrErr.get();
3119 else
3120 return NameOrErr.takeError();
3121 }
3122 }
3123
3124 Error Err = Error::success();
3125 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
3126 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
3127 if (Err)
3128 return std::move(Err);
3129
3130 TypeAliasTemplateDecl *ToAlias;
3131 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
3132 Name, ToTemplateParameters, ToTemplatedDecl))
3133 return ToAlias;
3134
3135 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
3136
3137 ToAlias->setAccess(D->getAccess());
3138 ToAlias->setLexicalDeclContext(LexicalDC);
3139 LexicalDC->addDeclInternal(ToAlias);
3140 if (DC != Importer.getToContext().getTranslationUnitDecl())
3141 updateLookupTableForTemplateParameters(*ToTemplateParameters);
3142 return ToAlias;
3143}
3144
3146 // Import the major distinguishing characteristics of this label.
3147 DeclContext *DC, *LexicalDC;
3148 DeclarationName Name;
3150 NamedDecl *ToD;
3151 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3152 return std::move(Err);
3153 if (ToD)
3154 return ToD;
3155
3156 assert(LexicalDC->isFunctionOrMethod());
3157
3158 LabelDecl *ToLabel;
3159 if (D->isGnuLocal()) {
3160 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3161 if (!BeginLocOrErr)
3162 return BeginLocOrErr.takeError();
3163 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3164 Name.getAsIdentifierInfo(), *BeginLocOrErr))
3165 return ToLabel;
3166
3167 } else {
3168 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
3169 Name.getAsIdentifierInfo()))
3170 return ToLabel;
3171
3172 }
3173
3174 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
3175 if (!ToStmtOrErr)
3176 return ToStmtOrErr.takeError();
3177
3178 ToLabel->setStmt(*ToStmtOrErr);
3179 ToLabel->setLexicalDeclContext(LexicalDC);
3180 LexicalDC->addDeclInternal(ToLabel);
3181 return ToLabel;
3182}
3183
3185 // Import the major distinguishing characteristics of this enum.
3186 DeclContext *DC, *LexicalDC;
3187 DeclarationName Name;
3189 NamedDecl *ToD;
3190 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3191 return std::move(Err);
3192 if (ToD)
3193 return ToD;
3194
3195 // Figure out what enum name we're looking for.
3196 unsigned IDNS = Decl::IDNS_Tag;
3197 DeclarationName SearchName = Name;
3198 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3199 if (Error Err = importInto(
3200 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3201 return std::move(Err);
3202 IDNS = Decl::IDNS_Ordinary;
3203 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3204 IDNS |= Decl::IDNS_Ordinary;
3205
3206 // We may already have an enum of the same name; try to find and match it.
3207 EnumDecl *PrevDecl = nullptr;
3208 if (!DC->isFunctionOrMethod()) {
3209 SmallVector<NamedDecl *, 4> ConflictingDecls;
3210 auto FoundDecls =
3211 Importer.findDeclsInToCtx(DC, SearchName);
3212 for (auto *FoundDecl : FoundDecls) {
3213 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3214 continue;
3215
3216 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3217 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3218 FoundDecl = Tag->getOriginalDecl();
3219 }
3220
3221 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3222 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3223 continue;
3224 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3225 EnumDecl *FoundDef = FoundEnum->getDefinition();
3226 if (D->isThisDeclarationADefinition() && FoundDef)
3227 return Importer.MapImported(D, FoundDef);
3228 PrevDecl = FoundEnum->getMostRecentDecl();
3229 break;
3230 }
3231 ConflictingDecls.push_back(FoundDecl);
3232 }
3233 }
3234
3235 // In case of unnamed enums, we try to find an existing similar one, if none
3236 // was found, perform the import always.
3237 // Structural in-equivalence is not detected in this way here, but it may
3238 // be found when the parent decl is imported (if the enum is part of a
3239 // class). To make this totally exact a more difficult solution is needed.
3240 if (SearchName && !ConflictingDecls.empty()) {
3241 ExpectedName NameOrErr = Importer.HandleNameConflict(
3242 SearchName, DC, IDNS, ConflictingDecls.data(),
3243 ConflictingDecls.size());
3244 if (NameOrErr)
3245 Name = NameOrErr.get();
3246 else
3247 return NameOrErr.takeError();
3248 }
3249 }
3250
3251 Error Err = Error::success();
3252 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3253 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3254 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3255 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3256 if (Err)
3257 return std::move(Err);
3258
3259 // Create the enum declaration.
3260 EnumDecl *D2;
3261 if (GetImportedOrCreateDecl(
3262 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3263 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3264 D->isScopedUsingClassTag(), D->isFixed()))
3265 return D2;
3266
3267 D2->setQualifierInfo(ToQualifierLoc);
3268 D2->setIntegerType(ToIntegerType);
3269 D2->setBraceRange(ToBraceRange);
3270 D2->setAccess(D->getAccess());
3271 D2->setLexicalDeclContext(LexicalDC);
3272 addDeclToContexts(D, D2);
3273
3274 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
3275 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3276 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3277 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3278 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3279 else
3280 return ToInstOrErr.takeError();
3281 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3283 else
3284 return POIOrErr.takeError();
3285 }
3286
3287 // Import the definition
3288 if (D->isCompleteDefinition())
3289 if (Error Err = ImportDefinition(D, D2))
3290 return std::move(Err);
3291
3292 return D2;
3293}
3294
3296 bool IsFriendTemplate = false;
3297 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3298 IsFriendTemplate =
3299 DCXX->getDescribedClassTemplate() &&
3300 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3302 }
3303
3304 // Import the major distinguishing characteristics of this record.
3305 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3306 DeclarationName Name;
3308 NamedDecl *ToD = nullptr;
3309 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3310 return std::move(Err);
3311 if (ToD)
3312 return ToD;
3313
3314 // Figure out what structure name we're looking for.
3315 unsigned IDNS = Decl::IDNS_Tag;
3316 DeclarationName SearchName = Name;
3317 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3318 if (Error Err = importInto(
3319 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3320 return std::move(Err);
3321 IDNS = Decl::IDNS_Ordinary;
3322 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3324
3325 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3326 : DC->isDependentContext();
3327 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3328
3329 // We may already have a record of the same name; try to find and match it.
3330 RecordDecl *PrevDecl = nullptr;
3331 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3332 SmallVector<NamedDecl *, 4> ConflictingDecls;
3333 auto FoundDecls =
3334 Importer.findDeclsInToCtx(DC, SearchName);
3335 if (!FoundDecls.empty()) {
3336 // We're going to have to compare D against potentially conflicting Decls,
3337 // so complete it.
3338 if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition())
3340 }
3341
3342 for (auto *FoundDecl : FoundDecls) {
3343 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3344 continue;
3345
3346 Decl *Found = FoundDecl;
3347 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3348 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3349 Found = Tag->getOriginalDecl();
3350 }
3351
3352 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3353 // Do not emit false positive diagnostic in case of unnamed
3354 // struct/union and in case of anonymous structs. Would be false
3355 // because there may be several anonymous/unnamed structs in a class.
3356 // E.g. these are both valid:
3357 // struct A { // unnamed structs
3358 // struct { struct A *next; } entry0;
3359 // struct { struct A *next; } entry1;
3360 // };
3361 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3362 if (!SearchName)
3363 if (!IsStructuralMatch(D, FoundRecord, false))
3364 continue;
3365
3366 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3367 continue;
3368
3369 if (IsStructuralMatch(D, FoundRecord)) {
3370 RecordDecl *FoundDef = FoundRecord->getDefinition();
3371 if (D->isThisDeclarationADefinition() && FoundDef) {
3372 // FIXME: Structural equivalence check should check for same
3373 // user-defined methods.
3374 Importer.MapImported(D, FoundDef);
3375 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3376 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3377 assert(FoundCXX && "Record type mismatch");
3378
3379 if (!Importer.isMinimalImport())
3380 // FoundDef may not have every implicit method that D has
3381 // because implicit methods are created only if they are used.
3382 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3383 return std::move(Err);
3384 }
3385 // FIXME: We can return FoundDef here.
3386 }
3387 PrevDecl = FoundRecord->getMostRecentDecl();
3388 break;
3389 }
3390 ConflictingDecls.push_back(FoundDecl);
3391 } // kind is RecordDecl
3392 } // for
3393
3394 if (!ConflictingDecls.empty() && SearchName) {
3395 ExpectedName NameOrErr = Importer.HandleNameConflict(
3396 SearchName, DC, IDNS, ConflictingDecls.data(),
3397 ConflictingDecls.size());
3398 if (NameOrErr)
3399 Name = NameOrErr.get();
3400 else
3401 return NameOrErr.takeError();
3402 }
3403 }
3404
3405 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3406 if (!BeginLocOrErr)
3407 return BeginLocOrErr.takeError();
3408
3409 // Create the record declaration.
3410 RecordDecl *D2 = nullptr;
3411 CXXRecordDecl *D2CXX = nullptr;
3412 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3413 if (DCXX->isLambda()) {
3414 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3415 if (!TInfoOrErr)
3416 return TInfoOrErr.takeError();
3417 if (GetImportedOrCreateSpecialDecl(
3418 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3419 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3420 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3421 return D2CXX;
3422 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3423 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3424 if (!CDeclOrErr)
3425 return CDeclOrErr.takeError();
3426 Numbering.ContextDecl = *CDeclOrErr;
3427 D2CXX->setLambdaNumbering(Numbering);
3428 } else {
3429 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3430 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3431 Name.getAsIdentifierInfo(),
3432 cast_or_null<CXXRecordDecl>(PrevDecl)))
3433 return D2CXX;
3434 }
3435
3436 D2 = D2CXX;
3437 D2->setAccess(D->getAccess());
3438 D2->setLexicalDeclContext(LexicalDC);
3439 addDeclToContexts(D, D2);
3440
3441 if (ClassTemplateDecl *FromDescribed =
3442 DCXX->getDescribedClassTemplate()) {
3443 ClassTemplateDecl *ToDescribed;
3444 if (Error Err = importInto(ToDescribed, FromDescribed))
3445 return std::move(Err);
3446 D2CXX->setDescribedClassTemplate(ToDescribed);
3447 } else if (MemberSpecializationInfo *MemberInfo =
3448 DCXX->getMemberSpecializationInfo()) {
3450 MemberInfo->getTemplateSpecializationKind();
3452
3453 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3454 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3455 else
3456 return ToInstOrErr.takeError();
3457
3458 if (ExpectedSLoc POIOrErr =
3459 import(MemberInfo->getPointOfInstantiation()))
3461 *POIOrErr);
3462 else
3463 return POIOrErr.takeError();
3464 }
3465
3466 } else {
3467 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3468 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3469 Name.getAsIdentifierInfo(), PrevDecl))
3470 return D2;
3471 D2->setLexicalDeclContext(LexicalDC);
3472 addDeclToContexts(D, D2);
3473 }
3474
3475 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3476 D2->setBraceRange(*BraceRangeOrErr);
3477 else
3478 return BraceRangeOrErr.takeError();
3479 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3480 D2->setQualifierInfo(*QualifierLocOrErr);
3481 else
3482 return QualifierLocOrErr.takeError();
3483
3484 if (D->isAnonymousStructOrUnion())
3485 D2->setAnonymousStructOrUnion(true);
3486
3487 if (D->isCompleteDefinition())
3488 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3489 return std::move(Err);
3490
3491 return D2;
3492}
3493
3495 // Import the major distinguishing characteristics of this enumerator.
3496 DeclContext *DC, *LexicalDC;
3497 DeclarationName Name;
3499 NamedDecl *ToD;
3500 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3501 return std::move(Err);
3502 if (ToD)
3503 return ToD;
3504
3505 // Determine whether there are any other declarations with the same name and
3506 // in the same context.
3507 if (!LexicalDC->isFunctionOrMethod()) {
3508 SmallVector<NamedDecl *, 4> ConflictingDecls;
3509 unsigned IDNS = Decl::IDNS_Ordinary;
3510 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3511 for (auto *FoundDecl : FoundDecls) {
3512 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3513 continue;
3514
3515 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3516 if (IsStructuralMatch(D, FoundEnumConstant))
3517 return Importer.MapImported(D, FoundEnumConstant);
3518 ConflictingDecls.push_back(FoundDecl);
3519 }
3520 }
3521
3522 if (!ConflictingDecls.empty()) {
3523 ExpectedName NameOrErr = Importer.HandleNameConflict(
3524 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3525 if (NameOrErr)
3526 Name = NameOrErr.get();
3527 else
3528 return NameOrErr.takeError();
3529 }
3530 }
3531
3532 ExpectedType TypeOrErr = import(D->getType());
3533 if (!TypeOrErr)
3534 return TypeOrErr.takeError();
3535
3536 ExpectedExpr InitOrErr = import(D->getInitExpr());
3537 if (!InitOrErr)
3538 return InitOrErr.takeError();
3539
3540 EnumConstantDecl *ToEnumerator;
3541 if (GetImportedOrCreateDecl(
3542 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3543 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3544 return ToEnumerator;
3545
3546 ToEnumerator->setAccess(D->getAccess());
3547 ToEnumerator->setLexicalDeclContext(LexicalDC);
3548 LexicalDC->addDeclInternal(ToEnumerator);
3549 return ToEnumerator;
3550}
3551
3552template <typename DeclTy>
3554 DeclTy *ToD) {
3555 unsigned int Num = FromD->getNumTemplateParameterLists();
3556 if (Num == 0)
3557 return Error::success();
3559 for (unsigned int I = 0; I < Num; ++I)
3560 if (Expected<TemplateParameterList *> ToTPListOrErr =
3561 import(FromD->getTemplateParameterList(I)))
3562 ToTPLists[I] = *ToTPListOrErr;
3563 else
3564 return ToTPListOrErr.takeError();
3565 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3566 return Error::success();
3567}
3568
3570 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3571 switch (FromFD->getTemplatedKind()) {
3574 return Error::success();
3575
3577 if (Expected<FunctionDecl *> InstFDOrErr =
3578 import(FromFD->getInstantiatedFromDecl()))
3579 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3580 return Error::success();
3583
3584 if (Expected<FunctionDecl *> InstFDOrErr =
3585 import(FromFD->getInstantiatedFromMemberFunction()))
3586 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3587 else
3588 return InstFDOrErr.takeError();
3589
3590 if (ExpectedSLoc POIOrErr = import(
3593 else
3594 return POIOrErr.takeError();
3595
3596 return Error::success();
3597 }
3598
3600 auto FunctionAndArgsOrErr =
3602 if (!FunctionAndArgsOrErr)
3603 return FunctionAndArgsOrErr.takeError();
3604
3606 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3607
3608 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3609 TemplateArgumentListInfo ToTAInfo;
3610 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3611 if (FromTAArgsAsWritten)
3612 if (Error Err = ImportTemplateArgumentListInfo(
3613 *FromTAArgsAsWritten, ToTAInfo))
3614 return Err;
3615
3616 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3617 if (!POIOrErr)
3618 return POIOrErr.takeError();
3619
3620 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3621 return Err;
3622
3623 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3624 ToFD->setFunctionTemplateSpecialization(
3625 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3626 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3627 return Error::success();
3628 }
3629
3631 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3632 UnresolvedSet<8> Candidates;
3633 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3634 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3635 Candidates.addDecl(*ToFTDOrErr);
3636 else
3637 return ToFTDOrErr.takeError();
3638 }
3639
3640 // Import TemplateArgumentListInfo.
3641 TemplateArgumentListInfo ToTAInfo;
3642 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3643 if (FromTAArgsAsWritten)
3644 if (Error Err =
3645 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3646 return Err;
3647
3649 Importer.getToContext(), Candidates,
3650 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3651 return Error::success();
3652 }
3653 }
3654 llvm_unreachable("All cases should be covered!");
3655}
3656
3659 auto FunctionAndArgsOrErr =
3661 if (!FunctionAndArgsOrErr)
3662 return FunctionAndArgsOrErr.takeError();
3663
3665 TemplateArgsTy ToTemplArgs;
3666 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3667 void *InsertPos = nullptr;
3668 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3669 return FoundSpec;
3670}
3671
3673 FunctionDecl *ToFD) {
3674 if (Stmt *FromBody = FromFD->getBody()) {
3675 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3676 ToFD->setBody(*ToBodyOrErr);
3677 else
3678 return ToBodyOrErr.takeError();
3679 }
3680 return Error::success();
3681}
3682
3683// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3684// which is equal to the given DC, or D is equal to DC.
3685static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3686 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3687 if (!DCi)
3688 DCi = D->getDeclContext();
3689 assert(DCi && "Declaration should have a context");
3690 while (DCi != D->getTranslationUnitDecl()) {
3691 if (DCi == DC)
3692 return true;
3693 DCi = DCi->getParent();
3694 }
3695 return false;
3696}
3697
3698// Check if there is a declaration that has 'DC' as parent context and is
3699// referenced from statement 'S' or one of its children. The search is done in
3700// BFS order through children of 'S'.
3701static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3702 SmallVector<const Stmt *> ToProcess;
3703 ToProcess.push_back(S);
3704 while (!ToProcess.empty()) {
3705 const Stmt *CurrentS = ToProcess.pop_back_val();
3706 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3707 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3708 if (const Decl *D = DeclRef->getDecl())
3709 if (isAncestorDeclContextOf(DC, D))
3710 return true;
3711 } else if (const auto *E =
3712 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3713 if (const Decl *D = E->getAssociatedDecl())
3714 if (isAncestorDeclContextOf(DC, D))
3715 return true;
3716 }
3717 }
3718 return false;
3719}
3720
3721namespace {
3722/// Check if a type has any reference to a declaration that is inside the body
3723/// of a function.
3724/// The \c CheckType(QualType) function should be used to determine
3725/// this property.
3726///
3727/// The type visitor visits one type object only (not recursive).
3728/// To find all referenced declarations we must discover all type objects until
3729/// the canonical type is reached (walk over typedef and similar objects). This
3730/// is done by loop over all "sugar" type objects. For every such type we must
3731/// check all declarations that are referenced from it. For this check the
3732/// visitor is used. In the visit functions all referenced declarations except
3733/// the one that follows in the sugar chain (if any) must be checked. For this
3734/// check the same visitor is re-used (it has no state-dependent data).
3735///
3736/// The visit functions have 3 possible return values:
3737/// - True, found a declaration inside \c ParentDC.
3738/// - False, found declarations only outside \c ParentDC and it is not possible
3739/// to find more declarations (the "sugar" chain does not continue).
3740/// - Empty optional value, found no declarations or only outside \c ParentDC,
3741/// but it is possible to find more declarations in the type "sugar" chain.
3742/// The loop over the "sugar" types can be implemented by using type visit
3743/// functions only (call \c CheckType with the desugared type). With the current
3744/// solution no visit function is needed if the type has only a desugared type
3745/// as data.
3746class IsTypeDeclaredInsideVisitor
3747 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3748public:
3749 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3750 : ParentDC(ParentDC) {}
3751
3752 bool CheckType(QualType T) {
3753 // Check the chain of "sugar" types.
3754 // The "sugar" types are typedef or similar types that have the same
3755 // canonical type.
3756 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3757 return *Res;
3758 QualType DsT =
3759 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3760 while (DsT != T) {
3761 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3762 return *Res;
3763 T = DsT;
3764 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3765 }
3766 return false;
3767 }
3768
3769 std::optional<bool> VisitTagType(const TagType *T) {
3770 if (auto *Spec =
3771 dyn_cast<ClassTemplateSpecializationDecl>(T->getOriginalDecl()))
3772 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3773 if (checkTemplateArgument(Arg))
3774 return true;
3775 return isAncestorDeclContextOf(ParentDC, T->getOriginalDecl());
3776 }
3777
3778 std::optional<bool> VisitPointerType(const PointerType *T) {
3779 return CheckType(T->getPointeeType());
3780 }
3781
3782 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3783 return CheckType(T->getPointeeTypeAsWritten());
3784 }
3785
3786 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3787 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3788 }
3789
3790 std::optional<bool> VisitUsingType(const UsingType *T) {
3791 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3792 }
3793
3794 std::optional<bool>
3795 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3796 for (const auto &Arg : T->template_arguments())
3797 if (checkTemplateArgument(Arg))
3798 return true;
3799 // This type is a "sugar" to a record type, it can have a desugared type.
3800 return {};
3801 }
3802
3803 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3804 return CheckType(T->getBaseType());
3805 }
3806
3807 std::optional<bool>
3808 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3809 // The "associated declaration" can be the same as ParentDC.
3810 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3811 return true;
3812 return {};
3813 }
3814
3815 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3816 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3817 return true;
3818
3819 return CheckType(T->getElementType());
3820 }
3821
3822 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3823 llvm_unreachable(
3824 "Variable array should not occur in deduced return type of a function");
3825 }
3826
3827 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3828 llvm_unreachable("Incomplete array should not occur in deduced return type "
3829 "of a function");
3830 }
3831
3832 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3833 llvm_unreachable("Dependent array should not occur in deduced return type "
3834 "of a function");
3835 }
3836
3837private:
3838 const DeclContext *const ParentDC;
3839
3840 bool checkTemplateArgument(const TemplateArgument &Arg) {
3841 switch (Arg.getKind()) {
3843 return false;
3845 return CheckType(Arg.getIntegralType());
3847 return CheckType(Arg.getAsType());
3849 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3851 // FIXME: The declaration in this case is not allowed to be in a function?
3852 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3854 // FIXME: The type is not allowed to be in the function?
3855 return CheckType(Arg.getNullPtrType());
3857 return CheckType(Arg.getStructuralValueType());
3859 for (const auto &PackArg : Arg.getPackAsArray())
3860 if (checkTemplateArgument(PackArg))
3861 return true;
3862 return false;
3864 // Templates can not be defined locally in functions.
3865 // A template passed as argument can be not in ParentDC.
3866 return false;
3868 // Templates can not be defined locally in functions.
3869 // A template passed as argument can be not in ParentDC.
3870 return false;
3871 }
3872 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3873 };
3874};
3875} // namespace
3876
3877/// This function checks if the given function has a return type that contains
3878/// a reference (in any way) to a declaration inside the same function.
3880 QualType FromTy = D->getType();
3881 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3882 assert(FromFPT && "Must be called on FunctionProtoType");
3883
3884 auto IsCXX11Lambda = [&]() {
3885 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3886 return false;
3887
3888 return isLambdaMethod(D);
3889 };
3890
3891 QualType RetT = FromFPT->getReturnType();
3892 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3893 FunctionDecl *Def = D->getDefinition();
3894 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3895 return Visitor.CheckType(RetT);
3896 }
3897
3898 return false;
3899}
3900
3902ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3903 Expr *ExplicitExpr = ESpec.getExpr();
3904 if (ExplicitExpr)
3905 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3906 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3907}
3908
3910
3912 auto RedeclIt = Redecls.begin();
3913 // Import the first part of the decl chain. I.e. import all previous
3914 // declarations starting from the canonical decl.
3915 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3916 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3917 if (!ToRedeclOrErr)
3918 return ToRedeclOrErr.takeError();
3919 }
3920 assert(*RedeclIt == D);
3921
3922 // Import the major distinguishing characteristics of this function.
3923 DeclContext *DC, *LexicalDC;
3924 DeclarationName Name;
3926 NamedDecl *ToD;
3927 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3928 return std::move(Err);
3929 if (ToD)
3930 return ToD;
3931
3932 FunctionDecl *FoundByLookup = nullptr;
3933 FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate();
3934
3935 // If this is a function template specialization, then try to find the same
3936 // existing specialization in the "to" context. The lookup below will not
3937 // find any specialization, but would find the primary template; thus, we
3938 // have to skip normal lookup in case of specializations.
3939 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3940 if (D->getTemplatedKind() ==
3942 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3943 if (!FoundFunctionOrErr)
3944 return FoundFunctionOrErr.takeError();
3945 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3946 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3947 return Def;
3948 FoundByLookup = FoundFunction;
3949 }
3950 }
3951 // Try to find a function in our own ("to") context with the same name, same
3952 // type, and in the same context as the function we're importing.
3953 else if (!LexicalDC->isFunctionOrMethod()) {
3954 SmallVector<NamedDecl *, 4> ConflictingDecls;
3956 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3957 for (auto *FoundDecl : FoundDecls) {
3958 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3959 continue;
3960
3961 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3962 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3963 continue;
3964
3965 if (IsStructuralMatch(D, FoundFunction)) {
3966 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3967 return Def;
3968 FoundByLookup = FoundFunction;
3969 break;
3970 }
3971 // FIXME: Check for overloading more carefully, e.g., by boosting
3972 // Sema::IsOverload out to the AST library.
3973
3974 // Function overloading is okay in C++.
3975 if (Importer.getToContext().getLangOpts().CPlusPlus)
3976 continue;
3977
3978 // Complain about inconsistent function types.
3979 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3980 << Name << D->getType() << FoundFunction->getType();
3981 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3982 << FoundFunction->getType();
3983 ConflictingDecls.push_back(FoundDecl);
3984 }
3985 }
3986
3987 if (!ConflictingDecls.empty()) {
3988 ExpectedName NameOrErr = Importer.HandleNameConflict(
3989 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3990 if (NameOrErr)
3991 Name = NameOrErr.get();
3992 else
3993 return NameOrErr.takeError();
3994 }
3995 }
3996
3997 // We do not allow more than one in-class declaration of a function. This is
3998 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3999 // assumes there is only one in-class declaration. Building a redecl
4000 // chain would result in more than one in-class declaration for
4001 // overrides (even if they are part of the same redecl chain inside the
4002 // derived class.)
4003 if (FoundByLookup) {
4004 if (isa<CXXMethodDecl>(FoundByLookup)) {
4005 if (D->getLexicalDeclContext() == D->getDeclContext()) {
4006 if (!D->doesThisDeclarationHaveABody()) {
4007 if (FunctionTemplateDecl *DescribedD =
4008 D->getDescribedFunctionTemplate()) {
4009 // Handle a "templated" function together with its described
4010 // template. This avoids need for a similar check at import of the
4011 // described template.
4012 assert(FoundByLookup->getDescribedFunctionTemplate() &&
4013 "Templated function mapped to non-templated?");
4014 Importer.MapImported(DescribedD,
4015 FoundByLookup->getDescribedFunctionTemplate());
4016 }
4017 return Importer.MapImported(D, FoundByLookup);
4018 } else {
4019 // Let's continue and build up the redecl chain in this case.
4020 // FIXME Merge the functions into one decl.
4021 }
4022 }
4023 }
4024 }
4025
4026 DeclarationNameInfo NameInfo(Name, Loc);
4027 // Import additional name location/type info.
4028 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
4029 return std::move(Err);
4030
4031 QualType FromTy = D->getType();
4032 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
4033 // Set to true if we do not import the type of the function as is. There are
4034 // cases when the original type would result in an infinite recursion during
4035 // the import. To avoid an infinite recursion when importing, we create the
4036 // FunctionDecl with a simplified function type and update it only after the
4037 // relevant AST nodes are already imported.
4038 // The type is related to TypeSourceInfo (it references the type), so we must
4039 // do the same with TypeSourceInfo.
4040 bool UsedDifferentProtoType = false;
4041 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
4042 QualType FromReturnTy = FromFPT->getReturnType();
4043 // Functions with auto return type may define a struct inside their body
4044 // and the return type could refer to that struct.
4045 // E.g.: auto foo() { struct X{}; return X(); }
4046 // To avoid an infinite recursion when importing, create the FunctionDecl
4047 // with a simplified return type.
4049 FromReturnTy = Importer.getFromContext().VoidTy;
4050 UsedDifferentProtoType = true;
4051 }
4052 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
4053 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
4054 // FunctionDecl that we are importing the FunctionProtoType for.
4055 // To avoid an infinite recursion when importing, create the FunctionDecl
4056 // with a simplified function type.
4057 if (FromEPI.ExceptionSpec.SourceDecl ||
4058 FromEPI.ExceptionSpec.SourceTemplate ||
4059 FromEPI.ExceptionSpec.NoexceptExpr) {
4061 FromEPI = DefaultEPI;
4062 UsedDifferentProtoType = true;
4063 }
4064 FromTy = Importer.getFromContext().getFunctionType(
4065 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
4066 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
4067 FromTy, D->getBeginLoc());
4068 }
4069
4070 Error Err = Error::success();
4071 auto T = importChecked(Err, FromTy);
4072 auto TInfo = importChecked(Err, FromTSI);
4073 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4074 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4075 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
4076 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4077 AssociatedConstraint TrailingRequiresClause = D->getTrailingRequiresClause();
4078 TrailingRequiresClause.ConstraintExpr =
4079 importChecked(Err, TrailingRequiresClause.ConstraintExpr);
4080 if (Err)
4081 return std::move(Err);
4082
4083 // Import the function parameters.
4085 for (auto *P : D->parameters()) {
4086 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
4087 Parameters.push_back(*ToPOrErr);
4088 else
4089 return ToPOrErr.takeError();
4090 }
4091
4092 // Create the imported function.
4093 FunctionDecl *ToFunction = nullptr;
4094 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4095 ExplicitSpecifier ESpec =
4096 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
4097 if (Err)
4098 return std::move(Err);
4099 auto ToInheritedConstructor = InheritedConstructor();
4100 if (FromConstructor->isInheritingConstructor()) {
4101 Expected<InheritedConstructor> ImportedInheritedCtor =
4102 import(FromConstructor->getInheritedConstructor());
4103 if (!ImportedInheritedCtor)
4104 return ImportedInheritedCtor.takeError();
4105 ToInheritedConstructor = *ImportedInheritedCtor;
4106 }
4107 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
4108 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4109 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
4110 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
4111 ToInheritedConstructor, TrailingRequiresClause))
4112 return ToFunction;
4113 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
4114
4115 Error Err = Error::success();
4116 auto ToOperatorDelete = importChecked(
4117 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
4118 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
4119 if (Err)
4120 return std::move(Err);
4121
4122 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
4123 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4124 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4125 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
4126 TrailingRequiresClause))
4127 return ToFunction;
4128
4129 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
4130
4131 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
4132 } else if (CXXConversionDecl *FromConversion =
4133 dyn_cast<CXXConversionDecl>(D)) {
4134 ExplicitSpecifier ESpec =
4135 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
4136 if (Err)
4137 return std::move(Err);
4138 if (GetImportedOrCreateDecl<CXXConversionDecl>(
4139 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4140 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
4141 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
4142 SourceLocation(), TrailingRequiresClause))
4143 return ToFunction;
4144 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
4145 if (GetImportedOrCreateDecl<CXXMethodDecl>(
4146 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
4147 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
4148 Method->UsesFPIntrin(), Method->isInlineSpecified(),
4149 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
4150 return ToFunction;
4151 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
4152 ExplicitSpecifier ESpec =
4153 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4154 CXXConstructorDecl *Ctor =
4155 importChecked(Err, Guide->getCorrespondingConstructor());
4156 const CXXDeductionGuideDecl *SourceDG =
4157 importChecked(Err, Guide->getSourceDeductionGuide());
4158 if (Err)
4159 return std::move(Err);
4160 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4161 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4162 NameInfo, T, TInfo, ToEndLoc, Ctor,
4163 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4164 SourceDG, Guide->getSourceDeductionGuideKind()))
4165 return ToFunction;
4166 } else {
4167 if (GetImportedOrCreateDecl(
4168 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4169 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4170 D->isInlineSpecified(), D->hasWrittenPrototype(),
4171 D->getConstexprKind(), TrailingRequiresClause))
4172 return ToFunction;
4173 }
4174
4175 // Connect the redecl chain.
4176 if (FoundByLookup) {
4177 auto *Recent = const_cast<FunctionDecl *>(
4178 FoundByLookup->getMostRecentDecl());
4179 ToFunction->setPreviousDecl(Recent);
4180 // FIXME Probably we should merge exception specifications. E.g. In the
4181 // "To" context the existing function may have exception specification with
4182 // noexcept-unevaluated, while the newly imported function may have an
4183 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4184 // decl and its redeclarations may be required.
4185 }
4186
4187 StringLiteral *Msg = D->getDeletedMessage();
4188 if (Msg) {
4189 auto Imported = import(Msg);
4190 if (!Imported)
4191 return Imported.takeError();
4192 Msg = *Imported;
4193 }
4194
4195 ToFunction->setQualifierInfo(ToQualifierLoc);
4196 ToFunction->setAccess(D->getAccess());
4197 ToFunction->setLexicalDeclContext(LexicalDC);
4198 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4199 ToFunction->setTrivial(D->isTrivial());
4200 ToFunction->setIsPureVirtual(D->isPureVirtual());
4201 ToFunction->setDefaulted(D->isDefaulted());
4202 ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted());
4203 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4205 D->FriendConstraintRefersToEnclosingTemplate());
4206 ToFunction->setIsDestroyingOperatorDelete(D->isDestroyingOperatorDelete());
4208 D->isTypeAwareOperatorNewOrDelete());
4209 ToFunction->setRangeEnd(ToEndLoc);
4210 ToFunction->setDefaultLoc(ToDefaultLoc);
4211
4212 if (Msg)
4213 ToFunction->setDefaultedOrDeletedInfo(
4215 Importer.getToContext(), {}, Msg));
4216
4217 // Set the parameters.
4218 for (auto *Param : Parameters) {
4219 Param->setOwningFunction(ToFunction);
4220 ToFunction->addDeclInternal(Param);
4221 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4222 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4223 }
4224 ToFunction->setParams(Parameters);
4225
4226 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4227 // params it refers to.
4228 if (TInfo) {
4229 if (auto ProtoLoc =
4230 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4231 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4232 ProtoLoc.setParam(I, Parameters[I]);
4233 }
4234 }
4235
4236 // Import the describing template function, if any.
4237 if (FromFT) {
4238 auto ToFTOrErr = import(FromFT);
4239 if (!ToFTOrErr)
4240 return ToFTOrErr.takeError();
4241 }
4242
4243 // Import Ctor initializers.
4244 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4245 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4246 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4247 // Import first, then allocate memory and copy if there was no error.
4248 if (Error Err = ImportContainerChecked(
4249 FromConstructor->inits(), CtorInitializers))
4250 return std::move(Err);
4251 auto **Memory =
4252 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4253 llvm::copy(CtorInitializers, Memory);
4254 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4255 ToCtor->setCtorInitializers(Memory);
4256 ToCtor->setNumCtorInitializers(NumInitializers);
4257 }
4258 }
4259
4260 // If it is a template, import all related things.
4261 if (Error Err = ImportTemplateInformation(D, ToFunction))
4262 return std::move(Err);
4263
4264 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4265 if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
4266 FromCXXMethod))
4267 return std::move(Err);
4268
4269 if (D->doesThisDeclarationHaveABody()) {
4270 Error Err = ImportFunctionDeclBody(D, ToFunction);
4271
4272 if (Err)
4273 return std::move(Err);
4274 }
4275
4276 // Import and set the original type in case we used another type.
4277 if (UsedDifferentProtoType) {
4278 if (ExpectedType TyOrErr = import(D->getType()))
4279 ToFunction->setType(*TyOrErr);
4280 else
4281 return TyOrErr.takeError();
4282 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4283 ToFunction->setTypeSourceInfo(*TSIOrErr);
4284 else
4285 return TSIOrErr.takeError();
4286 }
4287
4288 // FIXME: Other bits to merge?
4289
4290 addDeclToContexts(D, ToFunction);
4291
4292 // Import the rest of the chain. I.e. import all subsequent declarations.
4293 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4294 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4295 if (!ToRedeclOrErr)
4296 return ToRedeclOrErr.takeError();
4297 }
4298
4299 return ToFunction;
4300}
4301
4303 return VisitFunctionDecl(D);
4304}
4305
4307 return VisitCXXMethodDecl(D);
4308}
4309
4311 return VisitCXXMethodDecl(D);
4312}
4313
4315 return VisitCXXMethodDecl(D);
4316}
4317
4320 return VisitFunctionDecl(D);
4321}
4322
4324 // Import the major distinguishing characteristics of a variable.
4325 DeclContext *DC, *LexicalDC;
4326 DeclarationName Name;
4328 NamedDecl *ToD;
4329 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4330 return std::move(Err);
4331 if (ToD)
4332 return ToD;
4333
4334 // Determine whether we've already imported this field.
4335 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4336 for (auto *FoundDecl : FoundDecls) {
4337 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4338 // For anonymous fields, match up by index.
4339 if (!Name &&
4341 ASTImporter::getFieldIndex(FoundField))
4342 continue;
4343
4344 if (Importer.IsStructurallyEquivalent(D->getType(),
4345 FoundField->getType())) {
4346 Importer.MapImported(D, FoundField);
4347 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4348 // initializer of a FieldDecl might not had been instantiated in the
4349 // "To" context. However, the "From" context might instantiated that,
4350 // thus we have to merge that.
4351 // Note: `hasInClassInitializer()` is not the same as non-null
4352 // `getInClassInitializer()` value.
4353 if (Expr *FromInitializer = D->getInClassInitializer()) {
4354 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4355 // Import of the FromInitializer may result in the setting of
4356 // InClassInitializer. If not, set it here.
4357 assert(FoundField->hasInClassInitializer() &&
4358 "Field should have an in-class initializer if it has an "
4359 "expression for it.");
4360 if (!FoundField->getInClassInitializer())
4361 FoundField->setInClassInitializer(*ToInitializerOrErr);
4362 } else {
4363 return ToInitializerOrErr.takeError();
4364 }
4365 }
4366 return FoundField;
4367 }
4368
4369 // FIXME: Why is this case not handled with calling HandleNameConflict?
4370 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4371 << Name << D->getType() << FoundField->getType();
4372 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4373 << FoundField->getType();
4374
4375 return make_error<ASTImportError>(ASTImportError::NameConflict);
4376 }
4377 }
4378
4379 Error Err = Error::success();
4380 auto ToType = importChecked(Err, D->getType());
4381 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4382 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4383 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4384 if (Err)
4385 return std::move(Err);
4386 const Type *ToCapturedVLAType = nullptr;
4387 if (Error Err = Importer.importInto(
4388 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4389 return std::move(Err);
4390
4391 FieldDecl *ToField;
4392 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4393 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4394 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4395 D->getInClassInitStyle()))
4396 return ToField;
4397
4398 ToField->setAccess(D->getAccess());
4399 ToField->setLexicalDeclContext(LexicalDC);
4400 ToField->setImplicit(D->isImplicit());
4401 if (ToCapturedVLAType)
4402 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4403 LexicalDC->addDeclInternal(ToField);
4404 // Import initializer only after the field was created, it may have recursive
4405 // reference to the field.
4406 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4407 if (Err)
4408 return std::move(Err);
4409 if (ToInitializer) {
4410 auto *AlreadyImported = ToField->getInClassInitializer();
4411 if (AlreadyImported)
4412 assert(ToInitializer == AlreadyImported &&
4413 "Duplicate import of in-class initializer.");
4414 else
4415 ToField->setInClassInitializer(ToInitializer);
4416 }
4417
4418 return ToField;
4419}
4420
4422 // Import the major distinguishing characteristics of a variable.
4423 DeclContext *DC, *LexicalDC;
4424 DeclarationName Name;
4426 NamedDecl *ToD;
4427 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4428 return std::move(Err);
4429 if (ToD)
4430 return ToD;
4431
4432 // Determine whether we've already imported this field.
4433 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4434 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4435 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4436 // For anonymous indirect fields, match up by index.
4437 if (!Name &&
4439 ASTImporter::getFieldIndex(FoundField))
4440 continue;
4441
4442 if (Importer.IsStructurallyEquivalent(D->getType(),
4443 FoundField->getType(),
4444 !Name.isEmpty())) {
4445 Importer.MapImported(D, FoundField);
4446 return FoundField;
4447 }
4448
4449 // If there are more anonymous fields to check, continue.
4450 if (!Name && I < N-1)
4451 continue;
4452
4453 // FIXME: Why is this case not handled with calling HandleNameConflict?
4454 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4455 << Name << D->getType() << FoundField->getType();
4456 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4457 << FoundField->getType();
4458
4459 return make_error<ASTImportError>(ASTImportError::NameConflict);
4460 }
4461 }
4462
4463 // Import the type.
4464 auto TypeOrErr = import(D->getType());
4465 if (!TypeOrErr)
4466 return TypeOrErr.takeError();
4467
4468 auto **NamedChain =
4469 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4470
4471 unsigned i = 0;
4472 for (auto *PI : D->chain())
4473 if (Expected<NamedDecl *> ToD = import(PI))
4474 NamedChain[i++] = *ToD;
4475 else
4476 return ToD.takeError();
4477
4478 MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4479 IndirectFieldDecl *ToIndirectField;
4480 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4481 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4482 // FIXME here we leak `NamedChain` which is allocated before
4483 return ToIndirectField;
4484
4485 ToIndirectField->setAccess(D->getAccess());
4486 ToIndirectField->setLexicalDeclContext(LexicalDC);
4487 LexicalDC->addDeclInternal(ToIndirectField);
4488 return ToIndirectField;
4489}
4490
4491/// Used as return type of getFriendCountAndPosition.
4493 /// Number of similar looking friends.
4494 unsigned int TotalCount;
4495 /// Index of the specific FriendDecl.
4496 unsigned int IndexOfDecl;
4497};
4498
4499static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4500 FriendDecl *FD2) {
4501 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4502 return false;
4503
4504 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4505 return Importer.IsStructurallyEquivalent(
4506 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4507
4508 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4510 Importer.getToContext().getLangOpts(), FD1->getASTContext(),
4511 FD2->getASTContext(), NonEquivalentDecls,
4513 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4514 return Ctx.IsEquivalent(FD1, FD2);
4515}
4516
4518 FriendDecl *FD) {
4519 unsigned int FriendCount = 0;
4520 UnsignedOrNone FriendPosition = std::nullopt;
4521 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4522
4523 for (FriendDecl *FoundFriend : RD->friends()) {
4524 if (FoundFriend == FD) {
4525 FriendPosition = FriendCount;
4526 ++FriendCount;
4527 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4528 ++FriendCount;
4529 }
4530 }
4531
4532 assert(FriendPosition && "Friend decl not found in own parent.");
4533
4534 return {FriendCount, *FriendPosition};
4535}
4536
4538 // Import the major distinguishing characteristics of a declaration.
4539 DeclContext *DC, *LexicalDC;
4540 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4541 return std::move(Err);
4542
4543 // Determine whether we've already imported this decl.
4544 // FriendDecl is not a NamedDecl so we cannot use lookup.
4545 // We try to maintain order and count of redundant friend declarations.
4546 const auto *RD = cast<CXXRecordDecl>(DC);
4547 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4548 for (FriendDecl *ImportedFriend : RD->friends())
4549 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4550 ImportedEquivalentFriends.push_back(ImportedFriend);
4551
4552 FriendCountAndPosition CountAndPosition =
4553 getFriendCountAndPosition(Importer, D);
4554
4555 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4556 "Class with non-matching friends is imported, ODR check wrong?");
4557 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4558 return Importer.MapImported(
4559 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4560
4561 // Not found. Create it.
4562 // The declarations will be put into order later by ImportDeclContext.
4564 if (NamedDecl *FriendD = D->getFriendDecl()) {
4565 NamedDecl *ToFriendD;
4566 if (Error Err = importInto(ToFriendD, FriendD))
4567 return std::move(Err);
4568
4569 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4570 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4571 ToFriendD->setObjectOfFriendDecl(false);
4572
4573 ToFU = ToFriendD;
4574 } else { // The friend is a type, not a decl.
4575 if (auto TSIOrErr = import(D->getFriendType()))
4576 ToFU = *TSIOrErr;
4577 else
4578 return TSIOrErr.takeError();
4579 }
4580
4581 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4582 auto **FromTPLists = D->getTrailingObjects();
4583 for (unsigned I = 0; I < D->NumTPLists; I++) {
4584 if (auto ListOrErr = import(FromTPLists[I]))
4585 ToTPLists[I] = *ListOrErr;
4586 else
4587 return ListOrErr.takeError();
4588 }
4589
4590 auto LocationOrErr = import(D->getLocation());
4591 if (!LocationOrErr)
4592 return LocationOrErr.takeError();
4593 auto FriendLocOrErr = import(D->getFriendLoc());
4594 if (!FriendLocOrErr)
4595 return FriendLocOrErr.takeError();
4596 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4597 if (!EllipsisLocOrErr)
4598 return EllipsisLocOrErr.takeError();
4599
4600 FriendDecl *FrD;
4601 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4602 *LocationOrErr, ToFU, *FriendLocOrErr,
4603 *EllipsisLocOrErr, ToTPLists))
4604 return FrD;
4605
4606 FrD->setAccess(D->getAccess());
4607 FrD->setLexicalDeclContext(LexicalDC);
4608 LexicalDC->addDeclInternal(FrD);
4609 return FrD;
4610}
4611
4613 // Import the major distinguishing characteristics of an ivar.
4614 DeclContext *DC, *LexicalDC;
4615 DeclarationName Name;
4617 NamedDecl *ToD;
4618 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4619 return std::move(Err);
4620 if (ToD)
4621 return ToD;
4622
4623 // Determine whether we've already imported this ivar
4624 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4625 for (auto *FoundDecl : FoundDecls) {
4626 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4627 if (Importer.IsStructurallyEquivalent(D->getType(),
4628 FoundIvar->getType())) {
4629 Importer.MapImported(D, FoundIvar);
4630 return FoundIvar;
4631 }
4632
4633 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4634 << Name << D->getType() << FoundIvar->getType();
4635 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4636 << FoundIvar->getType();
4637
4638 return make_error<ASTImportError>(ASTImportError::NameConflict);
4639 }
4640 }
4641
4642 Error Err = Error::success();
4643 auto ToType = importChecked(Err, D->getType());
4644 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4645 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4646 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4647 if (Err)
4648 return std::move(Err);
4649
4650 ObjCIvarDecl *ToIvar;
4651 if (GetImportedOrCreateDecl(
4652 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4653 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4654 ToType, ToTypeSourceInfo,
4655 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4656 return ToIvar;
4657
4658 ToIvar->setLexicalDeclContext(LexicalDC);
4659 LexicalDC->addDeclInternal(ToIvar);
4660 return ToIvar;
4661}
4662
4664
4666 auto RedeclIt = Redecls.begin();
4667 // Import the first part of the decl chain. I.e. import all previous
4668 // declarations starting from the canonical decl.
4669 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4670 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4671 if (!RedeclOrErr)
4672 return RedeclOrErr.takeError();
4673 }
4674 assert(*RedeclIt == D);
4675
4676 // Import the major distinguishing characteristics of a variable.
4677 DeclContext *DC, *LexicalDC;
4678 DeclarationName Name;
4680 NamedDecl *ToD;
4681 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4682 return std::move(Err);
4683 if (ToD)
4684 return ToD;
4685
4686 // Try to find a variable in our own ("to") context with the same name and
4687 // in the same context as the variable we're importing.
4688 VarDecl *FoundByLookup = nullptr;
4689 if (D->isFileVarDecl()) {
4690 SmallVector<NamedDecl *, 4> ConflictingDecls;
4691 unsigned IDNS = Decl::IDNS_Ordinary;
4692 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4693 for (auto *FoundDecl : FoundDecls) {
4694 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4695 continue;
4696
4697 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4698 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4699 continue;
4700 if (Importer.IsStructurallyEquivalent(D->getType(),
4701 FoundVar->getType())) {
4702
4703 // The VarDecl in the "From" context has a definition, but in the
4704 // "To" context we already have a definition.
4705 VarDecl *FoundDef = FoundVar->getDefinition();
4706 if (D->isThisDeclarationADefinition() && FoundDef)
4707 // FIXME Check for ODR error if the two definitions have
4708 // different initializers?
4709 return Importer.MapImported(D, FoundDef);
4710
4711 // The VarDecl in the "From" context has an initializer, but in the
4712 // "To" context we already have an initializer.
4713 const VarDecl *FoundDInit = nullptr;
4714 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4715 // FIXME Diagnose ODR error if the two initializers are different?
4716 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4717
4718 FoundByLookup = FoundVar;
4719 break;
4720 }
4721
4722 const ArrayType *FoundArray
4723 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4724 const ArrayType *TArray
4725 = Importer.getToContext().getAsArrayType(D->getType());
4726 if (FoundArray && TArray) {
4727 if (isa<IncompleteArrayType>(FoundArray) &&
4728 isa<ConstantArrayType>(TArray)) {
4729 // Import the type.
4730 if (auto TyOrErr = import(D->getType()))
4731 FoundVar->setType(*TyOrErr);
4732 else
4733 return TyOrErr.takeError();
4734
4735 FoundByLookup = FoundVar;
4736 break;
4737 } else if (isa<IncompleteArrayType>(TArray) &&
4738 isa<ConstantArrayType>(FoundArray)) {
4739 FoundByLookup = FoundVar;
4740 break;
4741 }
4742 }
4743
4744 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4745 << Name << D->getType() << FoundVar->getType();
4746 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4747 << FoundVar->getType();
4748 ConflictingDecls.push_back(FoundDecl);
4749 }
4750 }
4751
4752 if (!ConflictingDecls.empty()) {
4753 ExpectedName NameOrErr = Importer.HandleNameConflict(
4754 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4755 if (NameOrErr)
4756 Name = NameOrErr.get();
4757 else
4758 return NameOrErr.takeError();
4759 }
4760 }
4761
4762 Error Err = Error::success();
4763 auto ToType = importChecked(Err, D->getType());
4764 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4765 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4766 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4767 if (Err)
4768 return std::move(Err);
4769
4770 VarDecl *ToVar;
4771 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4772 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4773 if (Error Err =
4774 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4775 return std::move(Err);
4776 DecompositionDecl *ToDecomp;
4777 if (GetImportedOrCreateDecl(
4778 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4779 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4780 return ToDecomp;
4781 ToVar = ToDecomp;
4782 } else {
4783 // Create the imported variable.
4784 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4785 ToInnerLocStart, Loc,
4786 Name.getAsIdentifierInfo(), ToType,
4787 ToTypeSourceInfo, D->getStorageClass()))
4788 return ToVar;
4789 }
4790
4791 ToVar->setTSCSpec(D->getTSCSpec());
4792 ToVar->setQualifierInfo(ToQualifierLoc);
4793 ToVar->setAccess(D->getAccess());
4794 ToVar->setLexicalDeclContext(LexicalDC);
4795 if (D->isInlineSpecified())
4796 ToVar->setInlineSpecified();
4797 if (D->isInline())
4798 ToVar->setImplicitlyInline();
4799
4800 if (FoundByLookup) {
4801 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4802 ToVar->setPreviousDecl(Recent);
4803 }
4804
4805 // Import the described template, if any.
4806 if (D->getDescribedVarTemplate()) {
4807 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4808 if (!ToVTOrErr)
4809 return ToVTOrErr.takeError();
4810 } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) {
4811 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4812 VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
4813 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4814 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4815 else
4816 return ToInstOrErr.takeError();
4817 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4819 else
4820 return POIOrErr.takeError();
4821 }
4822
4823 if (Error Err = ImportInitializer(D, ToVar))
4824 return std::move(Err);
4825
4826 if (D->isConstexpr())
4827 ToVar->setConstexpr(true);
4828
4829 addDeclToContexts(D, ToVar);
4830
4831 // Import the rest of the chain. I.e. import all subsequent declarations.
4832 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4833 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4834 if (!RedeclOrErr)
4835 return RedeclOrErr.takeError();
4836 }
4837
4838 return ToVar;
4839}
4840
4842 // Parameters are created in the translation unit's context, then moved
4843 // into the function declaration's context afterward.
4845
4846 Error Err = Error::success();
4847 auto ToDeclName = importChecked(Err, D->getDeclName());
4848 auto ToLocation = importChecked(Err, D->getLocation());
4849 auto ToType = importChecked(Err, D->getType());
4850 if (Err)
4851 return std::move(Err);
4852
4853 // Create the imported parameter.
4854 ImplicitParamDecl *ToParm = nullptr;
4855 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4856 ToLocation, ToDeclName.getAsIdentifierInfo(),
4857 ToType, D->getParameterKind()))
4858 return ToParm;
4859 return ToParm;
4860}
4861
4863 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4864
4865 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4866 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4867 else
4868 return LocOrErr.takeError();
4869
4871 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4872
4873 if (FromParam->hasUninstantiatedDefaultArg()) {
4874 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4875 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4876 else
4877 return ToDefArgOrErr.takeError();
4878 } else if (FromParam->hasUnparsedDefaultArg()) {
4879 ToParam->setUnparsedDefaultArg();
4880 } else if (FromParam->hasDefaultArg()) {
4881 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4882 ToParam->setDefaultArg(*ToDefArgOrErr);
4883 else
4884 return ToDefArgOrErr.takeError();
4885 }
4886
4887 return Error::success();
4888}
4889
4892 Error Err = Error::success();
4893 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4894 ConstructorUsingShadowDecl *ToShadow =
4895 importChecked(Err, From.getShadowDecl());
4896 if (Err)
4897 return std::move(Err);
4898 return InheritedConstructor(ToShadow, ToBaseCtor);
4899}
4900
4902 // Parameters are created in the translation unit's context, then moved
4903 // into the function declaration's context afterward.
4905
4906 Error Err = Error::success();
4907 auto ToDeclName = importChecked(Err, D->getDeclName());
4908 auto ToLocation = importChecked(Err, D->getLocation());
4909 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4910 auto ToType = importChecked(Err, D->getType());
4911 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4912 if (Err)
4913 return std::move(Err);
4914
4915 ParmVarDecl *ToParm;
4916 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4917 ToInnerLocStart, ToLocation,
4918 ToDeclName.getAsIdentifierInfo(), ToType,
4919 ToTypeSourceInfo, D->getStorageClass(),
4920 /*DefaultArg*/ nullptr))
4921 return ToParm;
4922
4923 // Set the default argument. It should be no problem if it was already done.
4924 // Do not import the default expression before GetImportedOrCreateDecl call
4925 // to avoid possible infinite import loop because circular dependency.
4926 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4927 return std::move(Err);
4928
4929 if (D->isObjCMethodParameter()) {
4930 ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex());
4931 ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier());
4932 } else {
4933 ToParm->setScopeInfo(D->getFunctionScopeDepth(),
4934 D->getFunctionScopeIndex());
4935 }
4936
4937 return ToParm;
4938}
4939
4941 // Import the major distinguishing characteristics of a method.
4942 DeclContext *DC, *LexicalDC;
4943 DeclarationName Name;
4945 NamedDecl *ToD;
4946 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4947 return std::move(Err);
4948 if (ToD)
4949 return ToD;
4950
4951 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4952 for (auto *FoundDecl : FoundDecls) {
4953 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4954 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4955 continue;
4956
4957 // Check return types.
4958 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4959 FoundMethod->getReturnType())) {
4960 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4961 << D->isInstanceMethod() << Name << D->getReturnType()
4962 << FoundMethod->getReturnType();
4963 Importer.ToDiag(FoundMethod->getLocation(),
4964 diag::note_odr_objc_method_here)
4965 << D->isInstanceMethod() << Name;
4966
4967 return make_error<ASTImportError>(ASTImportError::NameConflict);
4968 }
4969
4970 // Check the number of parameters.
4971 if (D->param_size() != FoundMethod->param_size()) {
4972 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4973 << D->isInstanceMethod() << Name
4974 << D->param_size() << FoundMethod->param_size();
4975 Importer.ToDiag(FoundMethod->getLocation(),
4976 diag::note_odr_objc_method_here)
4977 << D->isInstanceMethod() << Name;
4978
4979 return make_error<ASTImportError>(ASTImportError::NameConflict);
4980 }
4981
4982 // Check parameter types.
4983 for (ObjCMethodDecl::param_iterator P = D->param_begin(),
4984 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4985 P != PEnd; ++P, ++FoundP) {
4986 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4987 (*FoundP)->getType())) {
4988 Importer.FromDiag((*P)->getLocation(),
4989 diag::warn_odr_objc_method_param_type_inconsistent)
4990 << D->isInstanceMethod() << Name
4991 << (*P)->getType() << (*FoundP)->getType();
4992 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4993 << (*FoundP)->getType();
4994
4995 return make_error<ASTImportError>(ASTImportError::NameConflict);
4996 }
4997 }
4998
4999 // Check variadic/non-variadic.
5000 // Check the number of parameters.
5001 if (D->isVariadic() != FoundMethod->isVariadic()) {
5002 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
5003 << D->isInstanceMethod() << Name;
5004 Importer.ToDiag(FoundMethod->getLocation(),
5005 diag::note_odr_objc_method_here)
5006 << D->isInstanceMethod() << Name;
5007
5008 return make_error<ASTImportError>(ASTImportError::NameConflict);
5009 }
5010
5011 // FIXME: Any other bits we need to merge?
5012 return Importer.MapImported(D, FoundMethod);
5013 }
5014 }
5015
5016 Error Err = Error::success();
5017 auto ToEndLoc = importChecked(Err, D->getEndLoc());
5018 auto ToReturnType = importChecked(Err, D->getReturnType());
5019 auto ToReturnTypeSourceInfo =
5020 importChecked(Err, D->getReturnTypeSourceInfo());
5021 if (Err)
5022 return std::move(Err);
5023
5024 ObjCMethodDecl *ToMethod;
5025 if (GetImportedOrCreateDecl(
5026 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
5027 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
5028 D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(),
5029 D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(),
5030 D->getImplementationControl(), D->hasRelatedResultType()))
5031 return ToMethod;
5032
5033 // FIXME: When we decide to merge method definitions, we'll need to
5034 // deal with implicit parameters.
5035
5036 // Import the parameters
5038 for (auto *FromP : D->parameters()) {
5039 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
5040 ToParams.push_back(*ToPOrErr);
5041 else
5042 return ToPOrErr.takeError();
5043 }
5044
5045 // Set the parameters.
5046 for (auto *ToParam : ToParams) {
5047 ToParam->setOwningFunction(ToMethod);
5048 ToMethod->addDeclInternal(ToParam);
5049 }
5050
5052 D->getSelectorLocs(FromSelLocs);
5053 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
5054 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
5055 return std::move(Err);
5056
5057 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
5058
5059 ToMethod->setLexicalDeclContext(LexicalDC);
5060 LexicalDC->addDeclInternal(ToMethod);
5061
5062 // Implicit params are declared when Sema encounters the definition but this
5063 // never happens when the method is imported. Manually declare the implicit
5064 // params now that the MethodDecl knows its class interface.
5065 if (D->getSelfDecl())
5066 ToMethod->createImplicitParams(Importer.getToContext(),
5067 ToMethod->getClassInterface());
5068
5069 return ToMethod;
5070}
5071
5073 // Import the major distinguishing characteristics of a category.
5074 DeclContext *DC, *LexicalDC;
5075 DeclarationName Name;
5077 NamedDecl *ToD;
5078 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5079 return std::move(Err);
5080 if (ToD)
5081 return ToD;
5082
5083 Error Err = Error::success();
5084 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
5085 auto ToLocation = importChecked(Err, D->getLocation());
5086 auto ToColonLoc = importChecked(Err, D->getColonLoc());
5087 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5088 if (Err)
5089 return std::move(Err);
5090
5092 if (GetImportedOrCreateDecl(
5093 Result, D, Importer.getToContext(), DC, D->getVariance(),
5094 ToVarianceLoc, D->getIndex(),
5095 ToLocation, Name.getAsIdentifierInfo(),
5096 ToColonLoc, ToTypeSourceInfo))
5097 return Result;
5098
5099 // Only import 'ObjCTypeParamType' after the decl is created.
5100 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
5101 if (Err)
5102 return std::move(Err);
5103 Result->setTypeForDecl(ToTypeForDecl);
5104 Result->setLexicalDeclContext(LexicalDC);
5105 return Result;
5106}
5107
5109 // Import the major distinguishing characteristics of a category.
5110 DeclContext *DC, *LexicalDC;
5111 DeclarationName Name;
5113 NamedDecl *ToD;
5114 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5115 return std::move(Err);
5116 if (ToD)
5117 return ToD;
5118
5119 ObjCInterfaceDecl *ToInterface;
5120 if (Error Err = importInto(ToInterface, D->getClassInterface()))
5121 return std::move(Err);
5122
5123 // Determine if we've already encountered this category.
5124 ObjCCategoryDecl *MergeWithCategory
5125 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
5126 ObjCCategoryDecl *ToCategory = MergeWithCategory;
5127 if (!ToCategory) {
5128
5129 Error Err = Error::success();
5130 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5131 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5132 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5133 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5134 if (Err)
5135 return std::move(Err);
5136
5137 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
5138 ToAtStartLoc, Loc,
5139 ToCategoryNameLoc,
5140 Name.getAsIdentifierInfo(), ToInterface,
5141 /*TypeParamList=*/nullptr,
5142 ToIvarLBraceLoc,
5143 ToIvarRBraceLoc))
5144 return ToCategory;
5145
5146 ToCategory->setLexicalDeclContext(LexicalDC);
5147 LexicalDC->addDeclInternal(ToCategory);
5148 // Import the type parameter list after MapImported, to avoid
5149 // loops when bringing in their DeclContext.
5150 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
5151 ToCategory->setTypeParamList(*PListOrErr);
5152 else
5153 return PListOrErr.takeError();
5154
5155 // Import protocols
5157 SmallVector<SourceLocation, 4> ProtocolLocs;
5159 = D->protocol_loc_begin();
5160 for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
5161 FromProtoEnd = D->protocol_end();
5162 FromProto != FromProtoEnd;
5163 ++FromProto, ++FromProtoLoc) {
5164 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5165 Protocols.push_back(*ToProtoOrErr);
5166 else
5167 return ToProtoOrErr.takeError();
5168
5169 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5170 ProtocolLocs.push_back(*ToProtoLocOrErr);
5171 else
5172 return ToProtoLocOrErr.takeError();
5173 }
5174
5175 // FIXME: If we're merging, make sure that the protocol list is the same.
5176 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5177 ProtocolLocs.data(), Importer.getToContext());
5178
5179 } else {
5180 Importer.MapImported(D, ToCategory);
5181 }
5182
5183 // Import all of the members of this category.
5184 if (Error Err = ImportDeclContext(D))
5185 return std::move(Err);
5186
5187 // If we have an implementation, import it as well.
5188 if (D->getImplementation()) {
5189 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5190 import(D->getImplementation()))
5191 ToCategory->setImplementation(*ToImplOrErr);
5192 else
5193 return ToImplOrErr.takeError();
5194 }
5195
5196 return ToCategory;
5197}
5198
5201 if (To->getDefinition()) {
5203 if (Error Err = ImportDeclContext(From))
5204 return Err;
5205 return Error::success();
5206 }
5207
5208 // Start the protocol definition
5209 To->startDefinition();
5210
5211 // Import protocols
5213 SmallVector<SourceLocation, 4> ProtocolLocs;
5215 From->protocol_loc_begin();
5216 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5217 FromProtoEnd = From->protocol_end();
5218 FromProto != FromProtoEnd;
5219 ++FromProto, ++FromProtoLoc) {
5220 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5221 Protocols.push_back(*ToProtoOrErr);
5222 else
5223 return ToProtoOrErr.takeError();
5224
5225 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5226 ProtocolLocs.push_back(*ToProtoLocOrErr);
5227 else
5228 return ToProtoLocOrErr.takeError();
5229
5230 }
5231
5232 // FIXME: If we're merging, make sure that the protocol list is the same.
5233 To->setProtocolList(Protocols.data(), Protocols.size(),
5234 ProtocolLocs.data(), Importer.getToContext());
5235
5236 if (shouldForceImportDeclContext(Kind)) {
5237 // Import all of the members of this protocol.
5238 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5239 return Err;
5240 }
5241 return Error::success();
5242}
5243
5245 // If this protocol has a definition in the translation unit we're coming
5246 // from, but this particular declaration is not that definition, import the
5247 // definition and map to that.
5248 ObjCProtocolDecl *Definition = D->getDefinition();
5249 if (Definition && Definition != D) {
5250 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5251 return Importer.MapImported(D, *ImportedDefOrErr);
5252 else
5253 return ImportedDefOrErr.takeError();
5254 }
5255
5256 // Import the major distinguishing characteristics of a protocol.
5257 DeclContext *DC, *LexicalDC;
5258 DeclarationName Name;
5260 NamedDecl *ToD;
5261 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5262 return std::move(Err);
5263 if (ToD)
5264 return ToD;
5265
5266 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5267 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5268 for (auto *FoundDecl : FoundDecls) {
5270 continue;
5271
5272 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5273 break;
5274 }
5275
5276 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5277 if (!ToProto) {
5278 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5279 if (!ToAtBeginLocOrErr)
5280 return ToAtBeginLocOrErr.takeError();
5281
5282 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5283 Name.getAsIdentifierInfo(), Loc,
5284 *ToAtBeginLocOrErr,
5285 /*PrevDecl=*/nullptr))
5286 return ToProto;
5287 ToProto->setLexicalDeclContext(LexicalDC);
5288 LexicalDC->addDeclInternal(ToProto);
5289 }
5290
5291 Importer.MapImported(D, ToProto);
5292
5293 if (D->isThisDeclarationADefinition())
5294 if (Error Err = ImportDefinition(D, ToProto))
5295 return std::move(Err);
5296
5297 return ToProto;
5298}
5299
5301 DeclContext *DC, *LexicalDC;
5302 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5303 return std::move(Err);
5304
5305 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5306 if (!ExternLocOrErr)
5307 return ExternLocOrErr.takeError();
5308
5309 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5310 if (!LangLocOrErr)
5311 return LangLocOrErr.takeError();
5312
5313 bool HasBraces = D->hasBraces();
5314
5315 LinkageSpecDecl *ToLinkageSpec;
5316 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5317 *ExternLocOrErr, *LangLocOrErr,
5318 D->getLanguage(), HasBraces))
5319 return ToLinkageSpec;
5320
5321 if (HasBraces) {
5322 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5323 if (!RBraceLocOrErr)
5324 return RBraceLocOrErr.takeError();
5325 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5326 }
5327
5328 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5329 LexicalDC->addDeclInternal(ToLinkageSpec);
5330
5331 return ToLinkageSpec;
5332}
5333
5335 BaseUsingDecl *ToSI) {
5336 for (UsingShadowDecl *FromShadow : D->shadows()) {
5337 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5338 ToSI->addShadowDecl(*ToShadowOrErr);
5339 else
5340 // FIXME: We return error here but the definition is already created
5341 // and available with lookups. How to fix this?..
5342 return ToShadowOrErr.takeError();
5343 }
5344 return ToSI;
5345}
5346
5348 DeclContext *DC, *LexicalDC;
5349 DeclarationName Name;
5351 NamedDecl *ToD = nullptr;
5352 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5353 return std::move(Err);
5354 if (ToD)
5355 return ToD;
5356
5357 Error Err = Error::success();
5358 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5359 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5360 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5361 if (Err)
5362 return std::move(Err);
5363
5364 DeclarationNameInfo NameInfo(Name, ToLoc);
5365 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5366 return std::move(Err);
5367
5368 UsingDecl *ToUsing;
5369 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5370 ToUsingLoc, ToQualifierLoc, NameInfo,
5371 D->hasTypename()))
5372 return ToUsing;
5373
5374 ToUsing->setLexicalDeclContext(LexicalDC);
5375 LexicalDC->addDeclInternal(ToUsing);
5376
5377 if (NamedDecl *FromPattern =
5379 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5381 ToUsing, *ToPatternOrErr);
5382 else
5383 return ToPatternOrErr.takeError();
5384 }
5385
5386 return ImportUsingShadowDecls(D, ToUsing);
5387}
5388
5390 DeclContext *DC, *LexicalDC;
5391 DeclarationName Name;
5393 NamedDecl *ToD = nullptr;
5394 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5395 return std::move(Err);
5396 if (ToD)
5397 return ToD;
5398
5399 Error Err = Error::success();
5400 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5401 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5402 auto ToNameLoc = importChecked(Err, D->getLocation());
5403 auto *ToEnumType = importChecked(Err, D->getEnumType());
5404 if (Err)
5405 return std::move(Err);
5406
5407 UsingEnumDecl *ToUsingEnum;
5408 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5409 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5410 return ToUsingEnum;
5411
5412 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5413 LexicalDC->addDeclInternal(ToUsingEnum);
5414
5415 if (UsingEnumDecl *FromPattern =
5417 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5418 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5419 *ToPatternOrErr);
5420 else
5421 return ToPatternOrErr.takeError();
5422 }
5423
5424 return ImportUsingShadowDecls(D, ToUsingEnum);
5425}
5426
5428 DeclContext *DC, *LexicalDC;
5429 DeclarationName Name;
5431 NamedDecl *ToD = nullptr;
5432 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5433 return std::move(Err);
5434 if (ToD)
5435 return ToD;
5436
5437 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5438 if (!ToIntroducerOrErr)
5439 return ToIntroducerOrErr.takeError();
5440
5441 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5442 if (!ToTargetOrErr)
5443 return ToTargetOrErr.takeError();
5444
5445 UsingShadowDecl *ToShadow;
5446 if (auto *FromConstructorUsingShadow =
5447 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5448 Error Err = Error::success();
5450 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5451 if (Err)
5452 return std::move(Err);
5453 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5454 // is really the "NominatedBaseClassShadowDecl" value if it exists
5455 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5456 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5457 // get the correct values.
5458 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5459 ToShadow, D, Importer.getToContext(), DC, Loc,
5460 cast<UsingDecl>(*ToIntroducerOrErr),
5461 Nominated ? Nominated : *ToTargetOrErr,
5462 FromConstructorUsingShadow->constructsVirtualBase()))
5463 return ToShadow;
5464 } else {
5465 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5466 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5467 return ToShadow;
5468 }
5469
5470 ToShadow->setLexicalDeclContext(LexicalDC);
5471 ToShadow->setAccess(D->getAccess());
5472
5473 if (UsingShadowDecl *FromPattern =
5475 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5477 ToShadow, *ToPatternOrErr);
5478 else
5479 // FIXME: We return error here but the definition is already created
5480 // and available with lookups. How to fix this?..
5481 return ToPatternOrErr.takeError();
5482 }
5483
5484 LexicalDC->addDeclInternal(ToShadow);
5485
5486 return ToShadow;
5487}
5488
5490 DeclContext *DC, *LexicalDC;
5491 DeclarationName Name;
5493 NamedDecl *ToD = nullptr;
5494 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5495 return std::move(Err);
5496 if (ToD)
5497 return ToD;
5498
5499 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5500 if (!ToComAncestorOrErr)
5501 return ToComAncestorOrErr.takeError();
5502
5503 Error Err = Error::success();
5504 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5505 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5506 auto ToNamespaceKeyLocation =
5507 importChecked(Err, D->getNamespaceKeyLocation());
5508 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5509 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5510 if (Err)
5511 return std::move(Err);
5512
5513 UsingDirectiveDecl *ToUsingDir;
5514 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5515 ToUsingLoc,
5516 ToNamespaceKeyLocation,
5517 ToQualifierLoc,
5518 ToIdentLocation,
5519 ToNominatedNamespace, *ToComAncestorOrErr))
5520 return ToUsingDir;
5521
5522 ToUsingDir->setLexicalDeclContext(LexicalDC);
5523 LexicalDC->addDeclInternal(ToUsingDir);
5524
5525 return ToUsingDir;
5526}
5527
5529 DeclContext *DC, *LexicalDC;
5530 DeclarationName Name;
5532 NamedDecl *ToD = nullptr;
5533 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5534 return std::move(Err);
5535 if (ToD)
5536 return ToD;
5537
5538 auto ToInstantiatedFromUsingOrErr =
5539 Importer.Import(D->getInstantiatedFromUsingDecl());
5540 if (!ToInstantiatedFromUsingOrErr)
5541 return ToInstantiatedFromUsingOrErr.takeError();
5542 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5543 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5544 return std::move(Err);
5545
5546 UsingPackDecl *ToUsingPack;
5547 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5548 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5549 Expansions))
5550 return ToUsingPack;
5551
5552 addDeclToContexts(D, ToUsingPack);
5553
5554 return ToUsingPack;
5555}
5556
5559 DeclContext *DC, *LexicalDC;
5560 DeclarationName Name;
5562 NamedDecl *ToD = nullptr;
5563 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5564 return std::move(Err);
5565 if (ToD)
5566 return ToD;
5567
5568 Error Err = Error::success();
5569 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5570 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5571 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5572 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5573 if (Err)
5574 return std::move(Err);
5575
5576 DeclarationNameInfo NameInfo(Name, ToLoc);
5577 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5578 return std::move(Err);
5579
5580 UnresolvedUsingValueDecl *ToUsingValue;
5581 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5582 ToUsingLoc, ToQualifierLoc, NameInfo,
5583 ToEllipsisLoc))
5584 return ToUsingValue;
5585
5586 ToUsingValue->setAccess(D->getAccess());
5587 ToUsingValue->setLexicalDeclContext(LexicalDC);
5588 LexicalDC->addDeclInternal(ToUsingValue);
5589
5590 return ToUsingValue;
5591}
5592
5595 DeclContext *DC, *LexicalDC;
5596 DeclarationName Name;
5598 NamedDecl *ToD = nullptr;
5599 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5600 return std::move(Err);
5601 if (ToD)
5602 return ToD;
5603
5604 Error Err = Error::success();
5605 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5606 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5607 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5608 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5609 if (Err)
5610 return std::move(Err);
5611
5613 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5614 ToUsingLoc, ToTypenameLoc,
5615 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5616 return ToUsing;
5617
5618 ToUsing->setAccess(D->getAccess());
5619 ToUsing->setLexicalDeclContext(LexicalDC);
5620 LexicalDC->addDeclInternal(ToUsing);
5621
5622 return ToUsing;
5623}
5624
5626 Decl* ToD = nullptr;
5627 switch (D->getBuiltinTemplateKind()) {
5628#define BuiltinTemplate(BTName) \
5629 case BuiltinTemplateKind::BTK##BTName: \
5630 ToD = Importer.getToContext().get##BTName##Decl(); \
5631 break;
5632#include "clang/Basic/BuiltinTemplates.inc"
5633 }
5634 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5635 Importer.MapImported(D, ToD);
5636 return ToD;
5637}
5638
5641 if (To->getDefinition()) {
5642 // Check consistency of superclass.
5643 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5644 if (FromSuper) {
5645 if (auto FromSuperOrErr = import(FromSuper))
5646 FromSuper = *FromSuperOrErr;
5647 else
5648 return FromSuperOrErr.takeError();
5649 }
5650
5651 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5652 if ((bool)FromSuper != (bool)ToSuper ||
5653 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5654 Importer.ToDiag(To->getLocation(),
5655 diag::warn_odr_objc_superclass_inconsistent)
5656 << To->getDeclName();
5657 if (ToSuper)
5658 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5659 << To->getSuperClass()->getDeclName();
5660 else
5661 Importer.ToDiag(To->getLocation(),
5662 diag::note_odr_objc_missing_superclass);
5663 if (From->getSuperClass())
5664 Importer.FromDiag(From->getSuperClassLoc(),
5665 diag::note_odr_objc_superclass)
5666 << From->getSuperClass()->getDeclName();
5667 else
5668 Importer.FromDiag(From->getLocation(),
5669 diag::note_odr_objc_missing_superclass);
5670 }
5671
5673 if (Error Err = ImportDeclContext(From))
5674 return Err;
5675 return Error::success();
5676 }
5677
5678 // Start the definition.
5679 To->startDefinition();
5680
5681 // If this class has a superclass, import it.
5682 if (From->getSuperClass()) {
5683 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5684 To->setSuperClass(*SuperTInfoOrErr);
5685 else
5686 return SuperTInfoOrErr.takeError();
5687 }
5688
5689 // Import protocols
5691 SmallVector<SourceLocation, 4> ProtocolLocs;
5693 From->protocol_loc_begin();
5694
5696 FromProtoEnd = From->protocol_end();
5697 FromProto != FromProtoEnd;
5698 ++FromProto, ++FromProtoLoc) {
5699 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5700 Protocols.push_back(*ToProtoOrErr);
5701 else
5702 return ToProtoOrErr.takeError();
5703
5704 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5705 ProtocolLocs.push_back(*ToProtoLocOrErr);
5706 else
5707 return ToProtoLocOrErr.takeError();
5708
5709 }
5710
5711 // FIXME: If we're merging, make sure that the protocol list is the same.
5712 To->setProtocolList(Protocols.data(), Protocols.size(),
5713 ProtocolLocs.data(), Importer.getToContext());
5714
5715 // Import categories. When the categories themselves are imported, they'll
5716 // hook themselves into this interface.
5717 for (auto *Cat : From->known_categories()) {
5718 auto ToCatOrErr = import(Cat);
5719 if (!ToCatOrErr)
5720 return ToCatOrErr.takeError();
5721 }
5722
5723 // If we have an @implementation, import it as well.
5724 if (From->getImplementation()) {
5725 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5726 import(From->getImplementation()))
5727 To->setImplementation(*ToImplOrErr);
5728 else
5729 return ToImplOrErr.takeError();
5730 }
5731
5732 // Import all of the members of this class.
5733 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5734 return Err;
5735
5736 return Error::success();
5737}
5738
5741 if (!list)
5742 return nullptr;
5743
5745 for (auto *fromTypeParam : *list) {
5746 if (auto toTypeParamOrErr = import(fromTypeParam))
5747 toTypeParams.push_back(*toTypeParamOrErr);
5748 else
5749 return toTypeParamOrErr.takeError();
5750 }
5751
5752 auto LAngleLocOrErr = import(list->getLAngleLoc());
5753 if (!LAngleLocOrErr)
5754 return LAngleLocOrErr.takeError();
5755
5756 auto RAngleLocOrErr = import(list->getRAngleLoc());
5757 if (!RAngleLocOrErr)
5758 return RAngleLocOrErr.takeError();
5759
5760 return ObjCTypeParamList::create(Importer.getToContext(),
5761 *LAngleLocOrErr,
5762 toTypeParams,
5763 *RAngleLocOrErr);
5764}
5765
5767 // If this class has a definition in the translation unit we're coming from,
5768 // but this particular declaration is not that definition, import the
5769 // definition and map to that.
5770 ObjCInterfaceDecl *Definition = D->getDefinition();
5771 if (Definition && Definition != D) {
5772 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5773 return Importer.MapImported(D, *ImportedDefOrErr);
5774 else
5775 return ImportedDefOrErr.takeError();
5776 }
5777
5778 // Import the major distinguishing characteristics of an @interface.
5779 DeclContext *DC, *LexicalDC;
5780 DeclarationName Name;
5782 NamedDecl *ToD;
5783 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5784 return std::move(Err);
5785 if (ToD)
5786 return ToD;
5787
5788 // Look for an existing interface with the same name.
5789 ObjCInterfaceDecl *MergeWithIface = nullptr;
5790 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5791 for (auto *FoundDecl : FoundDecls) {
5793 continue;
5794
5795 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5796 break;
5797 }
5798
5799 // Create an interface declaration, if one does not already exist.
5800 ObjCInterfaceDecl *ToIface = MergeWithIface;
5801 if (!ToIface) {
5802 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5803 if (!AtBeginLocOrErr)
5804 return AtBeginLocOrErr.takeError();
5805
5806 if (GetImportedOrCreateDecl(
5807 ToIface, D, Importer.getToContext(), DC,
5808 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5809 /*TypeParamList=*/nullptr,
5810 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5811 return ToIface;
5812 ToIface->setLexicalDeclContext(LexicalDC);
5813 LexicalDC->addDeclInternal(ToIface);
5814 }
5815 Importer.MapImported(D, ToIface);
5816 // Import the type parameter list after MapImported, to avoid
5817 // loops when bringing in their DeclContext.
5818 if (auto ToPListOrErr =
5819 ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
5820 ToIface->setTypeParamList(*ToPListOrErr);
5821 else
5822 return ToPListOrErr.takeError();
5823
5824 if (D->isThisDeclarationADefinition())
5825 if (Error Err = ImportDefinition(D, ToIface))
5826 return std::move(Err);
5827
5828 return ToIface;
5829}
5830
5834 if (Error Err = importInto(Category, D->getCategoryDecl()))
5835 return std::move(Err);
5836
5837 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5838 if (!ToImpl) {
5839 DeclContext *DC, *LexicalDC;
5840 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5841 return std::move(Err);
5842
5843 Error Err = Error::success();
5844 auto ToLocation = importChecked(Err, D->getLocation());
5845 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5846 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5847 if (Err)
5848 return std::move(Err);
5849
5850 if (GetImportedOrCreateDecl(
5851 ToImpl, D, Importer.getToContext(), DC,
5852 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5853 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5854 return ToImpl;
5855
5856 ToImpl->setLexicalDeclContext(LexicalDC);
5857 LexicalDC->addDeclInternal(ToImpl);
5858 Category->setImplementation(ToImpl);
5859 }
5860
5861 Importer.MapImported(D, ToImpl);
5862 if (Error Err = ImportDeclContext(D))
5863 return std::move(Err);
5864
5865 return ToImpl;
5866}
5867
5870 // Find the corresponding interface.
5871 ObjCInterfaceDecl *Iface;
5872 if (Error Err = importInto(Iface, D->getClassInterface()))
5873 return std::move(Err);
5874
5875 // Import the superclass, if any.
5876 ObjCInterfaceDecl *Super;
5877 if (Error Err = importInto(Super, D->getSuperClass()))
5878 return std::move(Err);
5879
5881 if (!Impl) {
5882 // We haven't imported an implementation yet. Create a new @implementation
5883 // now.
5884 DeclContext *DC, *LexicalDC;
5885 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5886 return std::move(Err);
5887
5888 Error Err = Error::success();
5889 auto ToLocation = importChecked(Err, D->getLocation());
5890 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5891 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5892 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5893 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5894 if (Err)
5895 return std::move(Err);
5896
5897 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5898 DC, Iface, Super,
5899 ToLocation,
5900 ToAtStartLoc,
5901 ToSuperClassLoc,
5902 ToIvarLBraceLoc,
5903 ToIvarRBraceLoc))
5904 return Impl;
5905
5906 Impl->setLexicalDeclContext(LexicalDC);
5907
5908 // Associate the implementation with the class it implements.
5909 Iface->setImplementation(Impl);
5910 Importer.MapImported(D, Iface->getImplementation());
5911 } else {
5912 Importer.MapImported(D, Iface->getImplementation());
5913
5914 // Verify that the existing @implementation has the same superclass.
5915 if ((Super && !Impl->getSuperClass()) ||
5916 (!Super && Impl->getSuperClass()) ||
5917 (Super && Impl->getSuperClass() &&
5919 Impl->getSuperClass()))) {
5920 Importer.ToDiag(Impl->getLocation(),
5921 diag::warn_odr_objc_superclass_inconsistent)
5922 << Iface->getDeclName();
5923 // FIXME: It would be nice to have the location of the superclass
5924 // below.
5925 if (Impl->getSuperClass())
5926 Importer.ToDiag(Impl->getLocation(),
5927 diag::note_odr_objc_superclass)
5928 << Impl->getSuperClass()->getDeclName();
5929 else
5930 Importer.ToDiag(Impl->getLocation(),
5931 diag::note_odr_objc_missing_superclass);
5932 if (D->getSuperClass())
5933 Importer.FromDiag(D->getLocation(),
5934 diag::note_odr_objc_superclass)
5935 << D->getSuperClass()->getDeclName();
5936 else
5937 Importer.FromDiag(D->getLocation(),
5938 diag::note_odr_objc_missing_superclass);
5939
5940 return make_error<ASTImportError>(ASTImportError::NameConflict);
5941 }
5942 }
5943
5944 // Import all of the members of this @implementation.
5945 if (Error Err = ImportDeclContext(D))
5946 return std::move(Err);
5947
5948 return Impl;
5949}
5950
5952 // Import the major distinguishing characteristics of an @property.
5953 DeclContext *DC, *LexicalDC;
5954 DeclarationName Name;
5956 NamedDecl *ToD;
5957 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5958 return std::move(Err);
5959 if (ToD)
5960 return ToD;
5961
5962 // Check whether we have already imported this property.
5963 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5964 for (auto *FoundDecl : FoundDecls) {
5965 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5966 // Instance and class properties can share the same name but are different
5967 // declarations.
5968 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5969 continue;
5970
5971 // Check property types.
5972 if (!Importer.IsStructurallyEquivalent(D->getType(),
5973 FoundProp->getType())) {
5974 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5975 << Name << D->getType() << FoundProp->getType();
5976 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5977 << FoundProp->getType();
5978
5979 return make_error<ASTImportError>(ASTImportError::NameConflict);
5980 }
5981
5982 // FIXME: Check property attributes, getters, setters, etc.?
5983
5984 // Consider these properties to be equivalent.
5985 Importer.MapImported(D, FoundProp);
5986 return FoundProp;
5987 }
5988 }
5989
5990 Error Err = Error::success();
5991 auto ToType = importChecked(Err, D->getType());
5992 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5993 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5994 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5995 if (Err)
5996 return std::move(Err);
5997
5998 // Create the new property.
5999 ObjCPropertyDecl *ToProperty;
6000 if (GetImportedOrCreateDecl(
6001 ToProperty, D, Importer.getToContext(), DC, Loc,
6002 Name.getAsIdentifierInfo(), ToAtLoc,
6003 ToLParenLoc, ToType,
6004 ToTypeSourceInfo, D->getPropertyImplementation()))
6005 return ToProperty;
6006
6007 auto ToGetterName = importChecked(Err, D->getGetterName());
6008 auto ToSetterName = importChecked(Err, D->getSetterName());
6009 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
6010 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
6011 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
6012 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
6013 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
6014 if (Err)
6015 return std::move(Err);
6016
6017 ToProperty->setLexicalDeclContext(LexicalDC);
6018 LexicalDC->addDeclInternal(ToProperty);
6019
6020 ToProperty->setPropertyAttributes(D->getPropertyAttributes());
6022 D->getPropertyAttributesAsWritten());
6023 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
6024 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
6025 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
6026 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
6027 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
6028 return ToProperty;
6029}
6030
6034 if (Error Err = importInto(Property, D->getPropertyDecl()))
6035 return std::move(Err);
6036
6037 DeclContext *DC, *LexicalDC;
6038 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6039 return std::move(Err);
6040
6041 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
6042
6043 // Import the ivar (for an @synthesize).
6044 ObjCIvarDecl *Ivar = nullptr;
6045 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
6046 return std::move(Err);
6047
6048 ObjCPropertyImplDecl *ToImpl
6049 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
6050 Property->getQueryKind());
6051 if (!ToImpl) {
6052
6053 Error Err = Error::success();
6054 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
6055 auto ToLocation = importChecked(Err, D->getLocation());
6056 auto ToPropertyIvarDeclLoc =
6057 importChecked(Err, D->getPropertyIvarDeclLoc());
6058 if (Err)
6059 return std::move(Err);
6060
6061 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
6062 ToBeginLoc,
6063 ToLocation, Property,
6064 D->getPropertyImplementation(), Ivar,
6065 ToPropertyIvarDeclLoc))
6066 return ToImpl;
6067
6068 ToImpl->setLexicalDeclContext(LexicalDC);
6069 LexicalDC->addDeclInternal(ToImpl);
6070 } else {
6071 // Check that we have the same kind of property implementation (@synthesize
6072 // vs. @dynamic).
6073 if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
6074 Importer.ToDiag(ToImpl->getLocation(),
6075 diag::warn_odr_objc_property_impl_kind_inconsistent)
6076 << Property->getDeclName()
6077 << (ToImpl->getPropertyImplementation()
6079 Importer.FromDiag(D->getLocation(),
6080 diag::note_odr_objc_property_impl_kind)
6081 << D->getPropertyDecl()->getDeclName()
6082 << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
6083
6084 return make_error<ASTImportError>(ASTImportError::NameConflict);
6085 }
6086
6087 // For @synthesize, check that we have the same
6088 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize &&
6089 Ivar != ToImpl->getPropertyIvarDecl()) {
6090 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
6091 diag::warn_odr_objc_synthesize_ivar_inconsistent)
6092 << Property->getDeclName()
6093 << ToImpl->getPropertyIvarDecl()->getDeclName()
6094 << Ivar->getDeclName();
6095 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
6096 diag::note_odr_objc_synthesize_ivar_here)
6097 << D->getPropertyIvarDecl()->getDeclName();
6098
6099 return make_error<ASTImportError>(ASTImportError::NameConflict);
6100 }
6101
6102 // Merge the existing implementation with the new implementation.
6103 Importer.MapImported(D, ToImpl);
6104 }
6105
6106 return ToImpl;
6107}
6108
6111 // For template arguments, we adopt the translation unit as our declaration
6112 // context. This context will be fixed when (during) the actual template
6113 // declaration is created.
6114
6115 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6116 if (!BeginLocOrErr)
6117 return BeginLocOrErr.takeError();
6118
6119 ExpectedSLoc LocationOrErr = import(D->getLocation());
6120 if (!LocationOrErr)
6121 return LocationOrErr.takeError();
6122
6123 TemplateTypeParmDecl *ToD = nullptr;
6124 if (GetImportedOrCreateDecl(
6125 ToD, D, Importer.getToContext(),
6127 *BeginLocOrErr, *LocationOrErr,
6128 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
6129 D->wasDeclaredWithTypename(), D->isParameterPack(),
6130 D->hasTypeConstraint()))
6131 return ToD;
6132
6133 // Import the type-constraint
6134 if (const TypeConstraint *TC = D->getTypeConstraint()) {
6135
6136 Error Err = Error::success();
6137 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
6138 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
6139 if (Err)
6140 return std::move(Err);
6141
6142 ToD->setTypeConstraint(ToConceptRef, ToIDC, TC->getArgPackSubstIndex());
6143 }
6144
6145 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6146 return Err;
6147
6148 return ToD;
6149}
6150
6153
6154 Error Err = Error::success();
6155 auto ToDeclName = importChecked(Err, D->getDeclName());
6156 auto ToLocation = importChecked(Err, D->getLocation());
6157 auto ToType = importChecked(Err, D->getType());
6158 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6159 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6160 if (Err)
6161 return std::move(Err);
6162
6163 NonTypeTemplateParmDecl *ToD = nullptr;
6164 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6166 ToInnerLocStart, ToLocation, D->getDepth(),
6167 D->getPosition(),
6168 ToDeclName.getAsIdentifierInfo(), ToType,
6169 D->isParameterPack(), ToTypeSourceInfo))
6170 return ToD;
6171
6172 Err = importTemplateParameterDefaultArgument(D, ToD);
6173 if (Err)
6174 return Err;
6175
6176 return ToD;
6177}
6178
6181 bool IsCanonical = false;
6182 if (auto *CanonD = Importer.getFromContext()
6184 CanonD == D)
6185 IsCanonical = true;
6186
6187 // Import the name of this declaration.
6188 auto NameOrErr = import(D->getDeclName());
6189 if (!NameOrErr)
6190 return NameOrErr.takeError();
6191
6192 // Import the location of this declaration.
6193 ExpectedSLoc LocationOrErr = import(D->getLocation());
6194 if (!LocationOrErr)
6195 return LocationOrErr.takeError();
6196
6197 // Import template parameters.
6198 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6199 if (!TemplateParamsOrErr)
6200 return TemplateParamsOrErr.takeError();
6201
6202 TemplateTemplateParmDecl *ToD = nullptr;
6203 if (GetImportedOrCreateDecl(
6204 ToD, D, Importer.getToContext(),
6205 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6206 D->getDepth(), D->getPosition(), D->isParameterPack(),
6207 (*NameOrErr).getAsIdentifierInfo(), D->templateParameterKind(),
6208 D->wasDeclaredWithTypename(), *TemplateParamsOrErr))
6209 return ToD;
6210
6211 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6212 return Err;
6213
6214 if (IsCanonical)
6215 return Importer.getToContext()
6217
6218 return ToD;
6219}
6220
6221// Returns the definition for a (forward) declaration of a TemplateDecl, if
6222// it has any definition in the redecl chain.
6223template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6224 assert(D->getTemplatedDecl() && "Should be called on templates only");
6225 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6226 if (!ToTemplatedDef)
6227 return nullptr;
6228 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6229 return cast_or_null<T>(TemplateWithDef);
6230}
6231
6233
6234 // Import the major distinguishing characteristics of this class template.
6235 DeclContext *DC, *LexicalDC;
6236 DeclarationName Name;
6238 NamedDecl *ToD;
6239 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6240 return std::move(Err);
6241 if (ToD)
6242 return ToD;
6243
6244 // Should check if a declaration is friend in a dependent context.
6245 // Such templates are not linked together in a declaration chain.
6246 // The ASTImporter strategy is to map existing forward declarations to
6247 // imported ones only if strictly necessary, otherwise import these as new
6248 // forward declarations. In case of the "dependent friend" declarations, new
6249 // declarations are created, but not linked in a declaration chain.
6250 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6251 return TD->getFriendObjectKind() != Decl::FOK_None &&
6252 TD->getLexicalDeclContext()->isDependentContext();
6253 };
6254 bool DependentFriend = IsDependentFriend(D);
6255
6256 ClassTemplateDecl *FoundByLookup = nullptr;
6257
6258 // We may already have a template of the same name; try to find and match it.
6259 if (!DC->isFunctionOrMethod()) {
6260 SmallVector<NamedDecl *, 4> ConflictingDecls;
6261 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6262 for (auto *FoundDecl : FoundDecls) {
6265 continue;
6266
6267 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6268 if (FoundTemplate) {
6269 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6270 continue;
6271
6272 // FIXME: sufficient condition for 'IgnoreTemplateParmDepth'?
6273 bool IgnoreTemplateParmDepth =
6274 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6276 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6277 IgnoreTemplateParmDepth)) {
6278 if (DependentFriend || IsDependentFriend(FoundTemplate))
6279 continue;
6280
6281 ClassTemplateDecl *TemplateWithDef =
6282 getTemplateDefinition(FoundTemplate);
6283 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6284 return Importer.MapImported(D, TemplateWithDef);
6285 if (!FoundByLookup)
6286 FoundByLookup = FoundTemplate;
6287 // Search in all matches because there may be multiple decl chains,
6288 // see ASTTests test ImportExistingFriendClassTemplateDef.
6289 continue;
6290 }
6291 // When importing a friend, it is possible that multiple declarations
6292 // with same name can co-exist in specific cases (if a template contains
6293 // a friend template and has a specialization). For this case the
6294 // declarations should match, except that the "template depth" is
6295 // different. No linking of previous declaration is needed in this case.
6296 // FIXME: This condition may need refinement.
6298 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6299 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6300 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6301 /*IgnoreTemplateParmDepth=*/true))
6302 continue;
6303
6304 ConflictingDecls.push_back(FoundDecl);
6305 }
6306 }
6307
6308 if (!ConflictingDecls.empty()) {
6309 ExpectedName NameOrErr = Importer.HandleNameConflict(
6310 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6311 ConflictingDecls.size());
6312 if (NameOrErr)
6313 Name = NameOrErr.get();
6314 else
6315 return NameOrErr.takeError();
6316 }
6317 }
6318
6319 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6320
6321 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6322 if (!TemplateParamsOrErr)
6323 return TemplateParamsOrErr.takeError();
6324
6325 // Create the declaration that is being templated.
6326 CXXRecordDecl *ToTemplated;
6327 if (Error Err = importInto(ToTemplated, FromTemplated))
6328 return std::move(Err);
6329
6330 // Create the class template declaration itself.
6332 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6333 *TemplateParamsOrErr, ToTemplated))
6334 return D2;
6335
6336 ToTemplated->setDescribedClassTemplate(D2);
6337
6338 D2->setAccess(D->getAccess());
6339 D2->setLexicalDeclContext(LexicalDC);
6340
6341 addDeclToContexts(D, D2);
6342 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6343
6344 if (FoundByLookup) {
6345 auto *Recent =
6346 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6347
6348 // It is possible that during the import of the class template definition
6349 // we start the import of a fwd friend decl of the very same class template
6350 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6351 // had been created earlier and by that time the lookup could not find
6352 // anything existing, so it has no previous decl. Later, (still during the
6353 // import of the fwd friend decl) we start to import the definition again
6354 // and this time the lookup finds the previous fwd friend class template.
6355 // In this case we must set up the previous decl for the templated decl.
6356 if (!ToTemplated->getPreviousDecl()) {
6357 assert(FoundByLookup->getTemplatedDecl() &&
6358 "Found decl must have its templated decl set");
6359 CXXRecordDecl *PrevTemplated =
6360 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6361 if (ToTemplated != PrevTemplated)
6362 ToTemplated->setPreviousDecl(PrevTemplated);
6363 }
6364
6365 D2->setPreviousDecl(Recent);
6366 }
6367
6368 return D2;
6369}
6370
6373 ClassTemplateDecl *ClassTemplate;
6374 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6375 return std::move(Err);
6376
6377 // Import the context of this declaration.
6378 DeclContext *DC, *LexicalDC;
6379 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6380 return std::move(Err);
6381
6382 // Import template arguments.
6384 if (Error Err =
6385 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6386 return std::move(Err);
6387 // Try to find an existing specialization with these template arguments and
6388 // template parameter list.
6389 void *InsertPos = nullptr;
6390 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6392 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6393
6394 // Import template parameters.
6395 TemplateParameterList *ToTPList = nullptr;
6396
6397 if (PartialSpec) {
6398 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6399 if (!ToTPListOrErr)
6400 return ToTPListOrErr.takeError();
6401 ToTPList = *ToTPListOrErr;
6402 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6403 *ToTPListOrErr,
6404 InsertPos);
6405 } else
6406 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6407
6408 if (PrevDecl) {
6409 if (IsStructuralMatch(D, PrevDecl)) {
6410 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6411 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6412 Importer.MapImported(D, PrevDefinition);
6413 // Import those default field initializers which have been
6414 // instantiated in the "From" context, but not in the "To" context.
6415 for (auto *FromField : D->fields()) {
6416 auto ToOrErr = import(FromField);
6417 if (!ToOrErr)
6418 return ToOrErr.takeError();
6419 }
6420
6421 // Import those methods which have been instantiated in the
6422 // "From" context, but not in the "To" context.
6423 for (CXXMethodDecl *FromM : D->methods()) {
6424 auto ToOrErr = import(FromM);
6425 if (!ToOrErr)
6426 return ToOrErr.takeError();
6427 }
6428
6429 // TODO Import instantiated default arguments.
6430 // TODO Import instantiated exception specifications.
6431 //
6432 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6433 // what else could be fused during an AST merge.
6434 return PrevDefinition;
6435 }
6436 } else { // ODR violation.
6437 // FIXME HandleNameConflict
6438 return make_error<ASTImportError>(ASTImportError::NameConflict);
6439 }
6440 }
6441
6442 // Import the location of this declaration.
6443 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6444 if (!BeginLocOrErr)
6445 return BeginLocOrErr.takeError();
6446 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6447 if (!IdLocOrErr)
6448 return IdLocOrErr.takeError();
6449
6450 // Import TemplateArgumentListInfo.
6451 TemplateArgumentListInfo ToTAInfo;
6452 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6453 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6454 return std::move(Err);
6455 }
6456
6457 // Create the specialization.
6458 ClassTemplateSpecializationDecl *D2 = nullptr;
6459 if (PartialSpec) {
6460 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6461 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6462 *IdLocOrErr, ToTPList, ClassTemplate, ArrayRef(TemplateArgs),
6463 /*CanonInjectedTST=*/CanQualType(),
6464 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6465 return D2;
6466
6467 // Update InsertPos, because preceding import calls may have invalidated
6468 // it by adding new specializations.
6469 auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6470 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6471 InsertPos))
6472 // Add this partial specialization to the class template.
6473 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6475 import(PartialSpec->getInstantiatedFromMember()))
6476 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6477 else
6478 return ToInstOrErr.takeError();
6479
6480 updateLookupTableForTemplateParameters(*ToTPList);
6481 } else { // Not a partial specialization.
6482 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), D->getTagKind(),
6483 DC, *BeginLocOrErr, *IdLocOrErr, ClassTemplate,
6484 TemplateArgs, D->hasStrictPackMatch(),
6485 PrevDecl))
6486 return D2;
6487
6488 // Update InsertPos, because preceding import calls may have invalidated
6489 // it by adding new specializations.
6490 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6491 // Add this specialization to the class template.
6492 ClassTemplate->AddSpecialization(D2, InsertPos);
6493 }
6494
6495 D2->setSpecializationKind(D->getSpecializationKind());
6496
6497 // Set the context of this specialization/instantiation.
6498 D2->setLexicalDeclContext(LexicalDC);
6499
6500 // Add to the DC only if it was an explicit specialization/instantiation.
6502 LexicalDC->addDeclInternal(D2);
6503 }
6504
6505 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6506 D2->setBraceRange(*BraceRangeOrErr);
6507 else
6508 return BraceRangeOrErr.takeError();
6509
6510 if (Error Err = ImportTemplateParameterLists(D, D2))
6511 return std::move(Err);
6512
6513 // Import the qualifier, if any.
6514 if (auto LocOrErr = import(D->getQualifierLoc()))
6515 D2->setQualifierInfo(*LocOrErr);
6516 else
6517 return LocOrErr.takeError();
6518
6519 if (D->getTemplateArgsAsWritten())
6520 D2->setTemplateArgsAsWritten(ToTAInfo);
6521
6522 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6523 D2->setTemplateKeywordLoc(*LocOrErr);
6524 else
6525 return LocOrErr.takeError();
6526
6527 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6528 D2->setExternKeywordLoc(*LocOrErr);
6529 else
6530 return LocOrErr.takeError();
6531
6532 if (D->getPointOfInstantiation().isValid()) {
6533 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6534 D2->setPointOfInstantiation(*POIOrErr);
6535 else
6536 return POIOrErr.takeError();
6537 }
6538
6539 D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
6540
6541 if (auto P = D->getInstantiatedFrom()) {
6542 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6543 if (auto CTDorErr = import(CTD))
6544 D2->setInstantiationOf(*CTDorErr);
6545 } else {
6546 auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6547 auto CTPSDOrErr = import(CTPSD);
6548 if (!CTPSDOrErr)
6549 return CTPSDOrErr.takeError();
6550 const TemplateArgumentList &DArgs = D->getTemplateInstantiationArgs();
6551 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6552 for (unsigned I = 0; I < DArgs.size(); ++I) {
6553 const TemplateArgument &DArg = DArgs[I];
6554 if (auto ArgOrErr = import(DArg))
6555 D2ArgsVec[I] = *ArgOrErr;
6556 else
6557 return ArgOrErr.takeError();
6558 }
6560 *CTPSDOrErr,
6561 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6562 }
6563 }
6564
6565 if (D->isCompleteDefinition())
6566 if (Error Err = ImportDefinition(D, D2))
6567 return std::move(Err);
6568
6569 return D2;
6570}
6571
6573 // Import the major distinguishing characteristics of this variable template.
6574 DeclContext *DC, *LexicalDC;
6575 DeclarationName Name;
6577 NamedDecl *ToD;
6578 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6579 return std::move(Err);
6580 if (ToD)
6581 return ToD;
6582
6583 // We may already have a template of the same name; try to find and match it.
6584 assert(!DC->isFunctionOrMethod() &&
6585 "Variable templates cannot be declared at function scope");
6586
6587 SmallVector<NamedDecl *, 4> ConflictingDecls;
6588 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6589 VarTemplateDecl *FoundByLookup = nullptr;
6590 for (auto *FoundDecl : FoundDecls) {
6592 continue;
6593
6594 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6595 // Use the templated decl, some linkage flags are set only there.
6596 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6597 D->getTemplatedDecl()))
6598 continue;
6599 if (IsStructuralMatch(D, FoundTemplate)) {
6600 // FIXME Check for ODR error if the two definitions have
6601 // different initializers?
6602 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6603 if (D->getDeclContext()->isRecord()) {
6604 assert(FoundTemplate->getDeclContext()->isRecord() &&
6605 "Member variable template imported as non-member, "
6606 "inconsistent imported AST?");
6607 if (FoundDef)
6608 return Importer.MapImported(D, FoundDef);
6609 if (!D->isThisDeclarationADefinition())
6610 return Importer.MapImported(D, FoundTemplate);
6611 } else {
6612 if (FoundDef && D->isThisDeclarationADefinition())
6613 return Importer.MapImported(D, FoundDef);
6614 }
6615 FoundByLookup = FoundTemplate;
6616 break;
6617 }
6618 ConflictingDecls.push_back(FoundDecl);
6619 }
6620 }
6621
6622 if (!ConflictingDecls.empty()) {
6623 ExpectedName NameOrErr = Importer.HandleNameConflict(
6624 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6625 ConflictingDecls.size());
6626 if (NameOrErr)
6627 Name = NameOrErr.get();
6628 else
6629 return NameOrErr.takeError();
6630 }
6631
6632 VarDecl *DTemplated = D->getTemplatedDecl();
6633
6634 // Import the type.
6635 // FIXME: Value not used?
6636 ExpectedType TypeOrErr = import(DTemplated->getType());
6637 if (!TypeOrErr)
6638 return TypeOrErr.takeError();
6639
6640 // Create the declaration that is being templated.
6641 VarDecl *ToTemplated;
6642 if (Error Err = importInto(ToTemplated, DTemplated))
6643 return std::move(Err);
6644
6645 // Create the variable template declaration itself.
6646 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6647 if (!TemplateParamsOrErr)
6648 return TemplateParamsOrErr.takeError();
6649
6650 VarTemplateDecl *ToVarTD;
6651 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6652 Name, *TemplateParamsOrErr, ToTemplated))
6653 return ToVarTD;
6654
6655 ToTemplated->setDescribedVarTemplate(ToVarTD);
6656
6657 ToVarTD->setAccess(D->getAccess());
6658 ToVarTD->setLexicalDeclContext(LexicalDC);
6659 LexicalDC->addDeclInternal(ToVarTD);
6660 if (DC != Importer.getToContext().getTranslationUnitDecl())
6661 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6662
6663 if (FoundByLookup) {
6664 auto *Recent =
6665 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6666 if (!ToTemplated->getPreviousDecl()) {
6667 auto *PrevTemplated =
6668 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6669 if (ToTemplated != PrevTemplated)
6670 ToTemplated->setPreviousDecl(PrevTemplated);
6671 }
6672 ToVarTD->setPreviousDecl(Recent);
6673 }
6674
6675 return ToVarTD;
6676}
6677
6680 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6681 // in an analog way (but specialized for this case).
6682
6684 auto RedeclIt = Redecls.begin();
6685 // Import the first part of the decl chain. I.e. import all previous
6686 // declarations starting from the canonical decl.
6687 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6688 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6689 if (!RedeclOrErr)
6690 return RedeclOrErr.takeError();
6691 }
6692 assert(*RedeclIt == D);
6693
6694 VarTemplateDecl *VarTemplate = nullptr;
6695 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6696 return std::move(Err);
6697
6698 // Import the context of this declaration.
6699 DeclContext *DC, *LexicalDC;
6700 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6701 return std::move(Err);
6702
6703 // Import the location of this declaration.
6704 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6705 if (!BeginLocOrErr)
6706 return BeginLocOrErr.takeError();
6707
6708 auto IdLocOrErr = import(D->getLocation());
6709 if (!IdLocOrErr)
6710 return IdLocOrErr.takeError();
6711
6712 // Import template arguments.
6714 if (Error Err =
6715 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6716 return std::move(Err);
6717
6718 // Try to find an existing specialization with these template arguments.
6719 void *InsertPos = nullptr;
6720 VarTemplateSpecializationDecl *FoundSpecialization =
6721 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6722 if (FoundSpecialization) {
6723 if (IsStructuralMatch(D, FoundSpecialization)) {
6724 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6725 if (D->getDeclContext()->isRecord()) {
6726 // In a record, it is allowed only to have one optional declaration and
6727 // one definition of the (static or constexpr) variable template.
6728 assert(
6729 FoundSpecialization->getDeclContext()->isRecord() &&
6730 "Member variable template specialization imported as non-member, "
6731 "inconsistent imported AST?");
6732 if (FoundDef)
6733 return Importer.MapImported(D, FoundDef);
6734 if (!D->isThisDeclarationADefinition())
6735 return Importer.MapImported(D, FoundSpecialization);
6736 } else {
6737 // If definition is imported and there is already one, map to it.
6738 // Otherwise create a new variable and link it to the existing.
6739 if (FoundDef && D->isThisDeclarationADefinition())
6740 return Importer.MapImported(D, FoundDef);
6741 }
6742 } else {
6743 return make_error<ASTImportError>(ASTImportError::NameConflict);
6744 }
6745 }
6746
6747 VarTemplateSpecializationDecl *D2 = nullptr;
6748
6749 TemplateArgumentListInfo ToTAInfo;
6750 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6751 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6752 return std::move(Err);
6753 }
6754
6755 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6756 // Create a new specialization.
6757 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6758 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6759 if (!ToTPListOrErr)
6760 return ToTPListOrErr.takeError();
6761
6762 PartVarSpecDecl *ToPartial;
6763 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6764 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6765 VarTemplate, QualType(), nullptr,
6766 D->getStorageClass(), TemplateArgs))
6767 return ToPartial;
6768
6769 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6770 import(FromPartial->getInstantiatedFromMember()))
6771 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6772 else
6773 return ToInstOrErr.takeError();
6774
6775 if (FromPartial->isMemberSpecialization())
6776 ToPartial->setMemberSpecialization();
6777
6778 D2 = ToPartial;
6779
6780 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6781 // to adopt template parameters.
6782 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6783 } else { // Full specialization
6784 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6785 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6786 QualType(), nullptr, D->getStorageClass(),
6787 TemplateArgs))
6788 return D2;
6789 }
6790
6791 // Update InsertPos, because preceding import calls may have invalidated
6792 // it by adding new specializations.
6793 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6794 VarTemplate->AddSpecialization(D2, InsertPos);
6795
6796 QualType T;
6797 if (Error Err = importInto(T, D->getType()))
6798 return std::move(Err);
6799 D2->setType(T);
6800
6801 auto TInfoOrErr = import(D->getTypeSourceInfo());
6802 if (!TInfoOrErr)
6803 return TInfoOrErr.takeError();
6804 D2->setTypeSourceInfo(*TInfoOrErr);
6805
6806 if (D->getPointOfInstantiation().isValid()) {
6807 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6808 D2->setPointOfInstantiation(*POIOrErr);
6809 else
6810 return POIOrErr.takeError();
6811 }
6812
6813 D2->setSpecializationKind(D->getSpecializationKind());
6814
6815 if (D->getTemplateArgsAsWritten())
6816 D2->setTemplateArgsAsWritten(ToTAInfo);
6817
6818 if (auto LocOrErr = import(D->getQualifierLoc()))
6819 D2->setQualifierInfo(*LocOrErr);
6820 else
6821 return LocOrErr.takeError();
6822
6823 if (D->isConstexpr())
6824 D2->setConstexpr(true);
6825
6826 D2->setAccess(D->getAccess());
6827
6828 if (Error Err = ImportInitializer(D, D2))
6829 return std::move(Err);
6830
6831 if (FoundSpecialization)
6832 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6833
6834 addDeclToContexts(D, D2);
6835
6836 // Import the rest of the chain. I.e. import all subsequent declarations.
6837 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6838 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6839 if (!RedeclOrErr)
6840 return RedeclOrErr.takeError();
6841 }
6842
6843 return D2;
6844}
6845
6848 DeclContext *DC, *LexicalDC;
6849 DeclarationName Name;
6851 NamedDecl *ToD;
6852
6853 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6854 return std::move(Err);
6855
6856 if (ToD)
6857 return ToD;
6858
6859 const FunctionTemplateDecl *FoundByLookup = nullptr;
6860
6861 // Try to find a function in our own ("to") context with the same name, same
6862 // type, and in the same context as the function we're importing.
6863 // FIXME Split this into a separate function.
6864 if (!LexicalDC->isFunctionOrMethod()) {
6866 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6867 for (auto *FoundDecl : FoundDecls) {
6868 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6869 continue;
6870
6871 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6872 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6873 continue;
6874 if (IsStructuralMatch(D, FoundTemplate)) {
6875 FunctionTemplateDecl *TemplateWithDef =
6876 getTemplateDefinition(FoundTemplate);
6877 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6878 return Importer.MapImported(D, TemplateWithDef);
6879
6880 FoundByLookup = FoundTemplate;
6881 break;
6882 // TODO: handle conflicting names
6883 }
6884 }
6885 }
6886 }
6887
6888 auto ParamsOrErr = import(D->getTemplateParameters());
6889 if (!ParamsOrErr)
6890 return ParamsOrErr.takeError();
6891 TemplateParameterList *Params = *ParamsOrErr;
6892
6893 FunctionDecl *TemplatedFD;
6894 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6895 return std::move(Err);
6896
6897 // At creation of the template the template parameters are "adopted"
6898 // (DeclContext is changed). After this possible change the lookup table
6899 // must be updated.
6900 // At deduction guides the DeclContext of the template parameters may be
6901 // different from what we would expect, it may be the class template, or a
6902 // probably different CXXDeductionGuideDecl. This may come from the fact that
6903 // the template parameter objects may be shared between deduction guides or
6904 // the class template, and at creation of multiple FunctionTemplateDecl
6905 // objects (for deduction guides) the same parameters are re-used. The
6906 // "adoption" happens multiple times with different parent, even recursively
6907 // for TemplateTemplateParmDecl. The same happens at import when the
6908 // FunctionTemplateDecl objects are created, but in different order.
6909 // In this way the DeclContext of these template parameters is not necessarily
6910 // the same as in the "from" context.
6912 OldParamDC.reserve(Params->size());
6913 llvm::transform(*Params, std::back_inserter(OldParamDC),
6914 [](NamedDecl *ND) { return ND->getDeclContext(); });
6915
6916 FunctionTemplateDecl *ToFunc;
6917 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6918 Params, TemplatedFD))
6919 return ToFunc;
6920
6921 // Fail if TemplatedFD is already part of a template.
6922 // The template should have been found by structural equivalence check before,
6923 // or ToFunc should be already imported.
6924 // If not, there is AST incompatibility that can be caused by previous import
6925 // errors. (NameConflict is not exact here.)
6926 if (TemplatedFD->getDescribedTemplate())
6927 return make_error<ASTImportError>(ASTImportError::NameConflict);
6928
6929 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6930
6931 ToFunc->setAccess(D->getAccess());
6932 ToFunc->setLexicalDeclContext(LexicalDC);
6933 addDeclToContexts(D, ToFunc);
6934
6935 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6936 if (LT && !OldParamDC.empty()) {
6937 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6938 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6939 }
6940
6941 if (FoundByLookup) {
6942 auto *Recent =
6943 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6944 if (!TemplatedFD->getPreviousDecl()) {
6945 assert(FoundByLookup->getTemplatedDecl() &&
6946 "Found decl must have its templated decl set");
6947 auto *PrevTemplated =
6948 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6949 if (TemplatedFD != PrevTemplated)
6950 TemplatedFD->setPreviousDecl(PrevTemplated);
6951 }
6952 ToFunc->setPreviousDecl(Recent);
6953 }
6954
6955 return ToFunc;
6956}
6957
6959 DeclContext *DC, *LexicalDC;
6960 Error Err = ImportDeclContext(D, DC, LexicalDC);
6961 auto LocationOrErr = importChecked(Err, D->getLocation());
6962 auto NameDeclOrErr = importChecked(Err, D->getDeclName());
6963 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
6964 auto ConstraintExpr = importChecked(Err, D->getConstraintExpr());
6965 if (Err)
6966 return std::move(Err);
6967
6968 ConceptDecl *To;
6969 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, LocationOrErr,
6970 NameDeclOrErr, ToTemplateParameters,
6971 ConstraintExpr))
6972 return To;
6973 To->setLexicalDeclContext(LexicalDC);
6974 LexicalDC->addDeclInternal(To);
6975 return To;
6976}
6977
6980 DeclContext *DC, *LexicalDC;
6981 Error Err = ImportDeclContext(D, DC, LexicalDC);
6982 auto RequiresLoc = importChecked(Err, D->getLocation());
6983 if (Err)
6984 return std::move(Err);
6985
6987 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, RequiresLoc))
6988 return To;
6989 To->setLexicalDeclContext(LexicalDC);
6990 LexicalDC->addDeclInternal(To);
6991 return To;
6992}
6993
6996 DeclContext *DC, *LexicalDC;
6997 Error Err = ImportDeclContext(D, DC, LexicalDC);
6998 auto ToSL = importChecked(Err, D->getLocation());
6999 if (Err)
7000 return std::move(Err);
7001
7002 SmallVector<TemplateArgument, 2> ToArgs(D->getTemplateArguments().size());
7003 if (Error Err = ImportTemplateArguments(D->getTemplateArguments(), ToArgs))
7004 return std::move(Err);
7005
7007 if (GetImportedOrCreateDecl(To, D, Importer.getToContext(), DC, ToSL, ToArgs))
7008 return To;
7009 To->setLexicalDeclContext(LexicalDC);
7010 LexicalDC->addDeclInternal(To);
7011 return To;
7012}
7013
7014//----------------------------------------------------------------------------
7015// Import Statements
7016//----------------------------------------------------------------------------
7017
7019 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
7020 << S->getStmtClassName();
7021 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7022}
7023
7024
7026 if (Importer.returnWithErrorInTest())
7027 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7029 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7030 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
7031 // ToII is nullptr when no symbolic name is given for output operand
7032 // see ParseStmtAsm::ParseAsmOperandsOpt
7033 Names.push_back(ToII);
7034 }
7035
7036 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7037 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
7038 // ToII is nullptr when no symbolic name is given for input operand
7039 // see ParseStmtAsm::ParseAsmOperandsOpt
7040 Names.push_back(ToII);
7041 }
7042
7043 SmallVector<Expr *, 4> Clobbers;
7044 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
7045 if (auto ClobberOrErr = import(S->getClobberExpr(I)))
7046 Clobbers.push_back(*ClobberOrErr);
7047 else
7048 return ClobberOrErr.takeError();
7049
7050 }
7051
7052 SmallVector<Expr *, 4> Constraints;
7053 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
7054 if (auto OutputOrErr = import(S->getOutputConstraintExpr(I)))
7055 Constraints.push_back(*OutputOrErr);
7056 else
7057 return OutputOrErr.takeError();
7058 }
7059
7060 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
7061 if (auto InputOrErr = import(S->getInputConstraintExpr(I)))
7062 Constraints.push_back(*InputOrErr);
7063 else
7064 return InputOrErr.takeError();
7065 }
7066
7067 SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() +
7068 S->getNumLabels());
7069 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
7070 return std::move(Err);
7071
7072 if (Error Err =
7073 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
7074 return std::move(Err);
7075
7076 if (Error Err = ImportArrayChecked(
7077 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
7078 return std::move(Err);
7079
7080 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
7081 if (!AsmLocOrErr)
7082 return AsmLocOrErr.takeError();
7083 auto AsmStrOrErr = import(S->getAsmStringExpr());
7084 if (!AsmStrOrErr)
7085 return AsmStrOrErr.takeError();
7086 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
7087 if (!RParenLocOrErr)
7088 return RParenLocOrErr.takeError();
7089
7090 return new (Importer.getToContext()) GCCAsmStmt(
7091 Importer.getToContext(),
7092 *AsmLocOrErr,
7093 S->isSimple(),
7094 S->isVolatile(),
7095 S->getNumOutputs(),
7096 S->getNumInputs(),
7097 Names.data(),
7098 Constraints.data(),
7099 Exprs.data(),
7100 *AsmStrOrErr,
7101 S->getNumClobbers(),
7102 Clobbers.data(),
7103 S->getNumLabels(),
7104 *RParenLocOrErr);
7105}
7106
7108
7109 Error Err = Error::success();
7110 auto ToDG = importChecked(Err, S->getDeclGroup());
7111 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
7112 auto ToEndLoc = importChecked(Err, S->getEndLoc());
7113 if (Err)
7114 return std::move(Err);
7115 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
7116}
7117
7119 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
7120 if (!ToSemiLocOrErr)
7121 return ToSemiLocOrErr.takeError();
7122 return new (Importer.getToContext()) NullStmt(
7123 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
7124}
7125
7127 SmallVector<Stmt *, 8> ToStmts(S->size());
7128
7129 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
7130 return std::move(Err);
7131
7132 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
7133 if (!ToLBracLocOrErr)
7134 return ToLBracLocOrErr.takeError();
7135
7136 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
7137 if (!ToRBracLocOrErr)
7138 return ToRBracLocOrErr.takeError();
7139
7140 FPOptionsOverride FPO =
7141 S->hasStoredFPFeatures() ? S->getStoredFPFeatures() : FPOptionsOverride();
7142 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
7143 *ToLBracLocOrErr, *ToRBracLocOrErr);
7144}
7145
7147
7148 Error Err = Error::success();
7149 auto ToLHS = importChecked(Err, S->getLHS());
7150 auto ToRHS = importChecked(Err, S->getRHS());
7151 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7152 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
7153 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
7154 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7155 if (Err)
7156 return std::move(Err);
7157
7158 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
7159 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
7160 ToStmt->setSubStmt(ToSubStmt);
7161
7162 return ToStmt;
7163}
7164
7166
7167 Error Err = Error::success();
7168 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
7169 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7170 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7171 if (Err)
7172 return std::move(Err);
7173
7174 return new (Importer.getToContext()) DefaultStmt(
7175 ToDefaultLoc, ToColonLoc, ToSubStmt);
7176}
7177
7179
7180 Error Err = Error::success();
7181 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
7182 auto ToLabelDecl = importChecked(Err, S->getDecl());
7183 auto ToSubStmt = importChecked(Err, S->getSubStmt());
7184 if (Err)
7185 return std::move(Err);
7186
7187 return new (Importer.getToContext()) LabelStmt(
7188 ToIdentLoc, ToLabelDecl, ToSubStmt);
7189}
7190
7192 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
7193 if (!ToAttrLocOrErr)
7194 return ToAttrLocOrErr.takeError();
7195 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
7196 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
7197 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
7198 return std::move(Err);
7199 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7200 if (!ToSubStmtOrErr)
7201 return ToSubStmtOrErr.takeError();
7202
7204 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
7205}
7206
7208
7209 Error Err = Error::success();
7210 auto ToIfLoc = importChecked(Err, S->getIfLoc());
7211 auto ToInit = importChecked(Err, S->getInit());
7212 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7213 auto ToCond = importChecked(Err, S->getCond());
7214 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7215 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7216 auto ToThen = importChecked(Err, S->getThen());
7217 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7218 auto ToElse = importChecked(Err, S->getElse());
7219 if (Err)
7220 return std::move(Err);
7221
7222 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7223 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7224 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7225}
7226
7228
7229 Error Err = Error::success();
7230 auto ToInit = importChecked(Err, S->getInit());
7231 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7232 auto ToCond = importChecked(Err, S->getCond());
7233 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7234 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7235 auto ToBody = importChecked(Err, S->getBody());
7236 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7237 if (Err)
7238 return std::move(Err);
7239
7240 auto *ToStmt =
7241 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7242 ToCond, ToLParenLoc, ToRParenLoc);
7243 ToStmt->setBody(ToBody);
7244 ToStmt->setSwitchLoc(ToSwitchLoc);
7245
7246 // Now we have to re-chain the cases.
7247 SwitchCase *LastChainedSwitchCase = nullptr;
7248 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7249 SC = SC->getNextSwitchCase()) {
7250 Expected<SwitchCase *> ToSCOrErr = import(SC);
7251 if (!ToSCOrErr)
7252 return ToSCOrErr.takeError();
7253 if (LastChainedSwitchCase)
7254 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7255 else
7256 ToStmt->setSwitchCaseList(*ToSCOrErr);
7257 LastChainedSwitchCase = *ToSCOrErr;
7258 }
7259
7260 return ToStmt;
7261}
7262
7264
7265 Error Err = Error::success();
7266 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7267 auto ToCond = importChecked(Err, S->getCond());
7268 auto ToBody = importChecked(Err, S->getBody());
7269 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7270 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7271 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7272 if (Err)
7273 return std::move(Err);
7274
7275 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7276 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7277}
7278
7280
7281 Error Err = Error::success();
7282 auto ToBody = importChecked(Err, S->getBody());
7283 auto ToCond = importChecked(Err, S->getCond());
7284 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7285 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7286 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7287 if (Err)
7288 return std::move(Err);
7289
7290 return new (Importer.getToContext()) DoStmt(
7291 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7292}
7293
7295
7296 Error Err = Error::success();
7297 auto ToInit = importChecked(Err, S->getInit());
7298 auto ToCond = importChecked(Err, S->getCond());
7299 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7300 auto ToInc = importChecked(Err, S->getInc());
7301 auto ToBody = importChecked(Err, S->getBody());
7302 auto ToForLoc = importChecked(Err, S->getForLoc());
7303 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7304 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7305 if (Err)
7306 return std::move(Err);
7307
7308 return new (Importer.getToContext()) ForStmt(
7309 Importer.getToContext(),
7310 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7311 ToRParenLoc);
7312}
7313
7315
7316 Error Err = Error::success();
7317 auto ToLabel = importChecked(Err, S->getLabel());
7318 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7319 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7320 if (Err)
7321 return std::move(Err);
7322
7323 return new (Importer.getToContext()) GotoStmt(
7324 ToLabel, ToGotoLoc, ToLabelLoc);
7325}
7326
7328
7329 Error Err = Error::success();
7330 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7331 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7332 auto ToTarget = importChecked(Err, S->getTarget());
7333 if (Err)
7334 return std::move(Err);
7335
7336 return new (Importer.getToContext()) IndirectGotoStmt(
7337 ToGotoLoc, ToStarLoc, ToTarget);
7338}
7339
7340template <typename StmtClass>
7342 ASTImporter &Importer, StmtClass *S) {
7343 Error Err = Error::success();
7344 auto ToLoc = NodeImporter.importChecked(Err, S->getKwLoc());
7345 auto ToLabelLoc = S->hasLabelTarget()
7346 ? NodeImporter.importChecked(Err, S->getLabelLoc())
7347 : SourceLocation();
7348 auto ToDecl = S->hasLabelTarget()
7349 ? NodeImporter.importChecked(Err, S->getLabelDecl())
7350 : nullptr;
7351 if (Err)
7352 return std::move(Err);
7353 return new (Importer.getToContext()) StmtClass(ToLoc, ToLabelLoc, ToDecl);
7354}
7355
7357 return ImportLoopControlStmt(*this, Importer, S);
7358}
7359
7361 return ImportLoopControlStmt(*this, Importer, S);
7362}
7363
7365
7366 Error Err = Error::success();
7367 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7368 auto ToRetValue = importChecked(Err, S->getRetValue());
7369 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7370 if (Err)
7371 return std::move(Err);
7372
7373 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7374 ToNRVOCandidate);
7375}
7376
7378
7379 Error Err = Error::success();
7380 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7381 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7382 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7383 if (Err)
7384 return std::move(Err);
7385
7386 return new (Importer.getToContext()) CXXCatchStmt (
7387 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7388}
7389
7391 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7392 if (!ToTryLocOrErr)
7393 return ToTryLocOrErr.takeError();
7394
7395 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7396 if (!ToTryBlockOrErr)
7397 return ToTryBlockOrErr.takeError();
7398
7399 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7400 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7401 CXXCatchStmt *FromHandler = S->getHandler(HI);
7402 if (auto ToHandlerOrErr = import(FromHandler))
7403 ToHandlers[HI] = *ToHandlerOrErr;
7404 else
7405 return ToHandlerOrErr.takeError();
7406 }
7407
7408 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7409 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7410}
7411
7413
7414 Error Err = Error::success();
7415 auto ToInit = importChecked(Err, S->getInit());
7416 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7417 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7418 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7419 auto ToCond = importChecked(Err, S->getCond());
7420 auto ToInc = importChecked(Err, S->getInc());
7421 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7422 auto ToBody = importChecked(Err, S->getBody());
7423 auto ToForLoc = importChecked(Err, S->getForLoc());
7424 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7425 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7426 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7427 if (Err)
7428 return std::move(Err);
7429
7430 return new (Importer.getToContext()) CXXForRangeStmt(
7431 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7432 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7433}
7434
7437 Error Err = Error::success();
7438 auto ToElement = importChecked(Err, S->getElement());
7439 auto ToCollection = importChecked(Err, S->getCollection());
7440 auto ToBody = importChecked(Err, S->getBody());
7441 auto ToForLoc = importChecked(Err, S->getForLoc());
7442 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7443 if (Err)
7444 return std::move(Err);
7445
7446 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7447 ToCollection,
7448 ToBody,
7449 ToForLoc,
7450 ToRParenLoc);
7451}
7452
7454
7455 Error Err = Error::success();
7456 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7457 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7458 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7459 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7460 if (Err)
7461 return std::move(Err);
7462
7463 return new (Importer.getToContext()) ObjCAtCatchStmt (
7464 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7465}
7466
7468 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7469 if (!ToAtFinallyLocOrErr)
7470 return ToAtFinallyLocOrErr.takeError();
7471 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7472 if (!ToAtFinallyStmtOrErr)
7473 return ToAtFinallyStmtOrErr.takeError();
7474 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7475 *ToAtFinallyStmtOrErr);
7476}
7477
7479
7480 Error Err = Error::success();
7481 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7482 auto ToTryBody = importChecked(Err, S->getTryBody());
7483 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7484 if (Err)
7485 return std::move(Err);
7486
7487 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7488 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7489 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7490 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7491 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7492 else
7493 return ToCatchStmtOrErr.takeError();
7494 }
7495
7496 return ObjCAtTryStmt::Create(Importer.getToContext(),
7497 ToAtTryLoc, ToTryBody,
7498 ToCatchStmts.begin(), ToCatchStmts.size(),
7499 ToFinallyStmt);
7500}
7501
7504
7505 Error Err = Error::success();
7506 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7507 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7508 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7509 if (Err)
7510 return std::move(Err);
7511
7512 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7513 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7514}
7515
7517 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7518 if (!ToThrowLocOrErr)
7519 return ToThrowLocOrErr.takeError();
7520 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7521 if (!ToThrowExprOrErr)
7522 return ToThrowExprOrErr.takeError();
7523 return new (Importer.getToContext()) ObjCAtThrowStmt(
7524 *ToThrowLocOrErr, *ToThrowExprOrErr);
7525}
7526
7529 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7530 if (!ToAtLocOrErr)
7531 return ToAtLocOrErr.takeError();
7532 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7533 if (!ToSubStmtOrErr)
7534 return ToSubStmtOrErr.takeError();
7535 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7536 *ToSubStmtOrErr);
7537}
7538
7539//----------------------------------------------------------------------------
7540// Import Expressions
7541//----------------------------------------------------------------------------
7543 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7544 << E->getStmtClassName();
7545 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7546}
7547
7549 Error Err = Error::success();
7550 auto ToType = importChecked(Err, E->getType());
7551 auto BLoc = importChecked(Err, E->getBeginLoc());
7552 auto RParenLoc = importChecked(Err, E->getEndLoc());
7553 if (Err)
7554 return std::move(Err);
7555 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7556 if (!ParentContextOrErr)
7557 return ParentContextOrErr.takeError();
7558
7559 return new (Importer.getToContext())
7560 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7561 RParenLoc, *ParentContextOrErr);
7562}
7563
7565
7566 Error Err = Error::success();
7567 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7568 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7569 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7570 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7571 auto ToType = importChecked(Err, E->getType());
7572 if (Err)
7573 return std::move(Err);
7574
7575 return new (Importer.getToContext()) VAArgExpr(
7576 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7577 E->isMicrosoftABI());
7578}
7579
7581
7582 Error Err = Error::success();
7583 auto ToCond = importChecked(Err, E->getCond());
7584 auto ToLHS = importChecked(Err, E->getLHS());
7585 auto ToRHS = importChecked(Err, E->getRHS());
7586 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7587 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7588 auto ToType = importChecked(Err, E->getType());
7589 if (Err)
7590 return std::move(Err);
7591
7594
7595 // The value of CondIsTrue only matters if the value is not
7596 // condition-dependent.
7597 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7598
7599 return new (Importer.getToContext())
7600 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7601 ToRParenLoc, CondIsTrue);
7602}
7603
7605 Error Err = Error::success();
7606 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7607 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7608 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7609 auto ToType = importChecked(Err, E->getType());
7610 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7611 if (Err)
7612 return std::move(Err);
7613
7615 Importer.getToContext(), ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7616 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc,
7617 E->getStoredFPFeaturesOrDefault());
7618}
7619
7621 Error Err = Error::success();
7622 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7623 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7624 auto ToType = importChecked(Err, E->getType());
7625 const unsigned NumSubExprs = E->getNumSubExprs();
7626
7628 ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7629 ToSubExprs.resize(NumSubExprs);
7630
7631 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7632 return std::move(Err);
7633
7634 return new (Importer.getToContext()) ShuffleVectorExpr(
7635 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7636}
7637
7639 ExpectedType TypeOrErr = import(E->getType());
7640 if (!TypeOrErr)
7641 return TypeOrErr.takeError();
7642
7643 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7644 if (!BeginLocOrErr)
7645 return BeginLocOrErr.takeError();
7646
7647 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7648}
7649
7652 Error Err = Error::success();
7653 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7654 Expr *ToControllingExpr = nullptr;
7655 TypeSourceInfo *ToControllingType = nullptr;
7656 if (E->isExprPredicate())
7657 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7658 else
7659 ToControllingType = importChecked(Err, E->getControllingType());
7660 assert((ToControllingExpr || ToControllingType) &&
7661 "Either the controlling expr or type must be nonnull");
7662 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7663 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7664 if (Err)
7665 return std::move(Err);
7666
7667 ArrayRef<const TypeSourceInfo *> FromAssocTypes(E->getAssocTypeSourceInfos());
7668 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7669 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7670 return std::move(Err);
7671
7672 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7673 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7674 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7675 return std::move(Err);
7676
7677 const ASTContext &ToCtx = Importer.getToContext();
7678 if (E->isResultDependent()) {
7679 if (ToControllingExpr) {
7681 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7682 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7684 }
7686 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7687 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7689 }
7690
7691 if (ToControllingExpr) {
7693 ToCtx, ToGenericLoc, ToControllingExpr, ArrayRef(ToAssocTypes),
7694 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7695 E->containsUnexpandedParameterPack(), E->getResultIndex());
7696 }
7698 ToCtx, ToGenericLoc, ToControllingType, ArrayRef(ToAssocTypes),
7699 ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7700 E->containsUnexpandedParameterPack(), E->getResultIndex());
7701}
7702
7704
7705 Error Err = Error::success();
7706 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7707 auto ToType = importChecked(Err, E->getType());
7708 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7709 if (Err)
7710 return std::move(Err);
7711
7712 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7713 E->getIdentKind(), E->isTransparent(),
7714 ToFunctionName);
7715}
7716
7718
7719 Error Err = Error::success();
7720 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7721 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7722 auto ToDecl = importChecked(Err, E->getDecl());
7723 auto ToLocation = importChecked(Err, E->getLocation());
7724 auto ToType = importChecked(Err, E->getType());
7725 if (Err)
7726 return std::move(Err);
7727
7728 NamedDecl *ToFoundD = nullptr;
7729 if (E->getDecl() != E->getFoundDecl()) {
7730 auto FoundDOrErr = import(E->getFoundDecl());
7731 if (!FoundDOrErr)
7732 return FoundDOrErr.takeError();
7733 ToFoundD = *FoundDOrErr;
7734 }
7735
7736 TemplateArgumentListInfo ToTAInfo;
7737 TemplateArgumentListInfo *ToResInfo = nullptr;
7738 if (E->hasExplicitTemplateArgs()) {
7739 if (Error Err =
7740 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
7741 E->template_arguments(), ToTAInfo))
7742 return std::move(Err);
7743 ToResInfo = &ToTAInfo;
7744 }
7745
7746 auto *ToE = DeclRefExpr::Create(
7747 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7748 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7749 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7750 if (E->hadMultipleCandidates())
7751 ToE->setHadMultipleCandidates(true);
7752 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7753 return ToE;
7754}
7755
7757 ExpectedType TypeOrErr = import(E->getType());
7758 if (!TypeOrErr)
7759 return TypeOrErr.takeError();
7760
7761 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7762}
7763
7765 ExpectedExpr ToInitOrErr = import(E->getInit());
7766 if (!ToInitOrErr)
7767 return ToInitOrErr.takeError();
7768
7769 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7770 if (!ToEqualOrColonLocOrErr)
7771 return ToEqualOrColonLocOrErr.takeError();
7772
7773 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7774 // List elements from the second, the first is Init itself
7775 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7776 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7777 ToIndexExprs[I - 1] = *ToArgOrErr;
7778 else
7779 return ToArgOrErr.takeError();
7780 }
7781
7782 SmallVector<Designator, 4> ToDesignators(E->size());
7783 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7784 return std::move(Err);
7785
7787 Importer.getToContext(), ToDesignators,
7788 ToIndexExprs, *ToEqualOrColonLocOrErr,
7789 E->usesGNUSyntax(), *ToInitOrErr);
7790}
7791
7794 ExpectedType ToTypeOrErr = import(E->getType());
7795 if (!ToTypeOrErr)
7796 return ToTypeOrErr.takeError();
7797
7798 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7799 if (!ToLocationOrErr)
7800 return ToLocationOrErr.takeError();
7801
7802 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7803 *ToTypeOrErr, *ToLocationOrErr);
7804}
7805
7807 ExpectedType ToTypeOrErr = import(E->getType());
7808 if (!ToTypeOrErr)
7809 return ToTypeOrErr.takeError();
7810
7811 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7812 if (!ToLocationOrErr)
7813 return ToLocationOrErr.takeError();
7814
7816 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7817}
7818
7819
7821 ExpectedType ToTypeOrErr = import(E->getType());
7822 if (!ToTypeOrErr)
7823 return ToTypeOrErr.takeError();
7824
7825 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7826 if (!ToLocationOrErr)
7827 return ToLocationOrErr.takeError();
7828
7830 Importer.getToContext(), E->getValue(), E->isExact(),
7831 *ToTypeOrErr, *ToLocationOrErr);
7832}
7833
7835 auto ToTypeOrErr = import(E->getType());
7836 if (!ToTypeOrErr)
7837 return ToTypeOrErr.takeError();
7838
7839 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7840 if (!ToSubExprOrErr)
7841 return ToSubExprOrErr.takeError();
7842
7843 return new (Importer.getToContext()) ImaginaryLiteral(
7844 *ToSubExprOrErr, *ToTypeOrErr);
7845}
7846
7848 auto ToTypeOrErr = import(E->getType());
7849 if (!ToTypeOrErr)
7850 return ToTypeOrErr.takeError();
7851
7852 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7853 if (!ToLocationOrErr)
7854 return ToLocationOrErr.takeError();
7855
7856 return new (Importer.getToContext()) FixedPointLiteral(
7857 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7858 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7859}
7860
7862 ExpectedType ToTypeOrErr = import(E->getType());
7863 if (!ToTypeOrErr)
7864 return ToTypeOrErr.takeError();
7865
7866 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7867 if (!ToLocationOrErr)
7868 return ToLocationOrErr.takeError();
7869
7870 return new (Importer.getToContext()) CharacterLiteral(
7871 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7872}
7873
7875 ExpectedType ToTypeOrErr = import(E->getType());
7876 if (!ToTypeOrErr)
7877 return ToTypeOrErr.takeError();
7878
7879 SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated());
7880 if (Error Err = ImportArrayChecked(
7881 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7882 return std::move(Err);
7883
7884 return StringLiteral::Create(Importer.getToContext(), E->getBytes(),
7885 E->getKind(), E->isPascal(), *ToTypeOrErr,
7886 ToLocations);
7887}
7888
7890
7891 Error Err = Error::success();
7892 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7893 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7894 auto ToType = importChecked(Err, E->getType());
7895 auto ToInitializer = importChecked(Err, E->getInitializer());
7896 if (Err)
7897 return std::move(Err);
7898
7899 return new (Importer.getToContext()) CompoundLiteralExpr(
7900 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7901 ToInitializer, E->isFileScope());
7902}
7903
7905
7906 Error Err = Error::success();
7907 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7908 auto ToType = importChecked(Err, E->getType());
7909 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7910 if (Err)
7911 return std::move(Err);
7912
7913 SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs());
7914 if (Error Err = ImportArrayChecked(
7915 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7916 ToExprs.begin()))
7917 return std::move(Err);
7918
7919 return new (Importer.getToContext()) AtomicExpr(
7920
7921 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7922}
7923
7925 Error Err = Error::success();
7926 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7927 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7928 auto ToLabel = importChecked(Err, E->getLabel());
7929 auto ToType = importChecked(Err, E->getType());
7930 if (Err)
7931 return std::move(Err);
7932
7933 return new (Importer.getToContext()) AddrLabelExpr(
7934 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7935}
7937 Error Err = Error::success();
7938 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7939 auto ToResult = importChecked(Err, E->getAPValueResult());
7940 if (Err)
7941 return std::move(Err);
7942
7943 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7944}
7946 Error Err = Error::success();
7947 auto ToLParen = importChecked(Err, E->getLParen());
7948 auto ToRParen = importChecked(Err, E->getRParen());
7949 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7950 if (Err)
7951 return std::move(Err);
7952
7953 return new (Importer.getToContext())
7954 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7955}
7956
7958 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7959 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7960 return std::move(Err);
7961
7962 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7963 if (!ToLParenLocOrErr)
7964 return ToLParenLocOrErr.takeError();
7965
7966 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7967 if (!ToRParenLocOrErr)
7968 return ToRParenLocOrErr.takeError();
7969
7970 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7971 ToExprs, *ToRParenLocOrErr);
7972}
7973
7975 Error Err = Error::success();
7976 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7977 auto ToType = importChecked(Err, E->getType());
7978 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7979 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7980 if (Err)
7981 return std::move(Err);
7982
7983 return new (Importer.getToContext())
7984 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7985 E->getTemplateDepth());
7986}
7987
7989 Error Err = Error::success();
7990 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7991 auto ToType = importChecked(Err, E->getType());
7992 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7993 if (Err)
7994 return std::move(Err);
7995
7996 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7997 E->hasStoredFPFeatures());
7998 UO->setType(ToType);
7999 UO->setSubExpr(ToSubExpr);
8000 UO->setOpcode(E->getOpcode());
8001 UO->setOperatorLoc(ToOperatorLoc);
8002 UO->setCanOverflow(E->canOverflow());
8003 if (E->hasStoredFPFeatures())
8004 UO->setStoredFPFeatures(E->getStoredFPFeatures());
8005
8006 return UO;
8007}
8008
8010
8012 Error Err = Error::success();
8013 auto ToType = importChecked(Err, E->getType());
8014 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8015 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8016 if (Err)
8017 return std::move(Err);
8018
8019 if (E->isArgumentType()) {
8020 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
8021 import(E->getArgumentTypeInfo());
8022 if (!ToArgumentTypeInfoOrErr)
8023 return ToArgumentTypeInfoOrErr.takeError();
8024
8025 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8026 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
8027 ToRParenLoc);
8028 }
8029
8030 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
8031 if (!ToArgumentExprOrErr)
8032 return ToArgumentExprOrErr.takeError();
8033
8034 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
8035 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
8036}
8037
8039 Error Err = Error::success();
8040 auto ToLHS = importChecked(Err, E->getLHS());
8041 auto ToRHS = importChecked(Err, E->getRHS());
8042 auto ToType = importChecked(Err, E->getType());
8043 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8044 if (Err)
8045 return std::move(Err);
8046
8048 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8049 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8050 E->getFPFeatures());
8051}
8052
8054 Error Err = Error::success();
8055 auto ToCond = importChecked(Err, E->getCond());
8056 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8057 auto ToLHS = importChecked(Err, E->getLHS());
8058 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8059 auto ToRHS = importChecked(Err, E->getRHS());
8060 auto ToType = importChecked(Err, E->getType());
8061 if (Err)
8062 return std::move(Err);
8063
8064 return new (Importer.getToContext()) ConditionalOperator(
8065 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
8066 E->getValueKind(), E->getObjectKind());
8067}
8068
8071 Error Err = Error::success();
8072 auto ToCommon = importChecked(Err, E->getCommon());
8073 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
8074 auto ToCond = importChecked(Err, E->getCond());
8075 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
8076 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
8077 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
8078 auto ToColonLoc = importChecked(Err, E->getColonLoc());
8079 auto ToType = importChecked(Err, E->getType());
8080 if (Err)
8081 return std::move(Err);
8082
8083 return new (Importer.getToContext()) BinaryConditionalOperator(
8084 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
8085 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
8086 E->getObjectKind());
8087}
8088
8091 Error Err = Error::success();
8092 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
8093 if (Err)
8094 return std::move(Err);
8095
8096 return new (Importer.getToContext())
8097 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
8098}
8099
8101 Error Err = Error::success();
8102 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8103 auto ToQueriedTypeSourceInfo =
8104 importChecked(Err, E->getQueriedTypeSourceInfo());
8105 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
8106 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8107 auto ToType = importChecked(Err, E->getType());
8108 if (Err)
8109 return std::move(Err);
8110
8111 return new (Importer.getToContext()) ArrayTypeTraitExpr(
8112 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
8113 ToDimensionExpression, ToEndLoc, ToType);
8114}
8115
8117 Error Err = Error::success();
8118 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8119 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
8120 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8121 auto ToType = importChecked(Err, E->getType());
8122 if (Err)
8123 return std::move(Err);
8124
8125 return new (Importer.getToContext()) ExpressionTraitExpr(
8126 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
8127 ToEndLoc, ToType);
8128}
8129
8131 Error Err = Error::success();
8132 auto ToLocation = importChecked(Err, E->getLocation());
8133 auto ToType = importChecked(Err, E->getType());
8134 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
8135 if (Err)
8136 return std::move(Err);
8137
8138 return new (Importer.getToContext()) OpaqueValueExpr(
8139 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
8140}
8141
8143 Error Err = Error::success();
8144 auto ToLHS = importChecked(Err, E->getLHS());
8145 auto ToRHS = importChecked(Err, E->getRHS());
8146 auto ToType = importChecked(Err, E->getType());
8147 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
8148 if (Err)
8149 return std::move(Err);
8150
8151 return new (Importer.getToContext()) ArraySubscriptExpr(
8152 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
8153 ToRBracketLoc);
8154}
8155
8158 Error Err = Error::success();
8159 auto ToLHS = importChecked(Err, E->getLHS());
8160 auto ToRHS = importChecked(Err, E->getRHS());
8161 auto ToType = importChecked(Err, E->getType());
8162 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
8163 auto ToComputationResultType =
8164 importChecked(Err, E->getComputationResultType());
8165 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8166 if (Err)
8167 return std::move(Err);
8168
8170 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
8171 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
8172 E->getFPFeatures(),
8173 ToComputationLHSType, ToComputationResultType);
8174}
8175
8179 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
8180 if (auto SpecOrErr = import(*I))
8181 Path.push_back(*SpecOrErr);
8182 else
8183 return SpecOrErr.takeError();
8184 }
8185 return Path;
8186}
8187
8189 ExpectedType ToTypeOrErr = import(E->getType());
8190 if (!ToTypeOrErr)
8191 return ToTypeOrErr.takeError();
8192
8193 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8194 if (!ToSubExprOrErr)
8195 return ToSubExprOrErr.takeError();
8196
8197 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8198 if (!ToBasePathOrErr)
8199 return ToBasePathOrErr.takeError();
8200
8202 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
8203 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
8204}
8205
8207 Error Err = Error::success();
8208 auto ToType = importChecked(Err, E->getType());
8209 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8210 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8211 if (Err)
8212 return std::move(Err);
8213
8214 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
8215 if (!ToBasePathOrErr)
8216 return ToBasePathOrErr.takeError();
8217 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
8218
8219 switch (E->getStmtClass()) {
8220 case Stmt::CStyleCastExprClass: {
8221 auto *CCE = cast<CStyleCastExpr>(E);
8222 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
8223 if (!ToLParenLocOrErr)
8224 return ToLParenLocOrErr.takeError();
8225 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8226 if (!ToRParenLocOrErr)
8227 return ToRParenLocOrErr.takeError();
8229 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8230 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8231 *ToLParenLocOrErr, *ToRParenLocOrErr);
8232 }
8233
8234 case Stmt::CXXFunctionalCastExprClass: {
8235 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8236 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8237 if (!ToLParenLocOrErr)
8238 return ToLParenLocOrErr.takeError();
8239 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8240 if (!ToRParenLocOrErr)
8241 return ToRParenLocOrErr.takeError();
8243 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8244 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8245 *ToLParenLocOrErr, *ToRParenLocOrErr);
8246 }
8247
8248 case Stmt::ObjCBridgedCastExprClass: {
8249 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8250 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8251 if (!ToLParenLocOrErr)
8252 return ToLParenLocOrErr.takeError();
8253 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8254 if (!ToBridgeKeywordLocOrErr)
8255 return ToBridgeKeywordLocOrErr.takeError();
8256 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8257 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8258 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8259 }
8260 case Stmt::BuiltinBitCastExprClass: {
8261 auto *BBC = cast<BuiltinBitCastExpr>(E);
8262 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8263 if (!ToKWLocOrErr)
8264 return ToKWLocOrErr.takeError();
8265 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8266 if (!ToRParenLocOrErr)
8267 return ToRParenLocOrErr.takeError();
8268 return new (Importer.getToContext()) BuiltinBitCastExpr(
8269 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8270 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8271 }
8272 default:
8273 llvm_unreachable("Cast expression of unsupported type!");
8274 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8275 }
8276}
8277
8280 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8281 const OffsetOfNode &FromNode = E->getComponent(I);
8282
8283 SourceLocation ToBeginLoc, ToEndLoc;
8284
8285 if (FromNode.getKind() != OffsetOfNode::Base) {
8286 Error Err = Error::success();
8287 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8288 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8289 if (Err)
8290 return std::move(Err);
8291 }
8292
8293 switch (FromNode.getKind()) {
8295 ToNodes.push_back(
8296 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8297 break;
8298 case OffsetOfNode::Base: {
8299 auto ToBSOrErr = import(FromNode.getBase());
8300 if (!ToBSOrErr)
8301 return ToBSOrErr.takeError();
8302 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8303 break;
8304 }
8305 case OffsetOfNode::Field: {
8306 auto ToFieldOrErr = import(FromNode.getField());
8307 if (!ToFieldOrErr)
8308 return ToFieldOrErr.takeError();
8309 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8310 break;
8311 }
8313 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8314 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8315 break;
8316 }
8317 }
8318 }
8319
8320 SmallVector<Expr *, 4> ToExprs(E->getNumExpressions());
8321 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8322 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8323 if (!ToIndexExprOrErr)
8324 return ToIndexExprOrErr.takeError();
8325 ToExprs[I] = *ToIndexExprOrErr;
8326 }
8327
8328 Error Err = Error::success();
8329 auto ToType = importChecked(Err, E->getType());
8330 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8331 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8332 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8333 if (Err)
8334 return std::move(Err);
8335
8336 return OffsetOfExpr::Create(
8337 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8338 ToExprs, ToRParenLoc);
8339}
8340
8342 Error Err = Error::success();
8343 auto ToType = importChecked(Err, E->getType());
8344 auto ToOperand = importChecked(Err, E->getOperand());
8345 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8346 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8347 if (Err)
8348 return std::move(Err);
8349
8350 CanThrowResult ToCanThrow;
8351 if (E->isValueDependent())
8352 ToCanThrow = CT_Dependent;
8353 else
8354 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8355
8356 return new (Importer.getToContext()) CXXNoexceptExpr(
8357 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8358}
8359
8361 Error Err = Error::success();
8362 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8363 auto ToType = importChecked(Err, E->getType());
8364 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8365 if (Err)
8366 return std::move(Err);
8367
8368 return new (Importer.getToContext()) CXXThrowExpr(
8369 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8370}
8371
8373 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8374 if (!ToUsedLocOrErr)
8375 return ToUsedLocOrErr.takeError();
8376
8377 auto ToParamOrErr = import(E->getParam());
8378 if (!ToParamOrErr)
8379 return ToParamOrErr.takeError();
8380
8381 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8382 if (!UsedContextOrErr)
8383 return UsedContextOrErr.takeError();
8384
8385 // Import the default arg if it was not imported yet.
8386 // This is needed because it can happen that during the import of the
8387 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8388 // encountered here. The default argument for a ParmVarDecl is set in the
8389 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8390 // see VisitParmVarDecl).
8391 ParmVarDecl *ToParam = *ToParamOrErr;
8392 if (!ToParam->getDefaultArg()) {
8393 std::optional<ParmVarDecl *> FromParam =
8394 Importer.getImportedFromDecl(ToParam);
8395 assert(FromParam && "ParmVarDecl was not imported?");
8396
8397 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8398 return std::move(Err);
8399 }
8400 Expr *RewrittenInit = nullptr;
8401 if (E->hasRewrittenInit()) {
8402 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8403 if (!ExprOrErr)
8404 return ExprOrErr.takeError();
8405 RewrittenInit = ExprOrErr.get();
8406 }
8407 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8408 *ToParamOrErr, RewrittenInit,
8409 *UsedContextOrErr);
8410}
8411
8414 Error Err = Error::success();
8415 auto ToType = importChecked(Err, E->getType());
8416 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8417 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8418 if (Err)
8419 return std::move(Err);
8420
8421 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8422 ToType, ToTypeSourceInfo, ToRParenLoc);
8423}
8424
8427 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8428 if (!ToSubExprOrErr)
8429 return ToSubExprOrErr.takeError();
8430
8431 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8432 if (!ToDtorOrErr)
8433 return ToDtorOrErr.takeError();
8434
8435 ASTContext &ToCtx = Importer.getToContext();
8436 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8437 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8438}
8439
8441
8443 Error Err = Error::success();
8444 auto ToConstructor = importChecked(Err, E->getConstructor());
8445 auto ToType = importChecked(Err, E->getType());
8446 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8447 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8448 if (Err)
8449 return std::move(Err);
8450
8451 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8452 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8453 return std::move(Err);
8454
8456 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8457 ToParenOrBraceRange, E->hadMultipleCandidates(),
8458 E->isListInitialization(), E->isStdInitListInitialization(),
8459 E->requiresZeroInitialization());
8460}
8461
8464 DeclContext *DC, *LexicalDC;
8465 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8466 return std::move(Err);
8467
8468 Error Err = Error::success();
8469 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8470 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8471 if (Err)
8472 return std::move(Err);
8473 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8474
8476 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8477 D->getManglingNumber()))
8478 return To;
8479
8480 To->setLexicalDeclContext(LexicalDC);
8481 LexicalDC->addDeclInternal(To);
8482 return To;
8483}
8484
8487 Error Err = Error::success();
8488 auto ToType = importChecked(Err, E->getType());
8489 Expr *ToTemporaryExpr = importChecked(
8490 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8491 auto ToMaterializedDecl =
8492 importChecked(Err, E->getLifetimeExtendedTemporaryDecl());
8493 if (Err)
8494 return std::move(Err);
8495
8496 if (!ToTemporaryExpr)
8497 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8498
8499 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8500 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8501 ToMaterializedDecl);
8502
8503 return ToMTE;
8504}
8505
8507 Error Err = Error::success();
8508 auto *ToPattern = importChecked(Err, E->getPattern());
8509 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8510 if (Err)
8511 return std::move(Err);
8512
8513 return new (Importer.getToContext())
8514 PackExpansionExpr(ToPattern, ToEllipsisLoc, E->getNumExpansions());
8515}
8516
8518 Error Err = Error::success();
8519 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8520 auto ToPack = importChecked(Err, E->getPack());
8521 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8522 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8523 if (Err)
8524 return std::move(Err);
8525
8526 UnsignedOrNone Length = std::nullopt;
8527 if (!E->isValueDependent())
8528 Length = E->getPackLength();
8529
8530 SmallVector<TemplateArgument, 8> ToPartialArguments;
8531 if (E->isPartiallySubstituted()) {
8532 if (Error Err = ImportTemplateArguments(E->getPartialArguments(),
8533 ToPartialArguments))
8534 return std::move(Err);
8535 }
8536
8538 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8539 Length, ToPartialArguments);
8540}
8541
8542
8544 Error Err = Error::success();
8545 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8546 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8547 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8548 auto ToArraySize = importChecked(Err, E->getArraySize());
8549 auto ToInitializer = importChecked(Err, E->getInitializer());
8550 auto ToType = importChecked(Err, E->getType());
8551 auto ToAllocatedTypeSourceInfo =
8552 importChecked(Err, E->getAllocatedTypeSourceInfo());
8553 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8554 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8555 if (Err)
8556 return std::move(Err);
8557
8558 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8559 if (Error Err =
8560 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8561 return std::move(Err);
8562
8563 return CXXNewExpr::Create(
8564 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8565 ToOperatorDelete, E->implicitAllocationParameters(),
8566 E->doesUsualArrayDeleteWantSize(), ToPlacementArgs, ToTypeIdParens,
8567 ToArraySize, E->getInitializationStyle(), ToInitializer, ToType,
8568 ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange);
8569}
8570
8572 Error Err = Error::success();
8573 auto ToType = importChecked(Err, E->getType());
8574 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8575 auto ToArgument = importChecked(Err, E->getArgument());
8576 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8577 if (Err)
8578 return std::move(Err);
8579
8580 return new (Importer.getToContext()) CXXDeleteExpr(
8581 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8582 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8583 ToBeginLoc);
8584}
8585
8587 Error Err = Error::success();
8588 auto ToType = importChecked(Err, E->getType());
8589 auto ToLocation = importChecked(Err, E->getLocation());
8590 auto ToConstructor = importChecked(Err, E->getConstructor());
8591 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8592 if (Err)
8593 return std::move(Err);
8594
8595 SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
8596 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8597 return std::move(Err);
8598
8600 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8601 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8602 E->isListInitialization(), E->isStdInitListInitialization(),
8603 E->requiresZeroInitialization(), E->getConstructionKind(),
8604 ToParenOrBraceRange);
8605 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
8606 return ToE;
8607}
8608
8610 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8611 if (!ToSubExprOrErr)
8612 return ToSubExprOrErr.takeError();
8613
8614 SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects());
8615 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8616 return std::move(Err);
8617
8619 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8620 ToObjects);
8621}
8622
8624 Error Err = Error::success();
8625 auto ToCallee = importChecked(Err, E->getCallee());
8626 auto ToType = importChecked(Err, E->getType());
8627 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8628 if (Err)
8629 return std::move(Err);
8630
8631 SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
8632 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8633 return std::move(Err);
8634
8635 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8636 ToType, E->getValueKind(), ToRParenLoc,
8637 E->getFPFeatures());
8638}
8639
8641 ExpectedType ToTypeOrErr = import(E->getType());
8642 if (!ToTypeOrErr)
8643 return ToTypeOrErr.takeError();
8644
8645 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8646 if (!ToLocationOrErr)
8647 return ToLocationOrErr.takeError();
8648
8649 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8650 *ToTypeOrErr, E->isImplicit());
8651}
8652
8654 ExpectedType ToTypeOrErr = import(E->getType());
8655 if (!ToTypeOrErr)
8656 return ToTypeOrErr.takeError();
8657
8658 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8659 if (!ToLocationOrErr)
8660 return ToLocationOrErr.takeError();
8661
8662 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8663 *ToTypeOrErr, *ToLocationOrErr);
8664}
8665
8667 Error Err = Error::success();
8668 auto ToBase = importChecked(Err, E->getBase());
8669 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8670 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8671 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8672 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8673 auto ToType = importChecked(Err, E->getType());
8674 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8675 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8676 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8677 if (Err)
8678 return std::move(Err);
8679
8680 DeclAccessPair ToFoundDecl =
8681 DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess());
8682
8683 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8684
8685 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8686 if (E->hasExplicitTemplateArgs()) {
8687 if (Error Err =
8688 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8689 E->template_arguments(), ToTAInfo))
8690 return std::move(Err);
8691 ResInfo = &ToTAInfo;
8692 }
8693
8694 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8695 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8696 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8697 ResInfo, ToType, E->getValueKind(),
8698 E->getObjectKind(), E->isNonOdrUse());
8699}
8700
8703 Error Err = Error::success();
8704 auto ToBase = importChecked(Err, E->getBase());
8705 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8706 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8707 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8708 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8709 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8710 if (Err)
8711 return std::move(Err);
8712
8714 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8715 const IdentifierInfo *ToII = Importer.Import(FromII);
8716 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8717 if (!ToDestroyedTypeLocOrErr)
8718 return ToDestroyedTypeLocOrErr.takeError();
8719 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8720 } else {
8721 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8722 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8723 else
8724 return ToTIOrErr.takeError();
8725 }
8726
8727 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8728 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8729 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8730}
8731
8734 Error Err = Error::success();
8735 auto ToType = importChecked(Err, E->getType());
8736 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8737 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8738 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8739 auto ToFirstQualifierFoundInScope =
8740 importChecked(Err, E->getFirstQualifierFoundInScope());
8741 if (Err)
8742 return std::move(Err);
8743
8744 Expr *ToBase = nullptr;
8745 if (!E->isImplicitAccess()) {
8746 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8747 ToBase = *ToBaseOrErr;
8748 else
8749 return ToBaseOrErr.takeError();
8750 }
8751
8752 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8753
8754 if (E->hasExplicitTemplateArgs()) {
8755 if (Error Err =
8756 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8757 E->template_arguments(), ToTAInfo))
8758 return std::move(Err);
8759 ResInfo = &ToTAInfo;
8760 }
8761 auto ToMember = importChecked(Err, E->getMember());
8762 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8763 if (Err)
8764 return std::move(Err);
8765 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8766
8767 // Import additional name location/type info.
8768 if (Error Err =
8769 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8770 return std::move(Err);
8771
8773 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8774 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8775 ToMemberNameInfo, ResInfo);
8776}
8777
8780 Error Err = Error::success();
8781 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8782 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8783 auto ToDeclName = importChecked(Err, E->getDeclName());
8784 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8785 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8786 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8787 if (Err)
8788 return std::move(Err);
8789
8790 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8791 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8792 return std::move(Err);
8793
8794 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8795 TemplateArgumentListInfo *ResInfo = nullptr;
8796 if (E->hasExplicitTemplateArgs()) {
8797 if (Error Err =
8798 ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
8799 return std::move(Err);
8800 ResInfo = &ToTAInfo;
8801 }
8802
8804 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8805 ToNameInfo, ResInfo);
8806}
8807
8810 Error Err = Error::success();
8811 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8812 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8813 auto ToType = importChecked(Err, E->getType());
8814 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8815 if (Err)
8816 return std::move(Err);
8817
8818 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8819 if (Error Err =
8820 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8821 return std::move(Err);
8822
8824 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8825 ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8826}
8827
8830 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8831 if (!ToNamingClassOrErr)
8832 return ToNamingClassOrErr.takeError();
8833
8834 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8835 if (!ToQualifierLocOrErr)
8836 return ToQualifierLocOrErr.takeError();
8837
8838 Error Err = Error::success();
8839 auto ToName = importChecked(Err, E->getName());
8840 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8841 if (Err)
8842 return std::move(Err);
8843 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8844
8845 // Import additional name location/type info.
8846 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8847 return std::move(Err);
8848
8849 UnresolvedSet<8> ToDecls;
8850 for (auto *D : E->decls())
8851 if (auto ToDOrErr = import(D))
8852 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8853 else
8854 return ToDOrErr.takeError();
8855
8856 if (E->hasExplicitTemplateArgs()) {
8857 TemplateArgumentListInfo ToTAInfo;
8858 if (Error Err = ImportTemplateArgumentListInfo(
8859 E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
8860 ToTAInfo))
8861 return std::move(Err);
8862
8863 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8864 if (!ToTemplateKeywordLocOrErr)
8865 return ToTemplateKeywordLocOrErr.takeError();
8866
8867 const bool KnownDependent =
8868 (E->getDependence() & ExprDependence::TypeValue) ==
8869 ExprDependence::TypeValue;
8871 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8872 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8873 ToDecls.begin(), ToDecls.end(), KnownDependent,
8874 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8875 }
8876
8878 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8879 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8880 /*KnownDependent=*/E->isTypeDependent(),
8881 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8882}
8883
8886 Error Err = Error::success();
8887 auto ToType = importChecked(Err, E->getType());
8888 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8889 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8890 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8891 auto ToName = importChecked(Err, E->getName());
8892 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8893 if (Err)
8894 return std::move(Err);
8895
8896 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8897 // Import additional name location/type info.
8898 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8899 return std::move(Err);
8900
8901 UnresolvedSet<8> ToDecls;
8902 for (Decl *D : E->decls())
8903 if (auto ToDOrErr = import(D))
8904 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8905 else
8906 return ToDOrErr.takeError();
8907
8908 TemplateArgumentListInfo ToTAInfo;
8909 TemplateArgumentListInfo *ResInfo = nullptr;
8910 if (E->hasExplicitTemplateArgs()) {
8911 TemplateArgumentListInfo FromTAInfo;
8912 E->copyTemplateArgumentsInto(FromTAInfo);
8913 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8914 return std::move(Err);
8915 ResInfo = &ToTAInfo;
8916 }
8917
8918 Expr *ToBase = nullptr;
8919 if (!E->isImplicitAccess()) {
8920 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8921 ToBase = *ToBaseOrErr;
8922 else
8923 return ToBaseOrErr.takeError();
8924 }
8925
8927 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8928 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8929 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8930}
8931
8933 Error Err = Error::success();
8934 auto ToCallee = importChecked(Err, E->getCallee());
8935 auto ToType = importChecked(Err, E->getType());
8936 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8937 if (Err)
8938 return std::move(Err);
8939
8940 unsigned NumArgs = E->getNumArgs();
8941 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8942 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8943 return std::move(Err);
8944
8945 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8947 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8948 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8949 OCE->getADLCallKind());
8950 }
8951
8952 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8953 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8954 /*MinNumArgs=*/0, E->getADLCallKind());
8955}
8956
8958 CXXRecordDecl *FromClass = E->getLambdaClass();
8959 auto ToClassOrErr = import(FromClass);
8960 if (!ToClassOrErr)
8961 return ToClassOrErr.takeError();
8962 CXXRecordDecl *ToClass = *ToClassOrErr;
8963
8964 auto ToCallOpOrErr = import(E->getCallOperator());
8965 if (!ToCallOpOrErr)
8966 return ToCallOpOrErr.takeError();
8967
8968 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8969 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8970 return std::move(Err);
8971
8972 Error Err = Error::success();
8973 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8974 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8975 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8976 if (Err)
8977 return std::move(Err);
8978
8979 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8980 E->getCaptureDefault(), ToCaptureDefaultLoc,
8981 E->hasExplicitParameters(),
8982 E->hasExplicitResultType(), ToCaptureInits,
8983 ToEndLoc, E->containsUnexpandedParameterPack());
8984}
8985
8986
8988 Error Err = Error::success();
8989 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8990 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8991 auto ToType = importChecked(Err, E->getType());
8992 if (Err)
8993 return std::move(Err);
8994
8995 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8996 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8997 return std::move(Err);
8998
8999 ASTContext &ToCtx = Importer.getToContext();
9000 InitListExpr *To = new (ToCtx) InitListExpr(
9001 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
9002 To->setType(ToType);
9003
9004 if (E->hasArrayFiller()) {
9005 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
9006 To->setArrayFiller(*ToFillerOrErr);
9007 else
9008 return ToFillerOrErr.takeError();
9009 }
9010
9011 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
9012 if (auto ToFDOrErr = import(FromFD))
9013 To->setInitializedFieldInUnion(*ToFDOrErr);
9014 else
9015 return ToFDOrErr.takeError();
9016 }
9017
9018 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
9019 if (auto ToSyntFormOrErr = import(SyntForm))
9020 To->setSyntacticForm(*ToSyntFormOrErr);
9021 else
9022 return ToSyntFormOrErr.takeError();
9023 }
9024
9025 // Copy InitListExprBitfields, which are not handled in the ctor of
9026 // InitListExpr.
9027 To->sawArrayRangeDesignator(E->hadArrayRangeDesignator());
9028
9029 return To;
9030}
9031
9034 ExpectedType ToTypeOrErr = import(E->getType());
9035 if (!ToTypeOrErr)
9036 return ToTypeOrErr.takeError();
9037
9038 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
9039 if (!ToSubExprOrErr)
9040 return ToSubExprOrErr.takeError();
9041
9042 return new (Importer.getToContext()) CXXStdInitializerListExpr(
9043 *ToTypeOrErr, *ToSubExprOrErr);
9044}
9045
9048 Error Err = Error::success();
9049 auto ToLocation = importChecked(Err, E->getLocation());
9050 auto ToType = importChecked(Err, E->getType());
9051 auto ToConstructor = importChecked(Err, E->getConstructor());
9052 if (Err)
9053 return std::move(Err);
9054
9055 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
9056 ToLocation, ToType, ToConstructor, E->constructsVBase(),
9057 E->inheritedFromVBase());
9058}
9059
9061 Error Err = Error::success();
9062 auto ToType = importChecked(Err, E->getType());
9063 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
9064 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9065 if (Err)
9066 return std::move(Err);
9067
9068 return new (Importer.getToContext()) ArrayInitLoopExpr(
9069 ToType, ToCommonExpr, ToSubExpr);
9070}
9071
9073 ExpectedType ToTypeOrErr = import(E->getType());
9074 if (!ToTypeOrErr)
9075 return ToTypeOrErr.takeError();
9076 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
9077}
9078
9080 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
9081 if (!ToBeginLocOrErr)
9082 return ToBeginLocOrErr.takeError();
9083
9084 auto ToFieldOrErr = import(E->getField());
9085 if (!ToFieldOrErr)
9086 return ToFieldOrErr.takeError();
9087
9088 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
9089 if (!UsedContextOrErr)
9090 return UsedContextOrErr.takeError();
9091
9092 FieldDecl *ToField = *ToFieldOrErr;
9093 assert(ToField->hasInClassInitializer() &&
9094 "Field should have in-class initializer if there is a default init "
9095 "expression that uses it.");
9096 if (!ToField->getInClassInitializer()) {
9097 // The in-class initializer may be not yet set in "To" AST even if the
9098 // field is already there. This must be set here to make construction of
9099 // CXXDefaultInitExpr work.
9100 auto ToInClassInitializerOrErr =
9101 import(E->getField()->getInClassInitializer());
9102 if (!ToInClassInitializerOrErr)
9103 return ToInClassInitializerOrErr.takeError();
9104 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
9105 }
9106
9107 Expr *RewrittenInit = nullptr;
9108 if (E->hasRewrittenInit()) {
9109 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
9110 if (!ExprOrErr)
9111 return ExprOrErr.takeError();
9112 RewrittenInit = ExprOrErr.get();
9113 }
9114
9115 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
9116 ToField, *UsedContextOrErr, RewrittenInit);
9117}
9118
9120 Error Err = Error::success();
9121 auto ToType = importChecked(Err, E->getType());
9122 auto ToSubExpr = importChecked(Err, E->getSubExpr());
9123 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
9124 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
9125 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
9126 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
9127 if (Err)
9128 return std::move(Err);
9129
9131 CastKind CK = E->getCastKind();
9132 auto ToBasePathOrErr = ImportCastPath(E);
9133 if (!ToBasePathOrErr)
9134 return ToBasePathOrErr.takeError();
9135
9136 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
9138 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9139 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
9140 ToAngleBrackets);
9141 } else if (isa<CXXDynamicCastExpr>(E)) {
9143 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9144 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9145 } else if (isa<CXXReinterpretCastExpr>(E)) {
9147 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
9148 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9149 } else if (isa<CXXConstCastExpr>(E)) {
9151 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
9152 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
9153 } else {
9154 llvm_unreachable("Unknown cast type");
9155 return make_error<ASTImportError>();
9156 }
9157}
9158
9161 Error Err = Error::success();
9162 auto ToType = importChecked(Err, E->getType());
9163 auto ToNameLoc = importChecked(Err, E->getNameLoc());
9164 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
9165 auto ToReplacement = importChecked(Err, E->getReplacement());
9166 if (Err)
9167 return std::move(Err);
9168
9169 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
9170 ToType, E->getValueKind(), ToNameLoc, ToReplacement, ToAssociatedDecl,
9171 E->getIndex(), E->getPackIndex(), E->isReferenceParameter(),
9172 E->getFinal());
9173}
9174
9176 Error Err = Error::success();
9177 auto ToType = importChecked(Err, E->getType());
9178 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
9179 auto ToEndLoc = importChecked(Err, E->getEndLoc());
9180 if (Err)
9181 return std::move(Err);
9182
9183 SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs());
9184 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
9185 return std::move(Err);
9186
9187 if (E->isStoredAsBoolean()) {
9188 // According to Sema::BuildTypeTrait(), if E is value-dependent,
9189 // Value is always false.
9190 bool ToValue = (E->isValueDependent() ? false : E->getBoolValue());
9191 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9192 E->getTrait(), ToArgs, ToEndLoc, ToValue);
9193 }
9194 return TypeTraitExpr::Create(Importer.getToContext(), ToType, ToBeginLoc,
9195 E->getTrait(), ToArgs, ToEndLoc,
9196 E->getAPValue());
9197}
9198
9200 ExpectedType ToTypeOrErr = import(E->getType());
9201 if (!ToTypeOrErr)
9202 return ToTypeOrErr.takeError();
9203
9204 auto ToSourceRangeOrErr = import(E->getSourceRange());
9205 if (!ToSourceRangeOrErr)
9206 return ToSourceRangeOrErr.takeError();
9207
9208 if (E->isTypeOperand()) {
9209 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
9210 return new (Importer.getToContext()) CXXTypeidExpr(
9211 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
9212 else
9213 return ToTSIOrErr.takeError();
9214 }
9215
9216 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
9217 if (!ToExprOperandOrErr)
9218 return ToExprOperandOrErr.takeError();
9219
9220 return new (Importer.getToContext()) CXXTypeidExpr(
9221 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
9222}
9223
9225 Error Err = Error::success();
9226
9227 QualType ToType = importChecked(Err, E->getType());
9228 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9229 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9230 Expr *ToLHS = importChecked(Err, E->getLHS());
9231 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9232 Expr *ToRHS = importChecked(Err, E->getRHS());
9233 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9234
9235 if (Err)
9236 return std::move(Err);
9237
9238 return new (Importer.getToContext())
9239 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9240 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9241}
9242
9244 Error Err = Error::success();
9245 auto RequiresKWLoc = importChecked(Err, E->getRequiresKWLoc());
9246 auto RParenLoc = importChecked(Err, E->getRParenLoc());
9247 auto RBraceLoc = importChecked(Err, E->getRBraceLoc());
9248
9249 auto Body = importChecked(Err, E->getBody());
9250 auto LParenLoc = importChecked(Err, E->getLParenLoc());
9251 if (Err)
9252 return std::move(Err);
9253 SmallVector<ParmVarDecl *, 4> LocalParameters(E->getLocalParameters().size());
9254 if (Error Err =
9255 ImportArrayChecked(E->getLocalParameters(), LocalParameters.begin()))
9256 return std::move(Err);
9258 E->getRequirements().size());
9259 if (Error Err =
9260 ImportArrayChecked(E->getRequirements(), Requirements.begin()))
9261 return std::move(Err);
9262 return RequiresExpr::Create(Importer.getToContext(), RequiresKWLoc, Body,
9263 LParenLoc, LocalParameters, RParenLoc,
9264 Requirements, RBraceLoc);
9265}
9266
9269 Error Err = Error::success();
9270 auto CL = importChecked(Err, E->getConceptReference());
9271 auto CSD = importChecked(Err, E->getSpecializationDecl());
9272 if (Err)
9273 return std::move(Err);
9274 if (E->isValueDependent())
9276 Importer.getToContext(), CL,
9277 const_cast<ImplicitConceptSpecializationDecl *>(CSD), nullptr);
9278 ConstraintSatisfaction Satisfaction;
9279 if (Error Err =
9280 ImportConstraintSatisfaction(E->getSatisfaction(), Satisfaction))
9281 return std::move(Err);
9283 Importer.getToContext(), CL,
9284 const_cast<ImplicitConceptSpecializationDecl *>(CSD), &Satisfaction);
9285}
9286
9288 CXXMethodDecl *FromMethod) {
9289 Error ImportErrors = Error::success();
9290 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9291 if (auto ImportedOrErr = import(FromOverriddenMethod))
9292 ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
9293 (*ImportedOrErr)->getCanonicalDecl()));
9294 else
9295 ImportErrors =
9296 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9297 }
9298 return ImportErrors;
9299}
9300
9302 ASTContext &FromContext, FileManager &FromFileManager,
9303 bool MinimalImport,
9304 std::shared_ptr<ASTImporterSharedState> SharedState)
9305 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9306 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9307 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9308
9309 // Create a default state without the lookup table: LLDB case.
9310 if (!SharedState) {
9311 this->SharedState = std::make_shared<ASTImporterSharedState>();
9312 }
9313
9314 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9315 ToContext.getTranslationUnitDecl();
9316}
9317
9318ASTImporter::~ASTImporter() = default;
9319
9321 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9322 "Try to get field index for non-field.");
9323
9324 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9325 if (!Owner)
9326 return std::nullopt;
9327
9328 unsigned Index = 0;
9329 for (const auto *D : Owner->decls()) {
9330 if (D == F)
9331 return Index;
9332
9333 if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
9334 ++Index;
9335 }
9336
9337 llvm_unreachable("Field was not found in its parent context.");
9338
9339 return std::nullopt;
9340}
9341
9343ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9344 // We search in the redecl context because of transparent contexts.
9345 // E.g. a simple C language enum is a transparent context:
9346 // enum E { A, B };
9347 // Now if we had a global variable in the TU
9348 // int A;
9349 // then the enum constant 'A' and the variable 'A' violates ODR.
9350 // We can diagnose this only if we search in the redecl context.
9351 DeclContext *ReDC = DC->getRedeclContext();
9352 if (SharedState->getLookupTable()) {
9353 if (ReDC->isNamespace()) {
9354 // Namespaces can be reopened.
9355 // Lookup table does not handle this, we must search here in all linked
9356 // namespaces.
9357 FoundDeclsTy Result;
9358 SmallVector<Decl *, 2> NSChain =
9359 getCanonicalForwardRedeclChain<NamespaceDecl>(
9360 dyn_cast<NamespaceDecl>(ReDC));
9361 for (auto *D : NSChain) {
9363 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9364 Name);
9366 }
9367 return Result;
9368 } else {
9370 SharedState->getLookupTable()->lookup(ReDC, Name);
9371 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9372 }
9373 } else {
9374 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9375 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9376 // We must search by the slow case of localUncachedLookup because that is
9377 // working even if there is no LookupPtr for the DC. We could use
9378 // DC::buildLookup() to create the LookupPtr, but that would load external
9379 // decls again, we must avoid that case.
9380 // Also, even if we had the LookupPtr, we must find Decls which are not
9381 // in the LookupPtr, so we need the slow case.
9382 // These cases are handled in ASTImporterLookupTable, but we cannot use
9383 // that with LLDB since that traverses through the AST which initiates the
9384 // load of external decls again via DC::decls(). And again, we must avoid
9385 // loading external decls during the import.
9386 if (Result.empty())
9387 ReDC->localUncachedLookup(Name, Result);
9388 return Result;
9389 }
9390}
9391
9392void ASTImporter::AddToLookupTable(Decl *ToD) {
9393 SharedState->addDeclToLookup(ToD);
9394}
9395
9397 // Import the decl using ASTNodeImporter.
9398 ASTNodeImporter Importer(*this);
9399 return Importer.Visit(FromD);
9400}
9401
9403 MapImported(FromD, ToD);
9404}
9405
9408 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9409 if (Expected<Expr *> R = Import(CLE))
9410 return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
9411 }
9412
9413 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9414 // ASTNodeImporter.
9415 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9416}
9417
9419 if (!FromT)
9420 return FromT;
9421
9422 // Check whether we've already imported this type.
9423 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9424 ImportedTypes.find(FromT);
9425 if (Pos != ImportedTypes.end())
9426 return Pos->second;
9427
9428 // Import the type.
9429 ASTNodeImporter Importer(*this);
9430 ExpectedType ToTOrErr = Importer.Visit(FromT);
9431 if (!ToTOrErr)
9432 return ToTOrErr.takeError();
9433
9434 // Record the imported type.
9435 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9436
9437 return ToTOrErr->getTypePtr();
9438}
9439
9441 if (FromT.isNull())
9442 return QualType{};
9443
9444 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9445 if (!ToTyOrErr)
9446 return ToTyOrErr.takeError();
9447
9448 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9449}
9450
9452 if (!FromTSI)
9453 return FromTSI;
9454
9455 // FIXME: For now we just create a "trivial" type source info based
9456 // on the type and a single location. Implement a real version of this.
9457 ExpectedType TOrErr = Import(FromTSI->getType());
9458 if (!TOrErr)
9459 return TOrErr.takeError();
9460 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9461 if (!BeginLocOrErr)
9462 return BeginLocOrErr.takeError();
9463
9464 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9465}
9466
9467namespace {
9468// To use this object, it should be created before the new attribute is created,
9469// and destructed after it is created. The construction already performs the
9470// import of the data.
9471template <typename T> struct AttrArgImporter {
9472 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9473 AttrArgImporter(AttrArgImporter<T> &&) = default;
9474 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9475 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9476
9477 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9478 : To(I.importChecked(Err, From)) {}
9479
9480 const T &value() { return To; }
9481
9482private:
9483 T To;
9484};
9485
9486// To use this object, it should be created before the new attribute is created,
9487// and destructed after it is created. The construction already performs the
9488// import of the data. The array data is accessible in a pointer form, this form
9489// is used by the attribute classes. This object should be created once for the
9490// array data to be imported (the array size is not imported, just copied).
9491template <typename T> struct AttrArgArrayImporter {
9492 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9493 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9494 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9495 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9496
9497 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9498 const llvm::iterator_range<T *> &From,
9499 unsigned ArraySize) {
9500 if (Err)
9501 return;
9502 To.reserve(ArraySize);
9503 Err = I.ImportContainerChecked(From, To);
9504 }
9505
9506 T *value() { return To.data(); }
9507
9508private:
9510};
9511
9512class AttrImporter {
9513 Error Err{Error::success()};
9514 Attr *ToAttr = nullptr;
9515 ASTImporter &Importer;
9516 ASTNodeImporter NImporter;
9517
9518public:
9519 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9520
9521 // Useful for accessing the imported attribute.
9522 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9523 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9524
9525 // Create an "importer" for an attribute parameter.
9526 // Result of the 'value()' of that object is to be passed to the function
9527 // 'importAttr', in the order that is expected by the attribute class.
9528 template <class T> AttrArgImporter<T> importArg(const T &From) {
9529 return AttrArgImporter<T>(NImporter, Err, From);
9530 }
9531
9532 // Create an "importer" for an attribute parameter that has array type.
9533 // Result of the 'value()' of that object is to be passed to the function
9534 // 'importAttr', then the size of the array as next argument.
9535 template <typename T>
9536 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9537 unsigned ArraySize) {
9538 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9539 }
9540
9541 // Create an attribute object with the specified arguments.
9542 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9543 // should be values that are passed to the 'Create' function of the attribute.
9544 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9545 // used here.) As much data is copied or imported from the old attribute
9546 // as possible. The passed arguments should be already imported.
9547 // If an import error happens, the internal error is set to it, and any
9548 // further import attempt is ignored.
9549 template <typename T, typename... Arg>
9550 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9551 static_assert(std::is_base_of<Attr, T>::value,
9552 "T should be subclass of Attr.");
9553 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9554
9555 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9556 const IdentifierInfo *ToScopeName =
9557 Importer.Import(FromAttr->getScopeName());
9558 SourceRange ToAttrRange =
9559 NImporter.importChecked(Err, FromAttr->getRange());
9560 SourceLocation ToScopeLoc =
9561 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9562
9563 if (Err)
9564 return;
9565
9567 ToAttrName, AttributeScopeInfo(ToScopeName, ToScopeLoc), ToAttrRange,
9568 FromAttr->getParsedKind(), FromAttr->getForm());
9569 // The "SemanticSpelling" is not needed to be passed to the constructor.
9570 // That value is recalculated from the SpellingListIndex if needed.
9571 ToAttr = T::Create(Importer.getToContext(),
9572 std::forward<Arg>(ImportedArg)..., ToI);
9573
9574 ToAttr->setImplicit(FromAttr->isImplicit());
9575 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9576 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9577 ToInheritableAttr->setInherited(FromAttr->isInherited());
9578 }
9579
9580 // Create a clone of the 'FromAttr' and import its source range only.
9581 // This causes objects with invalid references to be created if the 'FromAttr'
9582 // contains other data that should be imported.
9583 void cloneAttr(const Attr *FromAttr) {
9584 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9585
9586 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9587 if (Err)
9588 return;
9589
9590 ToAttr = FromAttr->clone(Importer.getToContext());
9591 ToAttr->setRange(ToRange);
9592 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9593 }
9594
9595 // Get the result of the previous import attempt (can be used only once).
9596 llvm::Expected<Attr *> getResult() && {
9597 if (Err)
9598 return std::move(Err);
9599 assert(ToAttr && "Attribute should be created.");
9600 return ToAttr;
9601 }
9602};
9603} // namespace
9604
9606 AttrImporter AI(*this);
9607
9608 // FIXME: Is there some kind of AttrVisitor to use here?
9609 switch (FromAttr->getKind()) {
9610 case attr::Aligned: {
9611 auto *From = cast<AlignedAttr>(FromAttr);
9612 if (From->isAlignmentExpr())
9613 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9614 else
9615 AI.importAttr(From, false,
9616 AI.importArg(From->getAlignmentType()).value());
9617 break;
9618 }
9619
9620 case attr::AlignValue: {
9621 auto *From = cast<AlignValueAttr>(FromAttr);
9622 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9623 break;
9624 }
9625
9626 case attr::Format: {
9627 const auto *From = cast<FormatAttr>(FromAttr);
9628 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9629 From->getFirstArg());
9630 break;
9631 }
9632
9633 case attr::EnableIf: {
9634 const auto *From = cast<EnableIfAttr>(FromAttr);
9635 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9636 From->getMessage());
9637 break;
9638 }
9639
9640 case attr::AssertCapability: {
9641 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9642 AI.importAttr(From,
9643 AI.importArrayArg(From->args(), From->args_size()).value(),
9644 From->args_size());
9645 break;
9646 }
9647 case attr::AcquireCapability: {
9648 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9649 AI.importAttr(From,
9650 AI.importArrayArg(From->args(), From->args_size()).value(),
9651 From->args_size());
9652 break;
9653 }
9654 case attr::TryAcquireCapability: {
9655 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9656 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9657 AI.importArrayArg(From->args(), From->args_size()).value(),
9658 From->args_size());
9659 break;
9660 }
9661 case attr::ReleaseCapability: {
9662 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9663 AI.importAttr(From,
9664 AI.importArrayArg(From->args(), From->args_size()).value(),
9665 From->args_size());
9666 break;
9667 }
9668 case attr::RequiresCapability: {
9669 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9670 AI.importAttr(From,
9671 AI.importArrayArg(From->args(), From->args_size()).value(),
9672 From->args_size());
9673 break;
9674 }
9675 case attr::GuardedBy: {
9676 const auto *From = cast<GuardedByAttr>(FromAttr);
9677 AI.importAttr(From, AI.importArg(From->getArg()).value());
9678 break;
9679 }
9680 case attr::PtGuardedBy: {
9681 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9682 AI.importAttr(From, AI.importArg(From->getArg()).value());
9683 break;
9684 }
9685 case attr::AcquiredAfter: {
9686 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9687 AI.importAttr(From,
9688 AI.importArrayArg(From->args(), From->args_size()).value(),
9689 From->args_size());
9690 break;
9691 }
9692 case attr::AcquiredBefore: {
9693 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9694 AI.importAttr(From,
9695 AI.importArrayArg(From->args(), From->args_size()).value(),
9696 From->args_size());
9697 break;
9698 }
9699 case attr::LockReturned: {
9700 const auto *From = cast<LockReturnedAttr>(FromAttr);
9701 AI.importAttr(From, AI.importArg(From->getArg()).value());
9702 break;
9703 }
9704 case attr::LocksExcluded: {
9705 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9706 AI.importAttr(From,
9707 AI.importArrayArg(From->args(), From->args_size()).value(),
9708 From->args_size());
9709 break;
9710 }
9711 default: {
9712 // The default branch works for attributes that have no arguments to import.
9713 // FIXME: Handle every attribute type that has arguments of type to import
9714 // (most often Expr* or Decl* or type) in the switch above.
9715 AI.cloneAttr(FromAttr);
9716 break;
9717 }
9718 }
9719
9720 return std::move(AI).getResult();
9721}
9722
9724 return ImportedDecls.lookup(FromD);
9725}
9726
9728 auto FromDPos = ImportedFromDecls.find(ToD);
9729 if (FromDPos == ImportedFromDecls.end())
9730 return nullptr;
9731 return FromDPos->second->getTranslationUnitDecl();
9732}
9733
9735 if (!FromD)
9736 return nullptr;
9737
9738 // Push FromD to the stack, and remove that when we return.
9739 ImportPath.push(FromD);
9740 auto ImportPathBuilder =
9741 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9742
9743 // Check whether there was a previous failed import.
9744 // If yes return the existing error.
9745 if (auto Error = getImportDeclErrorIfAny(FromD))
9746 return make_error<ASTImportError>(*Error);
9747
9748 // Check whether we've already imported this declaration.
9749 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9750 if (ToD) {
9751 // Already imported (possibly from another TU) and with an error.
9752 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9753 setImportDeclError(FromD, *Error);
9754 return make_error<ASTImportError>(*Error);
9755 }
9756
9757 // If FromD has some updated flags after last import, apply it.
9758 updateFlags(FromD, ToD);
9759 // If we encounter a cycle during an import then we save the relevant part
9760 // of the import path associated to the Decl.
9761 if (ImportPath.hasCycleAtBack())
9762 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9763 return ToD;
9764 }
9765
9766 // Import the declaration.
9767 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9768 if (!ToDOrErr) {
9769 // Failed to import.
9770
9771 auto Pos = ImportedDecls.find(FromD);
9772 if (Pos != ImportedDecls.end()) {
9773 // Import failed after the object was created.
9774 // Remove all references to it.
9775 auto *ToD = Pos->second;
9776 ImportedDecls.erase(Pos);
9777
9778 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9779 // (e.g. with namespaces) that several decls from the 'from' context are
9780 // mapped to the same decl in the 'to' context. If we removed entries
9781 // from the LookupTable here then we may end up removing them multiple
9782 // times.
9783
9784 // The Lookuptable contains decls only which are in the 'to' context.
9785 // Remove from the Lookuptable only if it is *imported* into the 'to'
9786 // context (and do not remove it if it was added during the initial
9787 // traverse of the 'to' context).
9788 auto PosF = ImportedFromDecls.find(ToD);
9789 if (PosF != ImportedFromDecls.end()) {
9790 // In the case of TypedefNameDecl we create the Decl first and only
9791 // then we import and set its DeclContext. So, the DC might not be set
9792 // when we reach here.
9793 if (ToD->getDeclContext())
9794 SharedState->removeDeclFromLookup(ToD);
9795 ImportedFromDecls.erase(PosF);
9796 }
9797
9798 // FIXME: AST may contain remaining references to the failed object.
9799 // However, the ImportDeclErrors in the shared state contains all the
9800 // failed objects together with their error.
9801 }
9802
9803 // Error encountered for the first time.
9804 // After takeError the error is not usable any more in ToDOrErr.
9805 // Get a copy of the error object (any more simple solution for this?).
9806 ASTImportError ErrOut;
9807 handleAllErrors(ToDOrErr.takeError(),
9808 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9809 setImportDeclError(FromD, ErrOut);
9810 // Set the error for the mapped to Decl, which is in the "to" context.
9811 if (Pos != ImportedDecls.end())
9812 SharedState->setImportDeclError(Pos->second, ErrOut);
9813
9814 // Set the error for all nodes which have been created before we
9815 // recognized the error.
9816 for (const auto &Path : SavedImportPaths[FromD]) {
9817 // The import path contains import-dependency nodes first.
9818 // Save the node that was imported as dependency of the current node.
9819 Decl *PrevFromDi = FromD;
9820 for (Decl *FromDi : Path) {
9821 // Begin and end of the path equals 'FromD', skip it.
9822 if (FromDi == FromD)
9823 continue;
9824 // We should not set import error on a node and all following nodes in
9825 // the path if child import errors are ignored.
9826 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9827 PrevFromDi))
9828 break;
9829 PrevFromDi = FromDi;
9830 setImportDeclError(FromDi, ErrOut);
9831 //FIXME Should we remove these Decls from ImportedDecls?
9832 // Set the error for the mapped to Decl, which is in the "to" context.
9833 auto Ii = ImportedDecls.find(FromDi);
9834 if (Ii != ImportedDecls.end())
9835 SharedState->setImportDeclError(Ii->second, ErrOut);
9836 // FIXME Should we remove these Decls from the LookupTable,
9837 // and from ImportedFromDecls?
9838 }
9839 }
9840 SavedImportPaths.erase(FromD);
9841
9842 // Do not return ToDOrErr, error was taken out of it.
9843 return make_error<ASTImportError>(ErrOut);
9844 }
9845
9846 ToD = *ToDOrErr;
9847
9848 // FIXME: Handle the "already imported with error" case. We can get here
9849 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9850 // previously failed create was requested).
9851 // Later GetImportedOrCreateDecl can be updated to return the error.
9852 if (!ToD) {
9853 auto Err = getImportDeclErrorIfAny(FromD);
9854 assert(Err);
9855 return make_error<ASTImportError>(*Err);
9856 }
9857
9858 // We could import from the current TU without error. But previously we
9859 // already had imported a Decl as `ToD` from another TU (with another
9860 // ASTImporter object) and with an error.
9861 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9862 setImportDeclError(FromD, *Error);
9863 return make_error<ASTImportError>(*Error);
9864 }
9865 // Make sure that ImportImpl registered the imported decl.
9866 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9867
9868 if (FromD->hasAttrs())
9869 for (const Attr *FromAttr : FromD->getAttrs()) {
9870 auto ToAttrOrErr = Import(FromAttr);
9871 if (ToAttrOrErr)
9872 ToD->addAttr(*ToAttrOrErr);
9873 else
9874 return ToAttrOrErr.takeError();
9875 }
9876
9877 // Notify subclasses.
9878 Imported(FromD, ToD);
9879
9880 updateFlags(FromD, ToD);
9881 SavedImportPaths.erase(FromD);
9882 return ToDOrErr;
9883}
9884
9887 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9888}
9889
9891 if (!FromDC)
9892 return FromDC;
9893
9894 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9895 if (!ToDCOrErr)
9896 return ToDCOrErr.takeError();
9897 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9898
9899 // When we're using a record/enum/Objective-C class/protocol as a context, we
9900 // need it to have a definition.
9901 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9902 auto *FromRecord = cast<RecordDecl>(FromDC);
9903 if (ToRecord->isCompleteDefinition())
9904 return ToDC;
9905
9906 // If FromRecord is not defined we need to force it to be.
9907 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9908 // it will start the definition but we never finish it.
9909 // If there are base classes they won't be imported and we will
9910 // be missing anything that we inherit from those bases.
9911 if (FromRecord->getASTContext().getExternalSource() &&
9912 !FromRecord->isCompleteDefinition())
9913 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9914
9915 if (FromRecord->isCompleteDefinition())
9916 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9917 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9918 return std::move(Err);
9919 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9920 auto *FromEnum = cast<EnumDecl>(FromDC);
9921 if (ToEnum->isCompleteDefinition()) {
9922 // Do nothing.
9923 } else if (FromEnum->isCompleteDefinition()) {
9924 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9925 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9926 return std::move(Err);
9927 } else {
9928 CompleteDecl(ToEnum);
9929 }
9930 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9931 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9932 if (ToClass->getDefinition()) {
9933 // Do nothing.
9934 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9935 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9936 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9937 return std::move(Err);
9938 } else {
9939 CompleteDecl(ToClass);
9940 }
9941 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9942 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9943 if (ToProto->getDefinition()) {
9944 // Do nothing.
9945 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9946 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9947 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9948 return std::move(Err);
9949 } else {
9950 CompleteDecl(ToProto);
9951 }
9952 }
9953
9954 return ToDC;
9955}
9956
9958 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9959 return cast_or_null<Expr>(*ToSOrErr);
9960 else
9961 return ToSOrErr.takeError();
9962}
9963
9965 if (!FromS)
9966 return nullptr;
9967
9968 // Check whether we've already imported this statement.
9969 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9970 if (Pos != ImportedStmts.end())
9971 return Pos->second;
9972
9973 // Import the statement.
9974 ASTNodeImporter Importer(*this);
9975 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9976 if (!ToSOrErr)
9977 return ToSOrErr;
9978
9979 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9980 auto *FromE = cast<Expr>(FromS);
9981 // Copy ExprBitfields, which may not be handled in Expr subclasses
9982 // constructors.
9983 ToE->setValueKind(FromE->getValueKind());
9984 ToE->setObjectKind(FromE->getObjectKind());
9985 ToE->setDependence(FromE->getDependence());
9986 }
9987
9988 // Record the imported statement object.
9989 ImportedStmts[FromS] = *ToSOrErr;
9990 return ToSOrErr;
9991}
9992
9994 switch (FromNNS.getKind()) {
9997 return FromNNS;
9999 auto [Namespace, Prefix] = FromNNS.getAsNamespaceAndPrefix();
10000 auto NSOrErr = Import(Namespace);
10001 if (!NSOrErr)
10002 return NSOrErr.takeError();
10003 auto PrefixOrErr = Import(Prefix);
10004 if (!PrefixOrErr)
10005 return PrefixOrErr.takeError();
10006 return NestedNameSpecifier(ToContext, cast<NamespaceBaseDecl>(*NSOrErr),
10007 *PrefixOrErr);
10008 }
10010 if (ExpectedDecl RDOrErr = Import(FromNNS.getAsMicrosoftSuper()))
10011 return NestedNameSpecifier(cast<CXXRecordDecl>(*RDOrErr));
10012 else
10013 return RDOrErr.takeError();
10015 if (ExpectedTypePtr TyOrErr = Import(FromNNS.getAsType())) {
10016 return NestedNameSpecifier(*TyOrErr);
10017 } else {
10018 return TyOrErr.takeError();
10019 }
10020 }
10021 llvm_unreachable("Invalid nested name specifier kind");
10022}
10023
10026 // Copied from NestedNameSpecifier mostly.
10028 NestedNameSpecifierLoc NNS = FromNNS;
10029
10030 // Push each of the nested-name-specifiers's onto a stack for
10031 // serialization in reverse order.
10032 while (NNS) {
10033 NestedNames.push_back(NNS);
10034 NNS = NNS.getAsNamespaceAndPrefix().Prefix;
10035 }
10036
10038
10039 while (!NestedNames.empty()) {
10040 NNS = NestedNames.pop_back_val();
10041 NestedNameSpecifier Spec = std::nullopt;
10042 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
10043 return std::move(Err);
10044
10045 NestedNameSpecifier::Kind Kind = Spec.getKind();
10046
10047 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
10049 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
10050 return std::move(Err);
10051
10053 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
10054 return std::move(Err);
10055 }
10056
10057 switch (Kind) {
10059 Builder.Extend(getToContext(), Spec.getAsNamespaceAndPrefix().Namespace,
10060 ToLocalBeginLoc, ToLocalEndLoc);
10061 break;
10062
10064 SourceLocation ToTLoc;
10065 if (Error Err = importInto(ToTLoc, NNS.castAsTypeLoc().getBeginLoc()))
10066 return std::move(Err);
10068 QualType(Spec.getAsType(), 0), ToTLoc);
10069 Builder.Make(getToContext(), TSI->getTypeLoc(), ToLocalEndLoc);
10070 break;
10071 }
10072
10074 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
10075 break;
10076
10078 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
10079 if (!ToSourceRangeOrErr)
10080 return ToSourceRangeOrErr.takeError();
10081
10082 Builder.MakeMicrosoftSuper(getToContext(), Spec.getAsMicrosoftSuper(),
10083 ToSourceRangeOrErr->getBegin(),
10084 ToSourceRangeOrErr->getEnd());
10085 break;
10086 }
10088 llvm_unreachable("unexpected null nested name specifier");
10089 }
10090 }
10091
10092 return Builder.getWithLocInContext(getToContext());
10093}
10094
10096 switch (From.getKind()) {
10098 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
10099 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
10100 else
10101 return ToTemplateOrErr.takeError();
10102
10105 UnresolvedSet<2> ToTemplates;
10106 for (auto *I : *FromStorage) {
10107 if (auto ToOrErr = Import(I))
10108 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
10109 else
10110 return ToOrErr.takeError();
10111 }
10112 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
10113 ToTemplates.end());
10114 }
10115
10118 auto DeclNameOrErr = Import(FromStorage->getDeclName());
10119 if (!DeclNameOrErr)
10120 return DeclNameOrErr.takeError();
10121 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
10122 }
10123
10126 auto QualifierOrErr = Import(QTN->getQualifier());
10127 if (!QualifierOrErr)
10128 return QualifierOrErr.takeError();
10129 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
10130 if (!TNOrErr)
10131 return TNOrErr.takeError();
10132 return ToContext.getQualifiedTemplateName(
10133 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
10134 }
10135
10138 auto QualifierOrErr = Import(DTN->getQualifier());
10139 if (!QualifierOrErr)
10140 return QualifierOrErr.takeError();
10141 return ToContext.getDependentTemplateName(
10142 {*QualifierOrErr, Import(DTN->getName()), DTN->hasTemplateKeyword()});
10143 }
10144
10148 auto ReplacementOrErr = Import(Subst->getReplacement());
10149 if (!ReplacementOrErr)
10150 return ReplacementOrErr.takeError();
10151
10152 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
10153 if (!AssociatedDeclOrErr)
10154 return AssociatedDeclOrErr.takeError();
10155
10156 return ToContext.getSubstTemplateTemplateParm(
10157 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
10158 Subst->getPackIndex(), Subst->getFinal());
10159 }
10160
10164 ASTNodeImporter Importer(*this);
10165 auto ArgPackOrErr =
10166 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
10167 if (!ArgPackOrErr)
10168 return ArgPackOrErr.takeError();
10169
10170 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
10171 if (!AssociatedDeclOrErr)
10172 return AssociatedDeclOrErr.takeError();
10173
10174 return ToContext.getSubstTemplateTemplateParmPack(
10175 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
10176 SubstPack->getFinal());
10177 }
10179 auto UsingOrError = Import(From.getAsUsingShadowDecl());
10180 if (!UsingOrError)
10181 return UsingOrError.takeError();
10182 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
10183 }
10185 llvm_unreachable("Unexpected DeducedTemplate");
10186 }
10187
10188 llvm_unreachable("Invalid template name kind");
10189}
10190
10192 if (FromLoc.isInvalid())
10193 return SourceLocation{};
10194
10195 SourceManager &FromSM = FromContext.getSourceManager();
10196 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
10197
10198 FileIDAndOffset Decomposed = FromSM.getDecomposedLoc(FromLoc);
10199 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
10200 if (!ToFileIDOrErr)
10201 return ToFileIDOrErr.takeError();
10202 SourceManager &ToSM = ToContext.getSourceManager();
10203 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10204}
10205
10207 SourceLocation ToBegin, ToEnd;
10208 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10209 return std::move(Err);
10210 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10211 return std::move(Err);
10212
10213 return SourceRange(ToBegin, ToEnd);
10214}
10215
10217 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10218 if (Pos != ImportedFileIDs.end())
10219 return Pos->second;
10220
10221 SourceManager &FromSM = FromContext.getSourceManager();
10222 SourceManager &ToSM = ToContext.getSourceManager();
10223 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10224
10225 // Map the FromID to the "to" source manager.
10226 FileID ToID;
10227 if (FromSLoc.isExpansion()) {
10228 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10229 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10230 if (!ToSpLoc)
10231 return ToSpLoc.takeError();
10232 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10233 if (!ToExLocS)
10234 return ToExLocS.takeError();
10235 unsigned ExLength = FromSM.getFileIDSize(FromID);
10236 SourceLocation MLoc;
10237 if (FromEx.isMacroArgExpansion()) {
10238 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10239 } else {
10240 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10241 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10242 FromEx.isExpansionTokenRange());
10243 else
10244 return ToExLocE.takeError();
10245 }
10246 ToID = ToSM.getFileID(MLoc);
10247 } else {
10248 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10249
10250 if (!IsBuiltin && !Cache->BufferOverridden) {
10251 // Include location of this file.
10252 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10253 if (!ToIncludeLoc)
10254 return ToIncludeLoc.takeError();
10255
10256 // Every FileID that is not the main FileID needs to have a valid include
10257 // location so that the include chain points to the main FileID. When
10258 // importing the main FileID (which has no include location), we need to
10259 // create a fake include location in the main file to keep this property
10260 // intact.
10261 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10262 if (FromID == FromSM.getMainFileID())
10263 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10264
10265 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10266 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10267 // the disk again
10268 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10269 // than mmap the files several times.
10270 auto Entry =
10271 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10272 // FIXME: The filename may be a virtual name that does probably not
10273 // point to a valid file and we get no Entry here. In this case try with
10274 // the memory buffer below.
10275 if (Entry)
10276 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10277 FromSLoc.getFile().getFileCharacteristic());
10278 }
10279 }
10280
10281 if (ToID.isInvalid() || IsBuiltin) {
10282 // FIXME: We want to re-use the existing MemoryBuffer!
10283 std::optional<llvm::MemoryBufferRef> FromBuf =
10284 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10285 FromSM.getFileManager(), SourceLocation{});
10286 if (!FromBuf)
10287 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10288
10289 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10290 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10291 FromBuf->getBufferIdentifier());
10292 ToID = ToSM.createFileID(std::move(ToBuf),
10293 FromSLoc.getFile().getFileCharacteristic());
10294 }
10295 }
10296
10297 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10298
10299 ImportedFileIDs[FromID] = ToID;
10300 return ToID;
10301}
10302
10304 ExpectedExpr ToExprOrErr = Import(From->getInit());
10305 if (!ToExprOrErr)
10306 return ToExprOrErr.takeError();
10307
10308 auto LParenLocOrErr = Import(From->getLParenLoc());
10309 if (!LParenLocOrErr)
10310 return LParenLocOrErr.takeError();
10311
10312 auto RParenLocOrErr = Import(From->getRParenLoc());
10313 if (!RParenLocOrErr)
10314 return RParenLocOrErr.takeError();
10315
10316 if (From->isBaseInitializer()) {
10317 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10318 if (!ToTInfoOrErr)
10319 return ToTInfoOrErr.takeError();
10320
10321 SourceLocation EllipsisLoc;
10322 if (From->isPackExpansion())
10323 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10324 return std::move(Err);
10325
10326 return new (ToContext) CXXCtorInitializer(
10327 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10328 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10329 } else if (From->isMemberInitializer()) {
10330 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10331 if (!ToFieldOrErr)
10332 return ToFieldOrErr.takeError();
10333
10334 auto MemberLocOrErr = Import(From->getMemberLocation());
10335 if (!MemberLocOrErr)
10336 return MemberLocOrErr.takeError();
10337
10338 return new (ToContext) CXXCtorInitializer(
10339 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10340 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10341 } else if (From->isIndirectMemberInitializer()) {
10342 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10343 if (!ToIFieldOrErr)
10344 return ToIFieldOrErr.takeError();
10345
10346 auto MemberLocOrErr = Import(From->getMemberLocation());
10347 if (!MemberLocOrErr)
10348 return MemberLocOrErr.takeError();
10349
10350 return new (ToContext) CXXCtorInitializer(
10351 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10352 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10353 } else if (From->isDelegatingInitializer()) {
10354 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10355 if (!ToTInfoOrErr)
10356 return ToTInfoOrErr.takeError();
10357
10358 return new (ToContext)
10359 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10360 *ToExprOrErr, *RParenLocOrErr);
10361 } else {
10362 // FIXME: assert?
10363 return make_error<ASTImportError>();
10364 }
10365}
10366
10369 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10370 if (Pos != ImportedCXXBaseSpecifiers.end())
10371 return Pos->second;
10372
10373 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10374 if (!ToSourceRange)
10375 return ToSourceRange.takeError();
10377 if (!ToTSI)
10378 return ToTSI.takeError();
10379 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10380 if (!ToEllipsisLoc)
10381 return ToEllipsisLoc.takeError();
10382 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10383 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10384 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10385 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10386 return Imported;
10387}
10388
10390 ASTNodeImporter Importer(*this);
10391 return Importer.ImportAPValue(FromValue);
10392}
10393
10395 ExpectedDecl ToOrErr = Import(From);
10396 if (!ToOrErr)
10397 return ToOrErr.takeError();
10398 Decl *To = *ToOrErr;
10399
10400 auto *FromDC = cast<DeclContext>(From);
10401 ASTNodeImporter Importer(*this);
10402
10403 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10404 if (!ToRecord->getDefinition()) {
10405 return Importer.ImportDefinition(
10406 cast<RecordDecl>(FromDC), ToRecord,
10408 }
10409 }
10410
10411 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10412 if (!ToEnum->getDefinition()) {
10413 return Importer.ImportDefinition(
10414 cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10415 }
10416 }
10417
10418 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10419 if (!ToIFace->getDefinition()) {
10420 return Importer.ImportDefinition(
10421 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10423 }
10424 }
10425
10426 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10427 if (!ToProto->getDefinition()) {
10428 return Importer.ImportDefinition(
10429 cast<ObjCProtocolDecl>(FromDC), ToProto,
10431 }
10432 }
10433
10434 return Importer.ImportDeclContext(FromDC, true);
10435}
10436
10438 if (!FromName)
10439 return DeclarationName{};
10440
10441 switch (FromName.getNameKind()) {
10443 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10444
10448 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10449 return DeclarationName(*ToSelOrErr);
10450 else
10451 return ToSelOrErr.takeError();
10452
10454 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10455 return ToContext.DeclarationNames.getCXXConstructorName(
10456 ToContext.getCanonicalType(*ToTyOrErr));
10457 else
10458 return ToTyOrErr.takeError();
10459 }
10460
10462 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10463 return ToContext.DeclarationNames.getCXXDestructorName(
10464 ToContext.getCanonicalType(*ToTyOrErr));
10465 else
10466 return ToTyOrErr.takeError();
10467 }
10468
10470 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10472 cast<TemplateDecl>(*ToTemplateOrErr));
10473 else
10474 return ToTemplateOrErr.takeError();
10475 }
10476
10478 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10480 ToContext.getCanonicalType(*ToTyOrErr));
10481 else
10482 return ToTyOrErr.takeError();
10483 }
10484
10486 return ToContext.DeclarationNames.getCXXOperatorName(
10487 FromName.getCXXOverloadedOperator());
10488
10491 Import(FromName.getCXXLiteralIdentifier()));
10492
10494 // FIXME: STATICS!
10496 }
10497
10498 llvm_unreachable("Invalid DeclarationName Kind!");
10499}
10500
10502 if (!FromId)
10503 return nullptr;
10504
10505 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10506
10507 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10508 ToId->setBuiltinID(FromId->getBuiltinID());
10509
10510 return ToId;
10511}
10512
10515 if (const IdentifierInfo *FromII = FromIO.getIdentifier())
10516 return Import(FromII);
10517 return FromIO.getOperator();
10518}
10519
10521 if (FromSel.isNull())
10522 return Selector{};
10523
10525 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10526 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10527 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10528 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10529}
10530
10534 llvm::Error Err = llvm::Error::success();
10535 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10536 for (unsigned Idx = 0; Idx < Size; Idx++) {
10537 APValue Tmp = importChecked(Err, From[Idx]);
10538 To[Idx] = Tmp;
10539 }
10540 };
10541 switch (FromValue.getKind()) {
10542 case APValue::None:
10544 case APValue::Int:
10545 case APValue::Float:
10549 Result = FromValue;
10550 break;
10551 case APValue::Vector: {
10552 Result.MakeVector();
10554 Result.setVectorUninit(FromValue.getVectorLength());
10555 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10556 Elts.data(), FromValue.getVectorLength());
10557 break;
10558 }
10559 case APValue::Array:
10560 Result.MakeArray(FromValue.getArrayInitializedElts(),
10561 FromValue.getArraySize());
10562 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10563 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10564 FromValue.getArrayInitializedElts());
10565 break;
10566 case APValue::Struct:
10567 Result.MakeStruct(FromValue.getStructNumBases(),
10568 FromValue.getStructNumFields());
10569 ImportLoop(
10570 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10571 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10572 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10573 break;
10574 case APValue::Union: {
10575 Result.MakeUnion();
10576 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10577 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10578 if (Err)
10579 return std::move(Err);
10580 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10581 break;
10582 }
10584 Result.MakeAddrLabelDiff();
10585 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10586 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10587 if (Err)
10588 return std::move(Err);
10589 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10590 cast<AddrLabelExpr>(ImpRHS));
10591 break;
10592 }
10594 const Decl *ImpMemPtrDecl =
10595 importChecked(Err, FromValue.getMemberPointerDecl());
10596 if (Err)
10597 return std::move(Err);
10599 Result.setMemberPointerUninit(
10600 cast<const ValueDecl>(ImpMemPtrDecl),
10602 FromValue.getMemberPointerPath().size());
10603 ArrayRef<const CXXRecordDecl *> FromPath = Result.getMemberPointerPath();
10604 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10605 Idx++) {
10606 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10607 if (Err)
10608 return std::move(Err);
10609 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10610 }
10611 break;
10612 }
10613 case APValue::LValue:
10615 QualType FromElemTy;
10616 if (FromValue.getLValueBase()) {
10617 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10618 "in C++20 dynamic allocation are transient so they shouldn't "
10619 "appear in the AST");
10620 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10621 if (const auto *E =
10622 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10623 FromElemTy = E->getType();
10624 const Expr *ImpExpr = importChecked(Err, E);
10625 if (Err)
10626 return std::move(Err);
10627 Base = APValue::LValueBase(ImpExpr,
10628 FromValue.getLValueBase().getCallIndex(),
10629 FromValue.getLValueBase().getVersion());
10630 } else {
10631 FromElemTy =
10632 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10633 const Decl *ImpDecl = importChecked(
10634 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10635 if (Err)
10636 return std::move(Err);
10637 Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10638 FromValue.getLValueBase().getCallIndex(),
10639 FromValue.getLValueBase().getVersion());
10640 }
10641 } else {
10642 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10643 const Type *ImpTypeInfo = importChecked(
10644 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10645 QualType ImpType =
10646 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10647 if (Err)
10648 return std::move(Err);
10650 ImpType);
10651 }
10652 }
10653 CharUnits Offset = FromValue.getLValueOffset();
10654 unsigned PathLength = FromValue.getLValuePath().size();
10655 Result.MakeLValue();
10656 if (FromValue.hasLValuePath()) {
10657 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10658 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10659 FromValue.isNullPointer());
10661 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10662 if (FromElemTy->isRecordType()) {
10663 const Decl *FromDecl =
10664 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10665 const Decl *ImpDecl = importChecked(Err, FromDecl);
10666 if (Err)
10667 return std::move(Err);
10668 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10669 FromElemTy = Importer.FromContext.getCanonicalTagType(RD);
10670 else
10671 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10673 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10674 } else {
10675 FromElemTy =
10676 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10677 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10678 FromPath[LoopIdx].getAsArrayIndex());
10679 }
10680 }
10681 } else
10682 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10683 FromValue.isNullPointer());
10684 }
10685 if (Err)
10686 return std::move(Err);
10687 return Result;
10688}
10689
10691 DeclContext *DC,
10692 unsigned IDNS,
10693 NamedDecl **Decls,
10694 unsigned NumDecls) {
10695 if (ODRHandling == ODRHandlingType::Conservative)
10696 // Report error at any name conflict.
10697 return make_error<ASTImportError>(ASTImportError::NameConflict);
10698 else
10699 // Allow to create the new Decl with the same name.
10700 return Name;
10701}
10702
10704 if (LastDiagFromFrom)
10706 FromContext.getDiagnostics());
10707 LastDiagFromFrom = false;
10708 return ToContext.getDiagnostics().Report(Loc, DiagID);
10709}
10710
10712 if (!LastDiagFromFrom)
10714 ToContext.getDiagnostics());
10715 LastDiagFromFrom = true;
10716 return FromContext.getDiagnostics().Report(Loc, DiagID);
10717}
10718
10720 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10721 if (!ID->getDefinition())
10722 ID->startDefinition();
10723 }
10724 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10725 if (!PD->getDefinition())
10726 PD->startDefinition();
10727 }
10728 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10729 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10730 TD->startDefinition();
10731 TD->setCompleteDefinition(true);
10732 }
10733 }
10734 else {
10735 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10736 }
10737}
10738
10740 auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
10741 assert((Inserted || Pos->second == To) &&
10742 "Try to import an already imported Decl");
10743 if (!Inserted)
10744 return Pos->second;
10745 // This mapping should be maintained only in this function. Therefore do not
10746 // check for additional consistency.
10747 ImportedFromDecls[To] = From;
10748 // In the case of TypedefNameDecl we create the Decl first and only then we
10749 // import and set its DeclContext. So, the DC is still not set when we reach
10750 // here from GetImportedOrCreateDecl.
10751 if (To->getDeclContext())
10752 AddToLookupTable(To);
10753 return To;
10754}
10755
10756std::optional<ASTImportError>
10758 auto Pos = ImportDeclErrors.find(FromD);
10759 if (Pos != ImportDeclErrors.end())
10760 return Pos->second;
10761 else
10762 return std::nullopt;
10763}
10764
10766 auto InsertRes = ImportDeclErrors.insert({From, Error});
10767 (void)InsertRes;
10768 // Either we set the error for the first time, or we already had set one and
10769 // now we want to set the same error.
10770 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10771}
10772
10774 bool Complain) {
10775 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10776 ImportedTypes.find(From.getTypePtr());
10777 if (Pos != ImportedTypes.end()) {
10778 if (ExpectedType ToFromOrErr = Import(From)) {
10779 if (ToContext.hasSameType(*ToFromOrErr, To))
10780 return true;
10781 } else {
10782 llvm::consumeError(ToFromOrErr.takeError());
10783 }
10784 }
10785
10787 getToContext().getLangOpts(), FromContext, ToContext, NonEquivalentDecls,
10788 getStructuralEquivalenceKind(*this), false, Complain);
10789 return Ctx.IsEquivalent(From, To);
10790}
Defines the clang::ASTContext interface.
ASTImporterLookupTable & LT
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static ExpectedStmt ImportLoopControlStmt(ASTNodeImporter &NodeImporter, ASTImporter &Importer, StmtClass *S)
static auto getTemplateDefinition(T *D) -> T *
static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D)
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
const Decl * D
IndirectLocalPath & Path
enum clang::sema::@1840::IndirectLocalPathEntry::EntryKind Kind
Expr * E
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:3180
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:754
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
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:207
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition: APValue.h:215
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
const LValueBase getLValueBase() const
Definition: APValue.cpp:983
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:1003
const FieldDecl * getUnionField() const
Definition: APValue.h:629
unsigned getStructNumFields() const
Definition: APValue.h:608
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:204
ValueKind getKind() const
Definition: APValue.h:461
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:988
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1073
unsigned getArrayInitializedElts() const
Definition: APValue.h:595
unsigned getStructNumBases() const
Definition: APValue.h:604
bool hasLValuePath() const
Definition: APValue.cpp:998
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1066
APValue & getUnionValue()
Definition: APValue.h:633
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:649
CharUnits & getLValueOffset()
Definition: APValue.cpp:993
unsigned getVectorLength() const
Definition: APValue.h:571
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1080
unsigned getArraySize() const
Definition: APValue.h:599
@ 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:1019
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:645
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
SourceManager & getSourceManager()
Definition: ASTContext.h:801
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1201
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.
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 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.
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:744
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getSubstBuiltinTemplatePack(const TemplateArgument &ArgPack)
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
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2851
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2867
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
TemplateName getDependentTemplateName(const DependentTemplateStorage &Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template operat...
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
Retrieve a substitution-result 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 getUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UsingShadowDecl *D, QualType UnderlyingType=QualType()) const
IdentifierTable & Idents
Definition: ASTContext.h:740
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:894
SelectorTable & Selectors
Definition: ASTContext.h:741
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.
TemplateTemplateParmDecl * insertCanonicalTemplateTemplateParmDeclInternal(TemplateTemplateParmDecl *CanonTTP) const
Definition: ASTContext.cpp:863
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier NNS, const IdentifierInfo *Name) const
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 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...
TemplateTemplateParmDecl * findCanonicalTemplateTemplateParmDeclInternal(TemplateTemplateParmDecl *TTP) const
Definition: ASTContext.cpp:852
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)
CanQualType CharTy
Definition: ASTContext.h:1224
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2442
CanQualType SignedCharTy
Definition: ASTContext.h:1231
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 getPackIndexingType(QualType Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< QualType > Expansions={}, UnsignedOrNone Index=std::nullopt) const
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a non-unique reference to the type for a variable array of the specified element type.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, TemplateDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
CanQualType VoidTy
Definition: ASTContext.h:1222
QualType getPackExpansionType(QualType Pattern, UnsignedOrNone NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
CanQualType UnsignedCharTy
Definition: ASTContext.h:1232
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T, ArrayRef< TemplateArgument > SpecifiedArgs, ArrayRef< TemplateArgument > CanonicalArgs, QualType Underlying=QualType()) const
TemplateName getQualifiedTemplateName(NestedNameSpecifier Qualifier, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
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:1750
QualType getMemberPointerType(QualType T, NestedNameSpecifier Qualifier, const CXXRecordDecl *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
CanQualType getCanonicalUnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) const
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.
QualType getUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UnresolvedUsingTypenameDecl *D) const
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
QualType getDeducedTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1339
CanQualType getCanonicalTagType(const TagDecl *TD) const
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
CanQualType WCharTy
Definition: ASTContext.h:1225
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
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
Definition: ASTImporter.cpp:99
std::string toString() const
Definition: ASTImporter.cpp:85
@ 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:165
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Definition: ASTImporter.h:179
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:536
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:551
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:533
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.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition: ASTImporter.h:66
static UnsignedOrNone getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
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
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:576
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:561
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)
StringRef ImportASTStringRef(StringRef FromStr)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedDecl VisitRequiresExprBodyDecl(RequiresExprBodyDecl *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitRequiresExpr(RequiresExpr *E)
ExpectedDecl VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitConceptDecl(ConceptDecl *D)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
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)
Expected< concepts::Requirement * > ImportNestedRequirement(concepts::NestedRequirement *From)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
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 VisitConceptSpecializationExpr(ConceptSpecializationExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
Expected< concepts::Requirement * > ImportExprRequirement(concepts::ExprRequirement *From)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
Error ImportConstraintSatisfaction(const ASTConstraintSatisfaction &FromSat, ConstraintSatisfaction &ToSat)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
Expected< concepts::Requirement * > ImportTypeRequirement(concepts::TypeRequirement *From)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
ExpectedStmt VisitBreakStmt(BreakStmt *S)
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4486
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: TypeBase.h:3507
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5957
Represents a loop initializing the elements of an array.
Definition: Expr.h:5904
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: TypeBase.h:3908
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2723
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2990
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: TypeBase.h:3738
QualType getElementType() const
Definition: TypeBase.h:3750
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:6816
Attr - This represents one attribute.
Definition: Attr.h:44
attr::Kind getKind() const
Definition: Attr.h:90
void setPackExpansion(bool PE)
Definition: Attr.h:106
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition: Attr.h:104
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2203
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:432
An attributed type is a type to which a type attribute has been applied.
Definition: TypeBase.h:6585
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: TypeBase.h:7180
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3490
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3387
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4389
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3974
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:4938
A binding in a decomposition declaration.
Definition: DeclCXX.h:4179
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:4217
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4223
A fixed int type of a specified bitwidth.
Definition: TypeBase.h:8195
Pointer to a block type.
Definition: TypeBase.h:3558
BreakStmt - This represents a break.
Definition: Stmt.h:3135
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5470
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
This class is used for builtin types like 'int'.
Definition: TypeBase.h:3182
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:2099
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:1494
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1118
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:723
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition: ExprCXX.h:735
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:892
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1549
void setIsImmediateEscalating(bool Set)
Definition: ExprCXX.h:1711
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:1180
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2604
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2937
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2369
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2509
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2469
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2571
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2568
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2479
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2567
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2474
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2503
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2447
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2441
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2453
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2529
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2523
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2495
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1979
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition: DeclCXX.h:2063
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1271
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1039
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1378
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:1093
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2620
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3864
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:1550
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2869
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:3112
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:806
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:5026
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:918
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1753
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:179
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:692
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2129
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2755
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2778
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2225
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:375
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2349
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, const ImplicitAllocationParameters &IAP, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:293
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4303
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:768
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:624
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2739
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:539
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition: DeclCXX.cpp:2020
method_range methods() const
Definition: DeclCXX.h:650
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:548
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:141
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:2033
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:2046
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1834
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:2027
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:2061
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:530
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:870
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:286
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2198
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:780
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:800
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1901
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:1146
Represents a C++ temporary.
Definition: ExprCXX.h:1460
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1113
Represents the this expression in C++.
Definition: ExprCXX.h:1155
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1585
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1209
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:848
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3738
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1488
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2879
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:1513
CaseStmt - Represent a case statement.
Definition: Stmt.h:1920
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1264
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3612
path_iterator path_begin()
Definition: Expr.h:3682
path_iterator path_end()
Definition: Expr.h:3683
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
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:4784
Declaration of a class template.
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...
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
void setPointOfInstantiation(SourceLocation Loc)
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
Complex values, per C99 6.2.5p11.
Definition: TypeBase.h:3293
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4236
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:4960
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3541
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1720
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:390
Declaration of a C++20 concept.
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:126
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:166
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:193
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:170
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:199
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:87
TemplateDecl * getNamedConcept() const
Definition: ASTConcept.h:197
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:176
Represents the specialization of a concept - evaluates to a prvalue of type bool.
Definition: ExprConcepts.h:42
static ConceptSpecializationExpr * Create(const ASTContext &C, ConceptReference *ConceptRef, ImplicitConceptSpecializationDecl *SpecDecl, const ConstraintSatisfaction *Satisfaction)
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4327
Represents the canonical version of C arrays with a specified constant size.
Definition: TypeBase.h:3776
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1084
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:346
Represents a concrete matrix type with constant number of rows and columns.
Definition: TypeBase.h:4389
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:37
std::pair< SourceLocation, StringRef > SubstitutionDiagnostic
Definition: ASTConcept.h:51
llvm::SmallVector< Detail, 4 > Details
The substituted constraint expr, if the template arguments could be substituted into them,...
Definition: ASTConcept.h:60
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3671
ContinueStmt - This represents a continue.
Definition: Stmt.h:3119
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4655
static ConvertVectorExpr * Create(const ASTContext &C, Expr *SrcExpr, TypeSourceInfo *TI, QualType DstType, ExprValueKind VK, ExprObjectKind OK, SourceLocation BuiltinLoc, SourceLocation RParenLoc, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:5486
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: TypeBase.h:3454
Represents a pointer type decayed from an array or function type.
Definition: TypeBase.h:3541
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1382
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2109
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:2077
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1358
bool isNamespace() const
Definition: DeclBase.h:2198
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1879
bool isRecord() const
Definition: DeclBase.h:2189
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:2022
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1801
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1667
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1712
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:1951
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1662
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
Definition: DeclBase.cpp:2040
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2373
bool isFunctionOrMethod() const
Definition: DeclBase.h:2161
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:1983
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:64
iterator begin()
Definition: DeclGroup.h:95
iterator end()
Definition: DeclGroup.h:101
bool isNull() const
Definition: DeclGroup.h:75
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1272
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:484
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1611
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:68
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:435
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition: DeclBase.cpp:263
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1226
bool hasAttrs() const
Definition: DeclBase.h:518
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:524
void addAttr(Attr *A)
Definition: DeclBase.cpp:1022
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:593
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:244
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:893
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1217
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:1180
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:502
SourceLocation getLocation() const
Definition: DeclBase.h:439
const char * getDeclKindName() const
Definition: DeclBase.cpp:147
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:594
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1049
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:608
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:553
DeclContext * getDeclContext()
Definition: DeclBase.h:448
AccessSpecifier getAccess() const
Definition: DeclBase.h:507
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:417
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:431
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:509
AttrVec & getAttrs()
Definition: DeclBase.h:524
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:360
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:918
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:364
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:978
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.
bool isEmpty() const
Evaluates true when this declaration name is empty.
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:813
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:2000
Represents the type decltype(expr) (C++11).
Definition: TypeBase.h:6270
A decomposition declaration.
Definition: DeclCXX.h:4243
Represents a C++17 deduced template specialization type.
Definition: TypeBase.h:7228
Represents an extended address space qualifier where the input address space value is dependent.
Definition: TypeBase.h:4077
Represents a qualified type name for which the type name is dependent.
Definition: TypeBase.h:7414
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3504
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:544
Represents an array type in C++ whose size is a value-dependent expression.
Definition: TypeBase.h:4027
Represents an extended vector type where either the type or size is dependent.
Definition: TypeBase.h:4117
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: TypeBase.h:4448
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: TypeBase.h:7465
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:590
IdentifierOrOverloadedOperator getName() const
Definition: TemplateName.h:609
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:607
bool hasTemplateKeyword() const
Was this template name was preceeded by the template keyword?
Definition: TemplateName.h:612
Represents a vector type where either the type or size is dependent.
Definition: TypeBase.h:4243
Represents a single C99 designator.
Definition: Expr.h:5530
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5657
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5611
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5647
Represents a C99 designated initializer expression.
Definition: Expr.h:5487
static DesignatedInitExpr * Create(const ASTContext &C, ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4671
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1233
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1529
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:926
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2832
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
Represents an empty-declaration.
Definition: Decl.h:5141
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3420
Represents an enum.
Definition: Decl.h:4004
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4267
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4205
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4177
EnumDecl * getMostRecentDecl()
Definition: Decl.h:4100
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4973
EnumDecl * getDefinition() const
Definition: Decl.h:4107
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4194
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:4160
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: TypeBase.h:6522
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3864
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1924
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1932
const Expr * getExpr() const
Definition: DeclCXX.h:1933
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3655
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3661
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1464
This represents one expression.
Definition: Expr.h:112
void setType(QualType t)
Definition: Expr.h:145
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:177
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:444
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:194
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition: Expr.h:241
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:451
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:223
QualType getType() const
Definition: Expr.h:144
ExprDependence getDependence() const
Definition: Expr.h:164
An expression trait intrinsic.
Definition: ExprCXX.h:3063
ExtVectorType - Extended vector type.
Definition: TypeBase.h:4283
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:919
Represents a member of a struct/union/class.
Definition: Decl.h:3157
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4666
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3337
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4676
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4776
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:208
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1072
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2888
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
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:125
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition: Decl.cpp:3132
Represents a function declaration or definition.
Definition: Decl.h:1999
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3271
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4139
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4134
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3290
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition: Decl.cpp:3152
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2698
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2771
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4113
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4264
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2401
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4330
@ TK_MemberSpecialization
Definition: Decl.h:2011
@ TK_DependentNonTemplate
Definition: Decl.h:2020
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:2015
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:2018
void setTrivial(bool IT)
Definition: Decl.h:2377
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:4085
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4152
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:4319
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2348
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete)
Definition: Decl.cpp:3543
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator=true)
Definition: Decl.cpp:3551
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2217
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4158
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4358
void setDefaulted(bool D=true)
Definition: Decl.h:2385
void setBody(Stmt *B)
Definition: Decl.cpp:3283
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition: Decl.cpp:3161
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2393
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4106
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3191
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: TypeBase.h:4860
Represents a prototype with parameter type info, e.g.
Definition: TypeBase.h:5282
QualType desugar() const
Definition: TypeBase.h:5863
ExtProtoInfo getExtProtoInfo() const
Definition: TypeBase.h:5571
ArrayRef< QualType > exceptions() const
Definition: TypeBase.h:5736
ArrayRef< QualType > param_types() const
Definition: TypeBase.h:5722
Declaration of a template function.
Definition: DeclTemplate.h:952
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
Definition: DeclTemplate.h:998
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition: TypeBase.h:4834
QualType getReturnType() const
Definition: TypeBase.h:4818
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3395
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4859
Represents a C11 generic selection.
Definition: Expr.h:6114
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:4560
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2969
Represents an arbitrary, user-specified SPIR-V type instruction.
Definition: TypeBase.h:6860
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:2259
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:1002
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1733
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3789
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2068
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5993
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:5015
Represents a C array with an unspecified size.
Definition: TypeBase.h:3925
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3464
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:3008
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2575
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2588
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2587
Describes an C or C++ initializer list.
Definition: Expr.h:5235
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5412
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2433
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:5367
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5422
The injected class name of a C++ class template or class template partial specialization.
Definition: TypeBase.h:6553
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:971
An lvalue reference type, per C++11 [dcl.ref].
Definition: TypeBase.h:3633
Represents the declaration of a label.
Definition: Decl.h:523
void setStmt(LabelStmt *T)
Definition: Decl.h:548
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2146
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:1264
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:1970
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:1312
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3302
Represents a linkage specification.
Definition: DeclCXX.h:3009
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:3051
Represents the results of name lookup.
Definition: Lookup.h:147
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: TypeBase.h:6161
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4914
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3300
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:1746
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: TypeBase.h:3669
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:614
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:654
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:659
This represents a decl that may have a name.
Definition: Decl.h:273
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1182
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:339
Represents a C++ namespace alias.
Definition: DeclCXX.h:3195
Represent a C++ namespace.
Definition: Decl.h:591
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition: Decl.h:674
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:693
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.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1683
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:1643
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2329
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2164
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:2391
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2160
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2400
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2545
Represents Objective-C's collection statement.
Definition: StmtObjC.h:23
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2597
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2735
Represents an ObjC class declaration.
Definition: DeclObjC.h:1154
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:1485
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1745
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1392
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1639
known_categories_range known_categories() const
Definition: DeclObjC.h:1687
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1588
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1374
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:369
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:340
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1356
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1626
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1363
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:613
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1915
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:349
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1542
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1573
Interfaces are the core concept in Objective-C for object oriented design.
Definition: TypeBase.h:7905
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1952
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs={})
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:941
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1187
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1208
Represents a pointer to an Objective C object.
Definition: TypeBase.h:7961
Represents a class type in Objective C.
Definition: TypeBase.h:7707
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:731
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:896
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:819
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:831
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:920
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:905
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:888
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:902
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2805
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2879
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2882
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2875
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2084
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:2209
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2250
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:2020
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2158
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2165
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2172
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2186
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:662
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:711
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1517
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:710
Represents a type parameter type in Objective C.
Definition: TypeBase.h:7633
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2529
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1649
Helper class for OffsetOfExpr.
Definition: Expr.h:2423
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2481
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2487
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1684
@ Array
An index into an array.
Definition: Expr.h:2428
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2432
@ Field
A field.
Definition: Expr.h:2430
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2435
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2509
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2477
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2510
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2497
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1180
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:118
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4357
Represents a pack expansion of types.
Definition: TypeBase.h:7524
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2184
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4810
Sugar for parentheses used when specifying types.
Definition: TypeBase.h:3320
Represents a parameter to a function.
Definition: Decl.h:1789
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1870
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1857
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:3014
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1885
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1930
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1918
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3039
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1822
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1922
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1817
bool hasInheritedDefaultArg() const
Definition: Decl.h:1934
void setKNRPromoted(bool promoted)
Definition: Decl.h:1873
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1881
Expr * getDefaultArg()
Definition: Decl.cpp:3002
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3044
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3050
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1938
PipeType - OpenCL20.
Definition: TypeBase.h:8161
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: TypeBase.h:3346
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:2007
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:629
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2688
A (possibly-)qualified type.
Definition: TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: TypeBase.h:8343
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: TypeBase.h:8375
Represents a template name as written in source code.
Definition: TemplateName.h:504
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:532
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:539
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:536
An rvalue reference type, per C++11 [dcl.ref].
Definition: TypeBase.h:3651
Represents a struct/union/class.
Definition: Decl.h:4309
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5125
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4365
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4335
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5166
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4493
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: TypeBase.h:6502
RecordDecl * getOriginalDecl() const
Definition: TypeBase.h:6509
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:201
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:223
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:5292
Base for LValueReferenceType and RValueReferenceType.
Definition: TypeBase.h:3589
Represents the body of a requires-expression.
Definition: DeclCXX.h:2098
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:505
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3160
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1248
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
static std::enable_if_t< std::is_base_of_v< Attr, AttrInfo >, SourceLocation > getAttrLoc(const AttrInfo &AL)
A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.
Definition: Sema.h:4808
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4579
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4435
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1709
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4953
Encodes a location in the source.
This class handles loading and caching of source files into memory.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
static SpirvOperand createConstant(QualType ResultType, llvm::APInt Val)
Definition: TypeBase.h:6837
static SpirvOperand createType(QualType T)
Definition: TypeBase.h:6845
static SpirvOperand createLiteral(llvm::APInt Val)
Definition: TypeBase.h:6841
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:4130
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4531
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:186
Stmt - This represents one statement.
Definition: Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:358
child_iterator child_begin()
Definition: Stmt.h:1571
StmtClass getStmtClass() const
Definition: Stmt.h:1472
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:334
child_iterator child_end()
Definition: Stmt.h:1572
const char * getStmtClassName() const
Definition: Stmt.cpp:87
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:346
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1801
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, ArrayRef< SourceLocation > Locs)
This is the "fully general" constructor that allows representation of strings formed from one or more...
Definition: Expr.cpp:1184
Represents the result of substituting a builtin template as a pack.
Definition: TypeBase.h:7062
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4658
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:151
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:166
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:418
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:441
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:437
Represents the result of substituting a set of types for a template type parameter pack.
Definition: TypeBase.h:7091
Represents the result of substituting a type for a template type parameter.
Definition: TypeBase.h:6972
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1895
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2509
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1125
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3714
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3829
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3809
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3945
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4847
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4842
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4884
void setBraceRange(SourceRange R)
Definition: Decl.h:3786
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3812
A convenient class for passing around template argument information.
Definition: TemplateBase.h:634
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:650
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:669
ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:661
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:649
A template argument list.
Definition: DeclTemplate.h:250
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:286
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:528
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:576
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
NestedNameSpecifierLoc getTemplateQualifierLoc() const
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:452
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:402
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:334
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:411
UnsignedOrNone getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:322
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:340
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:346
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:446
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:380
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:396
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:329
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:440
@ 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:296
bool isCanonicalExpr() const
Definition: TemplateBase.h:416
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:353
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:399
Represents a C++ template name within the type system.
Definition: TemplateName.h:222
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) 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:267
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:242
@ Template
A single template declaration.
Definition: TemplateName.h:239
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:254
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:258
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:263
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
Definition: TemplateName.h:271
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:250
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:246
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:74
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:146
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:182
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:207
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:206
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:205
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: TypeBase.h:7290
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Declaration of a template type parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint, UnsignedOrNone ArgPackSubstIndex)
The top declaration context.
Definition: Decl.h:104
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3685
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3703
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:223
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
Definition: TypeBase.h:3374
Symbolic representation of typeid(T) for some type T.
Definition: APValue.h:44
const Type * getType() const
Definition: APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:193
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: TypeBase.h:6193
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: TypeBase.h:6243
The type-property cache.
Definition: Type.cpp:4791
A container of type source information.
Definition: TypeBase.h:8314
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:272
QualType getType() const
Return the type wrapped by this type source info.
Definition: TypeBase.h:8325
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2890
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:1914
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: TypeBase.h:1833
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: TypeBase.h:9116
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.h:41
bool isArrayType() const
Definition: TypeBase.h:8679
bool isPointerType() const
Definition: TypeBase.h:8580
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:752
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: TypeBase.h:2800
const char * getTypeClassName() const
Definition: Type.cpp:3386
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: TypeBase.h:9109
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2440
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: TypeBase.h:2429
const T * getAs() const
Member-template getAs<specific type>'.
Definition: TypeBase.h:9159
bool isRecordType() const
Definition: TypeBase.h:8707
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3664
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3559
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2627
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2246
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4974
A unary type transform, which is a type constructed from another.
Definition: TypeBase.h:6375
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3384
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition: ExprCXX.cpp:432
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:4120
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:1652
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: TypeBase.h:5998
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:4031
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3934
Represents a C++ using-declaration.
Definition: DeclCXX.h:3585
Represents C++ using-directive.
Definition: DeclCXX.h:3090
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3786
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3867
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3393
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4893
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:711
void setType(QualType newType)
Definition: Decl.h:723
QualType getType() const
Definition: Decl.h:722
Represents a variable declaration or definition.
Definition: Decl.h:925
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2935
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2366
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2571
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2557
void setInlineSpecified()
Definition: Decl.h:1557
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1172
const Expr * getInit() const
Definition: Decl.h:1367
void setConstexpr(bool IC)
Definition: Decl.h:1571
void setInit(Expr *I)
Definition: Decl.cpp:2477
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2815
void setImplicitlyInline()
Definition: Decl.h:1562
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1357
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2898
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
VarTemplateDecl * getMostRecentDecl()
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
Represents a variable template specialization, which refers to a variable template with a given set o...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setPointOfInstantiation(SourceLocation Loc)
VarTemplateSpecializationDecl * getMostRecentDecl()
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: TypeBase.h:3982
Represents a GCC generic vector type.
Definition: TypeBase.h:4191
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2697
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:1187
A requires-expression requirement which queries the validity and properties of an expression ('simple...
Definition: ExprConcepts.h:282
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
Definition: ExprConcepts.h:411
ConceptSpecializationExpr * getReturnTypeRequirementSubstitutedConstraintExpr() const
Definition: ExprConcepts.h:406
const ReturnTypeRequirement & getReturnTypeRequirement() const
Definition: ExprConcepts.h:401
SatisfactionStatus getSatisfactionStatus() const
Definition: ExprConcepts.h:395
SourceLocation getNoexceptLoc() const
Definition: ExprConcepts.h:393
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
Definition: ExprConcepts.h:432
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
Definition: ExprConcepts.h:487
A static requirement that can be used in a requires-expression to check properties of types and expre...
Definition: ExprConcepts.h:170
RequirementKind getKind() const
Definition: ExprConcepts.h:200
A requires-expression requirement which queries the existence of a type name or type template special...
Definition: ExprConcepts.h:227
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:262
TypeSourceInfo * getType() const
Definition: ExprConcepts.h:269
Definition: SPIR.cpp:35
Definition: SPIR.cpp:47
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:330
std::pair< FileID, unsigned > FileIDAndOffset
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
CanThrowResult
Possible results from evaluation of a noexcept expression.
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:149
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ Property
The type of a property.
@ Result
The result type of a method or function.
@ Template
We are parsing a template declaration.
@ VarTemplate
The name was classified as a variable template name.
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:132
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:1288
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:188
bool isLambdaMethod(const DeclContext *DC)
Definition: ASTLambda.h:39
static void updateFlags(const Decl *From, Decl *To)
unsigned int uint32_t
#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.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:91
const UnsatisfiedConstraintRecord * end() const
Definition: ASTConcept.h:100
static ASTConstraintSatisfaction * Rebuild(const ASTContext &C, const ASTConstraintSatisfaction &Satisfaction)
Definition: ASTConcept.cpp:69
const UnsatisfiedConstraintRecord * begin() const
Definition: ASTConcept.h:96
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:678
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
const Expr * ConstraintExpr
Definition: Decl.h:87
Information about how a lambda is numbered within its context.
Definition: DeclCXX.h:1796
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:886
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:904
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:897
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: TypeBase.h:5351
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: TypeBase.h:5355
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: TypeBase.h:5341
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: TypeBase.h:5344
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: TypeBase.h:5347
Extra information about a function prototype.
Definition: TypeBase.h:5367
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:559
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:566
const NamespaceBaseDecl * Namespace
Location information for a TemplateArgument.
Definition: TemplateBase.h:480
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
SourceLocation getTemplateKwLoc() const
Definition: TemplateBase.h:509
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:503
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513